Skip to contentSkip to conversation

Patch for AD1985 AC97 CODEC

PATCH Randy Cushman 2 participants 12 messages Dec 1, 2006 – Dec 21, 2006 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

(This message references ALSA bugtracking issue ID 2655.
https://bugtrack.alsa-project.org/alsa-bug/view.php?id=2655)

I am researching issues I am having with the audio chipsets onboard my ASUS A8S-X Motherboard, which has an AD1986A CODEC, using its AC'97 interface.

$ cat /proc/asound/cards
 0 [SI7012 ]: ICH - SiS SI7012
                      SiS SI7012 with AD1986 at 0x8000, irq 50

The attached patch file removes the "V_REFOUT Enable" mixer control that recently was added to the driver for the AD1888 CODEC, and was inherited by the driver for the AD1985 CODEC. The AD1986/AD1986A CODECs currently utilize the AD1985 driver.

I am preparing additional patches that will provide improved support for these CODECs. Please let me know if my work thus far is satisfactory.

Randy Cushman

Summary: remove malfunctioning mixer control for AD1985/AD1986

This patch removes the "V_REFOUT Enable" mixer control for the AD1985 and AD1986 CODECs.

Previous patch "AD1888 mixer controls for DC mode" added controls that were propogated to multiple codecs. For the AD1985 codec, the bits VREFH and VREFD function differently, preventing the "V_REFOUT Enable" control from setting V_REFOUT to Hi-Z. For the AD1986 codec, the V_REFOUT pins are controlled by other register bits.

b/alsa-kernel/pci/ac97/ac97_patch.c renamed from a/alsa-kernel/pci/ac97/ac97_patch.c +27 -2
@@ -1953,7 +1953,27 @@
 }
 
 static const struct snd_kcontrol_new snd_ac97_ad1985_controls[] = {
-	AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0)
+	AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0),
+	{
+		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+		.name = "Exchange Front/Surround",
+		.info = snd_ac97_ad1888_lohpsel_info,
+		.get = snd_ac97_ad1888_lohpsel_get,
+		.put = snd_ac97_ad1888_lohpsel_put
+	},
+	AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC, 7, 1, 0),
+	{
+		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+		.name = "Downmix",
+		.info = snd_ac97_ad1888_downmix_info,
+		.get = snd_ac97_ad1888_downmix_get,
+		.put = snd_ac97_ad1888_downmix_put
+	},
+	AC97_SURROUND_JACK_MODE_CTL,
+	AC97_CHANNEL_MODE_CTL,
+
+	AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0),
+	AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
 };
 
 static void ad1985_update_jacks(struct snd_ac97 *ac97)
@@ -1967,8 +1987,13 @@
 {
 	int err;
 
-	if ((err = patch_ad1980_specific(ac97)) < 0)
+	/* rename 0x04 as "Master" and 0x02 as "Master Surround" */
+	snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Master Surround Playback");
+	snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback");
+
+	if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0)
 		return err;
+
 	return patch_build_controls(ac97, snd_ac97_ad1985_controls, ARRAY_SIZE(snd_ac97_ad1985_controls));
 }
 

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel

#1 lore raw

Attached please find my revision 2 patch of improvements to the AD1985 CODEC driver. This supersedes the patch I submitted on 30-Nov-2006, and patches the latest Mercurial source.

At this time I am figuring that I may be able to reduce the amount of work I create for the ALSA-Project team if I combine my work into a smaller number of patches. This combined patch includes all of the modifications I have planned for the AD1985 CODEC driver. I am continuing work on a patch to create separate AD1986/AD1986A CODEC driver code.

In this revised, combined patch I have included my "fix microphone and line_in selection logic" patch that should help users of the AD1985, along with many other multichannel CODECs. I have also decided to provide an enhanced V_REFOUT control, rather than simply remove the faulty control, as I had done in my previous revision.

Again, any feedback regarding my work is welcome.

Randy Cushman

Quoted 31 lines · Randy Cushman

(This message references ALSA bugtracking issue ID 2655.
https://bugtrack.alsa-project.org/alsa-bug/view.php?id=2655)

I am researching issues I am having with the audio chipsets onboard my ASUS A8S-X Motherboard, which has an AD1986A CODEC, using its AC'97 interface.

$ cat /proc/asound/cards
 0 [SI7012 ]: ICH - SiS SI7012
                      SiS SI7012 with AD1986 at 0x8000, irq 50

The attached patch file removes the "V_REFOUT Enable" mixer control that recently was added to the driver for the AD1888 CODEC, and was inherited by the driver for the AD1985 CODEC. The AD1986/AD1986A CODECs currently utilize the AD1985 driver.

I am preparing additional patches that will provide improved support for these CODECs. Please let me know if my work thus far is satisfactory.

Randy Cushman

------------------------------------------------------------------------

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
------------------------------------------------------------------------

Quoted 5 lines

_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel

Summary: fix microphone and line_in selection logic

This patch fixes the Microphone and LINE_IN select logic for surround codecs with shared jacks. This issue appears to apply to most, if not all AC'97 surround codecs. The existing code can never utilize the shared jacks for Microphone and LINE_IN due to the reversed jack selection logic. The patched code correctly selects the shared jack for input if the "Channel Mode" selector does not specify that the jack is to be used for output.

Specifically, in "2ch" mode the Center/LFE jack is used for microphone input and the Surround jack is used for LINE_IN, in "4ch" mode the Center/LFE jack is used for microphone input and the Surround jack is used for output, and in "6ch" mode both jacks are used for output.

Summary: replace malfunctioning mixer control for AD1985

This patch replacing the "V_REFOUT Enable" mixer switch control with a listbox control for the AD1985 CODEC.

Previous patch "AD1888 mixer controls for DC mode" added controls that were propogated to multiple codecs. For the AD1985 codec, the bits VREFH and VREFD function differently, preventing the "V_REFOUT Enable" control from setting V_REFOUT to Hi-Z.

b/alsa-kernel/pci/ac97/ac97_patch.c renamed from a/alsa-kernel/pci/ac97/ac97_patch.c +81 -8
@@ -192,12 +192,12 @@
 
 static inline int is_shared_linein(struct snd_ac97 *ac97)
 {
-	return ! ac97->indep_surround && is_surround_on(ac97);
+	return ! ac97->indep_surround && ! is_surround_on(ac97);
 }
 
 static inline int is_shared_micin(struct snd_ac97 *ac97)
 {
-	return ! ac97->indep_surround && is_clfe_on(ac97);
+	return ! ac97->indep_surround && ! is_clfe_on(ac97);
 }
 
 
@@ -1615,8 +1615,10 @@
 #define AC97_AD198X_MBC_10	0x0001	/* +10dB */
 #define AC97_AD198X_MBC_30	0x0002	/* +30dB */
 #define AC97_AD198X_VREFD	0x0004	/* VREF high-Z */
-#define AC97_AD198X_VREFH	0x0008	/* 2.25V, 3.7V */
-#define AC97_AD198X_VREF_0	0x000c	/* 0V */
+#define AC97_AD198X_VREFH	0x0008	/* 0=2.25V, 1=3.7V */
+#define AC97_AD198X_VREF_0	0x000c	/* 0V (AD1985 only) */
+#define AC97_AD198X_VREF_MASK	(AC97_AD198X_VREFH | AC97_AD198X_VREFD)
+#define AC97_AD198X_VREF_OFFSET 2
 #define AC97_AD198X_SRU		0x0010	/* sample rate unlock */
 #define AC97_AD198X_LOSEL	0x0020	/* LINE_OUT amplifiers input select */
 #define AC97_AD198X_2MIC	0x0040	/* 2-channel mic select */
@@ -1952,8 +1954,75 @@
 	return 0;
 }
 
+static int snd_ac97_ad1985_vrefout_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
+{
+	static char *texts[4] = {"High-Z", "3.7 V", "2.25 V", "0 V"};
+
+	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
+	uinfo->count = 1;
+	uinfo->value.enumerated.items = 4;
+	if (uinfo->value.enumerated.item > 3)
+		uinfo->value.enumerated.item = 3;
+	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
+	return 0;
+}
+
+static int snd_ac97_ad1985_vrefout_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
+{
+	static const int reg2ctrl[4] = {2, 0, 1, 3};
+	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
+	unsigned short val;
+	val = (ac97->regs[AC97_AD_MISC] & AC97_AD198X_VREF_MASK)
+	      >> AC97_AD198X_VREF_OFFSET;
+	ucontrol->value.enumerated.item[0] = reg2ctrl[val];
+	return 0;
+}
+
+static int snd_ac97_ad1985_vrefout_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
+{
+	static const int ctrl2reg[4] = {1, 2, 0, 3};
+	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
+	unsigned short val;
+
+	if (ucontrol->value.enumerated.item[0] > 3
+	    || ucontrol->value.enumerated.item[0] < 0)
+		return -EINVAL;
+	val = ctrl2reg[ucontrol->value.enumerated.item[0]]
+	      << AC97_AD198X_VREF_OFFSET;
+	return snd_ac97_update_bits(ac97, AC97_AD_MISC,
+				    AC97_AD198X_VREF_MASK, val);
+}
+
 static const struct snd_kcontrol_new snd_ac97_ad1985_controls[] = {
-	AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0)
+	AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0),
+	{
+		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+		.name = "Exchange Front/Surround",
+		.info = snd_ac97_ad1888_lohpsel_info,
+		.get = snd_ac97_ad1888_lohpsel_get,
+		.put = snd_ac97_ad1888_lohpsel_put
+	},
+	AC97_SINGLE("High Pass Filter Enable", AC97_AD_TEST2, 12, 1, 1),
+	AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC, 7, 1, 0),
+	{
+		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+		.name = "Downmix",
+		.info = snd_ac97_ad1888_downmix_info,
+		.get = snd_ac97_ad1888_downmix_get,
+		.put = snd_ac97_ad1888_downmix_put
+	},
+	{
+		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+		.name = "V_REFOUT",
+		.info = snd_ac97_ad1985_vrefout_info,
+		.get = snd_ac97_ad1985_vrefout_get,
+		.put = snd_ac97_ad1985_vrefout_put
+	},
+	AC97_SURROUND_JACK_MODE_CTL,
+	AC97_CHANNEL_MODE_CTL,
+
+	AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0),
+	AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
 };
 
 static void ad1985_update_jacks(struct snd_ac97 *ac97)
@@ -1967,8 +2036,13 @@
 {
 	int err;
 
-	if ((err = patch_ad1980_specific(ac97)) < 0)
+	/* rename 0x04 as "Master" and 0x02 as "Master Surround" */
+	snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Master Surround Playback");
+	snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback");
+
+	if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0)
 		return err;
+
 	return patch_build_controls(ac97, snd_ac97_ad1985_controls, ARRAY_SIZE(snd_ac97_ad1985_controls));
 }
 
@@ -1989,12 +2063,11 @@
 	ac97->build_ops = &patch_ad1985_build_ops;
 	misc = snd_ac97_read(ac97, AC97_AD_MISC);
 	/* switch front/surround line-out/hp-out */
-	/* center/LFE, mic in 3.75V mode */
+	/* center/LFE */
 	/* AD-compatible mode */
 	/* Stereo mutes enabled */
 	/* in accordance with ADI driver: misc | 0x5c28 */
 	snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
-			     AC97_AD198X_VREFH |
 			     AC97_AD198X_LOSEL |
 			     AC97_AD198X_HPSEL |
 			     AC97_AD198X_CLDIS |

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel

#2 lore raw

Attached please find my latest patch of AC '97 CODEC improvements. This supersedes the patches I submitted on 30-Nov-2006 and 4-Dec-2006.

I am including my enhancements for the AD1985 and the AD1986/AD1986A CODECs in a single patch due to interdependencies.

Notes:
- I have tested AD1985 functionality to the extent possible (mostly by diffing register outputs).
- I have tested nearly all AD1986 functionality, except:
- My hardware is not equipped to test the Jack Sense mixer controls.
- I do not have any convenient method of testing the S/PDIF output at
this time.
- I made no effort to resolve anticipated Power Management issues.
- I noticed that the first time I booted with these new drivers installed, the front speaker balance was off. Moving the Master Surround slider all the way down and then back resolved the issue.

Randy Cushman

Quoted 60 lines · Randy Cushman

Attached please find my revision 2 patch of improvements to the AD1985 CODEC driver. This supersedes the patch I submitted on 30-Nov-2006, and patches the latest Mercurial source.

At this time I am figuring that I may be able to reduce the amount of work I create for the ALSA-Project team if I combine my work into a smaller number of patches. This combined patch includes all of the modifications I have planned for the AD1985 CODEC driver. I am continuing work on a patch to create separate AD1986/AD1986A CODEC driver code.

In this revised, combined patch I have included my "fix microphone and line_in selection logic" patch that should help users of the AD1985, along with many other multichannel CODECs. I have also decided to provide an enhanced V_REFOUT control, rather than simply remove the faulty control, as I had done in my previous revision.

Again, any feedback regarding my work is welcome.

Randy Cushman

Quoted 31 lines · Randy Cushman

(This message references ALSA bugtracking issue ID 2655.
https://bugtrack.alsa-project.org/alsa-bug/view.php?id=2655)

I am researching issues I am having with the audio chipsets onboard my ASUS A8S-X Motherboard, which has an AD1986A CODEC, using its AC'97 interface.

$ cat /proc/asound/cards
 0 [SI7012 ]: ICH - SiS SI7012
                      SiS SI7012 with AD1986 at 0x8000, irq 50

The attached patch file removes the "V_REFOUT Enable" mixer control that recently was added to the driver for the AD1888 CODEC, and was inherited by the driver for the AD1985 CODEC. The AD1986/AD1986A CODECs currently utilize the AD1985 driver.

I am preparing additional patches that will provide improved support for these CODECs. Please let me know if my work thus far is satisfactory.

Randy Cushman

------------------------------------------------------------------------

-------------------------------------------------------------------------

Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

Quoted 7 lines

------------------------------------------------------------------------

_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel

------------------------------------------------------------------------

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
------------------------------------------------------------------------

Quoted 5 lines

_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel

Summary: fix microphone and line_in selection logic

This patch fixes the Microphone and LINE_IN select logic for surround codecs with shared jacks. This issue appears to apply to most, if not all AC'97 surround codecs. The existing code can never utilize the shared jacks for Microphone and LINE_IN due to the reversed jack selection logic. The patched code correctly selects the shared jack for input if the "Channel Mode" selector does not specify that the jack is to be used for output.

Specifically, in "2ch" mode the Center/LFE jack is used for microphone input and the Surround jack is used for LINE_IN, in "4ch" mode the Center/LFE jack is used for microphone input and the Surround jack is used for output, and in "6ch" mode both jacks are used for output.

Summary: fix malfunctioning mixer controls for AD1985

This patch replaces the "V_REFOUT Enable" mixer switch control with a listbox control for the AD1985 CODEC.

Previous patch "AD1888 mixer controls for DC mode" added controls that were propogated to multiple codecs. For the AD1985 codec, the bits VREFH and VREFD function differently, preventing the "V_REFOUT Enable" control from setting V_REFOUT to Hi-Z.

This patch also corrects an issue in which register bits relating to mixer controls "Surround Jack Mode" and "Channel Mode". The register bits controlled by these controls were being set at boot time to states inconsistent with the stored values of these controls.

Summary: fix various issues with AD1986/AD1986A support

Previously, ac97_codec.c was coded to support AD1986 and AD1986A CODECs using code written for the AD1985 CODEC. This allowed the LINE_OUT and HEADPHONE jacks to function properly, however register differences between the CODECs prevented line and microphone inputs from functioning.

Specifically, this patch fixes issues with the following mixer
controls: 'V_REFOUT', 'Spread Front to Surround and Center/LFE', 'Exchange Front/Surround', 'Surround Jack Mode', and 'Channel Mode'. This patch removes the undocumented AD1888 control
'High Pass Filter Enable' and adds the new control 'Exchange Mic/Line In'.

include/ac97_codec.h +3 -0
diff -r bc7ef767d0cf include/ac97_codec.h
@@ -282,9 +282,11 @@
 #define AC97_AD_TEST		0x5a	/* test register */
 #define AC97_AD_TEST2		0x5c	/* undocumented test register 2 */
 #define AC97_AD_CODEC_CFG	0x70	/* codec configuration */
+#define AC97_AD_MISC2		0x70	/* Misc Control Bits 2 (AD1986) */
 #define AC97_AD_JACK_SPDIF	0x72	/* Jack Sense & S/PDIF */
 #define AC97_AD_SERIAL_CFG	0x74	/* Serial Configuration */
 #define AC97_AD_MISC		0x76	/* Misc Control Bits */
+#define AC97_AD_MISC3		0x7a	/* Misc Control Bits 3 (AD1986) */
 
 /* specific - Cirrus Logic */
 #define AC97_CSR_ACMODE		0x5e	/* AC Mode Register */
@@ -503,6 +505,7 @@ struct snd_ac97 {
 			unsigned short id[3];		// codec IDs (lower 16-bit word)
 			unsigned short pcmreg[3];	// PCM registers
 			unsigned short codec_cfg[3];	// CODEC_CFG bits
+			unsigned short swap_mic_linein;
 		} ad18xx;
 		unsigned int dev_flags;		/* device specific */
 	} spec;
pci/ac97/ac97_codec.c +1 -1
diff -r bc7ef767d0cf pci/ac97/ac97_codec.c
@@ -111,7 +111,7 @@ static const struct ac97_codec_id snd_ac
 { 0x41445372, 0xffffffff, "AD1981A",		patch_ad1981a,	NULL },
 { 0x41445374, 0xffffffff, "AD1981B",		patch_ad1981b,	NULL },
 { 0x41445375, 0xffffffff, "AD1985",		patch_ad1985,	NULL },
-{ 0x41445378, 0xffffffff, "AD1986",		patch_ad1985,	NULL },
+{ 0x41445378, 0xffffffff, "AD1986",		patch_ad1986,	NULL },
 { 0x414c4300, 0xffffff00, "ALC100,100P", 	NULL,		NULL },
 { 0x414c4710, 0xfffffff0, "ALC200,200P",	NULL,		NULL },
 { 0x414c4721, 0xffffffff, "ALC650D",		NULL,	NULL }, /* already patched */
pci/ac97/ac97_patch.c +428 -12

499 lines not on this page · raw message

pci/ac97/ac97_patch.h +1 -0
diff -r bc7ef767d0cf pci/ac97/ac97_patch.h
@@ -48,6 +48,7 @@ int patch_ad1981a(struct snd_ac97 * ac97
 int patch_ad1981a(struct snd_ac97 * ac97);
 int patch_ad1981b(struct snd_ac97 * ac97);
 int patch_ad1985(struct snd_ac97 * ac97);
+int patch_ad1986(struct snd_ac97 * ac97);
 int patch_alc650(struct snd_ac97 * ac97);
 int patch_alc655(struct snd_ac97 * ac97);
 int patch_alc850(struct snd_ac97 * ac97);

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel

#3 lore raw

Hi,

thanks for the patch.
For the ease of review, could you split your change to several patches? Please post one patch per mail, then.

Anyway, a quick review through the patch is below.

At Tue, 12 Dec 2006 19:31:33 -0500,

Quoted 11 lines · Randy Cushman

Summary: fix microphone and line_in selection logic

This patch fixes the Microphone and LINE_IN select logic for surround codecs with shared jacks. This issue appears to apply to most, if not all AC'97 surround codecs. The existing code can never utilize the shared jacks for Microphone and LINE_IN due to the reversed jack selection logic. The patched code correctly selects the shared jack for input if the "Channel Mode" selector does not specify that the jack is to be used for output.

Quoted 7 lines

Specifically, in "2ch" mode the Center/LFE jack is used for microphone input and the Surround jack is used for LINE_IN, in "4ch" mode the Center/LFE jack is used for microphone input and the Surround jack is used for output, and in "6ch" mode both jacks are used for output.

This hunk likely breaks other codec support.

is_shared_linein() returns true if the line-in jack is shared with surround output _and_ being used as the surround output. Maybe the AD codec support is wrongly implemented.

Quoted 11 lines

Summary: fix malfunctioning mixer controls for AD1985

This patch replaces the "V_REFOUT Enable" mixer switch control with a listbox control for the AD1985 CODEC.

Previous patch "AD1888 mixer controls for DC mode" added controls that were propogated to multiple codecs. For the AD1985 codec, the bits VREFH and VREFD function differently, preventing the "V_REFOUT Enable" control from setting V_REFOUT to Hi-Z.

Quoted 7 lines

This patch also corrects an issue in which register bits relating to mixer controls "Surround Jack Mode" and "Channel Mode". The register bits controlled by these controls were being set at boot time to states inconsistent with the stored values of these controls.

This change looks fine.

Quoted 8 lines

Summary: fix various issues with AD1986/AD1986A support

Previously, ac97_codec.c was coded to support AD1986 and AD1986A CODECs using code written for the AD1985 CODEC. This allowed the LINE_OUT and HEADPHONE jacks to function properly, however register differences between the CODECs prevented line and microphone inputs from functioning.

Quoted 8 lines

Specifically, this patch fixes issues with the following mixer
controls: 'V_REFOUT', 'Spread Front to Surround and Center/LFE', 'Exchange Front/Surround', 'Surround Jack Mode', and 'Channel Mode'. This patch removes the undocumented AD1888 control
'High Pass Filter Enable' and adds the new control 'Exchange Mic/Line In'.

This sounds fine, too.

include/ac97_codec.h line 289

Quoted 12 lines

diff -r bc7ef767d0cf include/ac97_codec.h

include/ac97_codec.h +2 -0
@@ -282,9 +282,11 @@
 #define AC97_AD_TEST		0x5a	/* test register */
 #define AC97_AD_TEST2		0x5c	/* undocumented test register 2 */
 #define AC97_AD_CODEC_CFG	0x70	/* codec configuration */
+#define AC97_AD_MISC2		0x70	/* Misc Control Bits 2 (AD1986) */
 #define AC97_AD_JACK_SPDIF	0x72	/* Jack Sense & S/PDIF */
 #define AC97_AD_SERIAL_CFG	0x74	/* Serial Configuration */
 #define AC97_AD_MISC		0x76	/* Misc Control Bits */
+#define AC97_AD_MISC3		0x7a	/* Misc Control Bits 3 (AD1986) */

These don't have to be defined in the public header. (I'd rather like to move all these codec-speicific definitions to
local file, i.e. ac97_patch.c or local headers.)

include/ac97_codec.h struct snd_ac97 { · line 508

Quoted 7 lines
include/ac97_codec.h +1 -0
 /* specific - Cirrus Logic */
 #define AC97_CSR_ACMODE		0x5e	/* AC Mode Register */
@@ -503,6 +505,7 @@ struct snd_ac97 {
 			unsigned short id[3];		// codec IDs (lower 16-bit word)
 			unsigned short pcmreg[3];	// PCM registers
 			unsigned short codec_cfg[3];	// CODEC_CFG bits
+			unsigned short swap_mic_linein;

Any need to be unsigned short?

Quoted 6 lines

diff -r bc7ef767d0cf pci/ac97/ac97_patch.c

pci/ac97/ac97_patch.c +0 -0
@@ -192,12 +192,12 @@ static inline int is_clfe_on(struct snd_
 
 static inline int is_shared_linein(struct snd_ac97 *ac97)

pci/ac97/ac97_patch.c static inline int is_clfe_on(struct snd_ · line 201

Quoted 10 lines
pci/ac97/ac97_patch.c +2 -2
 {
-	return ! ac97->indep_surround && is_surround_on(ac97);
+	return ! ac97->indep_surround && ! is_surround_on(ac97);
 }
 
 static inline int is_shared_micin(struct snd_ac97 *ac97)
 {
-	return ! ac97->indep_surround && is_clfe_on(ac97);
+	return ! ac97->indep_surround && ! is_clfe_on(ac97);
 }

Dangerous changes as I mentioned.

pci/ac97/ac97_patch.c int patch_ad1980(struct snd_ac97 * ac97) · line 2019

Quoted 1 line
pci/ac97/ac97_patch.c +1 -0
+static int snd_ac97_ad1985_vrefout_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)

Please fold lines to keep the (new) code within 80 columns.

pci/ac97/ac97_patch.c static int patch_ad1985_specific(struct · line 2103

Quoted 9 lines
pci/ac97/ac97_patch.c +3 -1
 static void ad1985_update_jacks(struct snd_ac97 *ac97)
@@ -1967,8 +2098,13 @@ static int patch_ad1985_specific(struct 
 {
 	int err;
 
-	if ((err = patch_ad1980_specific(ac97)) < 0)
+	/* rename 0x04 as "Master" and 0x02 as "Master Surround" */
+	snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Master Surround Playback");
+	snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback");

This rename would break many other boards since the renaming of master/headphone is usually done via ac97_quirk.

pci/ac97/ac97_patch.c int patch_ad1985(struct snd_ac97 * ac97) · line 2396

Quoted 6 lines
pci/ac97/ac97_patch.c +6 -0
+static int patch_ad1986_specific(struct snd_ac97 *ac97)
+{
+	int err;
+
+	/* rename 0x02 as "Master Surround" */
+	snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Master Surround Playback");

Ditto.

thanks,

Takashi

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

#5 lore raw

Re: Patch for AC97 AD CODEC shared jacks

In reply to a message not in the archive

At Tue, 19 Dec 2006 11:51:29 -0500,

Quoted 2 lines · Randy Cushman

Attached is the first of my split submissions.

Thanks!

Quoted 5 lines

Apparently you are correct. I compared the ALC650 datasheet with the corresponding code in ac97_patch.c. This analysis indicates that my change would have broken support for this chipset. Part of my confusion stemmed from the names of the functions in question, which I find to be counterintuitive.

Ah yes, the names are confusing.

Quoted 9 lines

Since some of your comments suggest to me that changes that improve code maintainability are sometimes preferable to changes that affect the fewest lines of code, in the attached patch I have taken the liberty of renaming functions to names that I find to be more meaningful.

I'll hold off on creating the remaining patches for now because my other patches may need to be changed if this patch is not accepted.

Please let me know what you think.

Then change looks fine. One minor request is not to put a space between '!' and the rest in the new codes. I used this style, but apparently it's no major and kernel people tend to dislike it.

[BTW, I added Cc to alsa-devel ML again, supposing that you forgot
it.]

Takashi

Quoted 208 lines

Randy Cushman

(From "Re: [Alsa-devel] Patch for AD1985 AC97 CODEC")

Quoted 36 lines · Takashi Iwai

Hi,

thanks for the patch.
For the ease of review, could you split your change to several patches? Please post one patch per mail, then.

Anyway, a quick review through the patch is below.

At Tue, 12 Dec 2006 19:31:33 -0500,

Quoted 10 lines · Randy Cushman

Summary: fix microphone and line_in selection logic

This patch fixes the Microphone and LINE_IN select logic for surround codecs with shared jacks. This issue appears to apply to most, if not all AC'97 surround codecs. The existing code can never utilize the shared jacks for Microphone and LINE_IN due to the reversed jack selection logic. The patched code correctly selects the shared jack for input if the "Channel Mode" selector does not specify that the jack is to be used for output.

Quoted 8 lines

Specifically, in "2ch" mode the Center/LFE jack is used for microphone input and the Surround jack is used for LINE_IN, in "4ch" mode the Center/LFE jack is used for microphone input and the Surround jack is used for output, and in "6ch" mode both jacks are used for output.

This hunk likely breaks other codec support.

is_shared_linein() returns true if the line-in jack is shared with surround output _and_ being used as the surround output. Maybe the AD codec support is wrongly implemented.

(snip)

Quoted 6 lines

thanks,

Takashi

[2 ac97_shared_1.patch <text/plain (7bit)>]
Summary: fix microphone and line_in selection logic

This patch fixes the Microphone and LINE_IN select logic for Analog Devices surround codecs with shared jacks. The existing code can never utilize the shared jacks for Microphone and LINE_IN due to the reversed jack selection logic. The patched code correctly selects the shared jack for input if the "Channel Mode" selector does not specify that the jack is to be used for output.

Specifically, in "2ch" mode the Center/LFE jack is used for microphone input and the Surround jack is used for LINE_IN, in "4ch" mode the Center/LFE jack is used for microphone input and the Surround jack is used for output, and in "6ch" mode both jacks are used for output.

diff -r cdbbd773cd9e pci/ac97/ac97_patch.c

pci/ac97/ac97_patch.c +39 -25
@@ -190,14 +190,28 @@ static inline int is_clfe_on(struct snd_
 	return ac97->channel_mode >= 2;
 }
 
+/* system has shared jacks with surround out enabled */
+static inline int is_shared_surrout(struct snd_ac97 *ac97)
+{
+	return ! ac97->indep_surround && is_surround_on(ac97);
+}
+
+/* system has shared jacks with center/lfe out enabled */
+static inline int is_shared_clfeout(struct snd_ac97 *ac97)
+{
+	return ! ac97->indep_surround && is_clfe_on(ac97);
+}
+
+/* system has shared jacks with line in enabled */
 static inline int is_shared_linein(struct snd_ac97 *ac97)
 {
-	return ! ac97->indep_surround && is_surround_on(ac97);
-}
-
+	return ! ac97->indep_surround && ! is_surround_on(ac97);
+}
+
+/* system has shared jacks with mic in enabled */
 static inline int is_shared_micin(struct snd_ac97 *ac97)
 {
-	return ! ac97->indep_surround && is_clfe_on(ac97);
+	return ! ac97->indep_surround && ! is_clfe_on(ac97);
 }
 
 
@@ -2014,12 +2028,12 @@ static void alc650_update_jacks(struct s
 {
 	int shared;
 
-	/* shared Line-In */
-	shared = is_shared_linein(ac97);
+	/* shared Line-In / Surround Out */
+	shared = is_shared_surrout(ac97);
 	snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 9,
 			     shared ? (1 << 9) : 0);
-	/* update shared Mic */
-	shared = is_shared_micin(ac97);
+	/* update shared Mic In / Center/LFE Out */
+	shared = is_shared_clfeout(ac97);
 	/* disable/enable vref */
 	snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
 			     shared ? (1 << 12) : 0);
@@ -2149,12 +2163,12 @@ static void alc655_update_jacks(struct s
 {
 	int shared;
 
-	/* shared Line-In */
-	shared = is_shared_linein(ac97);
+	/* shared Line-In / Surround Out */
+	shared = is_shared_surrout(ac97);
 	ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 9,
 			      shared ? (1 << 9) : 0, 0);
-	/* update shared mic */
-	shared = is_shared_micin(ac97);
+	/* update shared Mic In / Center/LFE Out */
+	shared = is_shared_clfeout(ac97);
 	/* misc control; vrefout disable */
 	snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
 			     shared ? (1 << 12) : 0);
@@ -2298,16 +2312,16 @@ static void alc850_update_jacks(struct s
 {
 	int shared;
 
-	/* shared Line-In */
-	shared = is_shared_linein(ac97);
+	/* shared Line-In / Surround Out */
+	shared = is_shared_surrout(ac97);
 	/* SURR 1kOhm (bit4), Amp (bit5) */
 	snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<4)|(1<<5),
 			     shared ? (1<<5) : (1<<4));
 	/* LINE-IN = 0, SURROUND = 2 */
 	snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 12,
 			     shared ? (2<<12) : (0<<12));
-	/* update shared mic */
-	shared = is_shared_micin(ac97);
+	/* update shared Mic In / Center/LFE Out */
+	shared = is_shared_clfeout(ac97);
 	/* Vref disable (bit12), 1kOhm (bit13) */
 	snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<12)|(1<<13),
 			     shared ? (1<<12) : (1<<13));
@@ -2380,9 +2394,9 @@ int patch_alc850(struct snd_ac97 *ac97)
  */
 static void cm9738_update_jacks(struct snd_ac97 *ac97)
 {
-	/* shared Line-In */
+	/* shared Line-In / Surround Out */
 	snd_ac97_update_bits(ac97, AC97_CM9738_VENDOR_CTRL, 1 << 10,
-			     is_shared_linein(ac97) ? (1 << 10) : 0);
+			     is_shared_surrout(ac97) ? (1 << 10) : 0);
 }
 
 static const struct snd_kcontrol_new snd_ac97_cm9738_controls[] = {
@@ -2464,12 +2478,12 @@ static const struct snd_kcontrol_new snd
 
 static void cm9739_update_jacks(struct snd_ac97 *ac97)
 {
-	/* shared Line-In */
+	/* shared Line-In / Surround Out */
 	snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 1 << 10,
-			     is_shared_linein(ac97) ? (1 << 10) : 0);
-	/* shared Mic */
+			     is_shared_surrout(ac97) ? (1 << 10) : 0);
+	/* shared Mic In / Center/LFE Out **/
 	snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 0x3000,
-			     is_shared_micin(ac97) ? 0x1000 : 0x2000);
+			     is_shared_clfeout(ac97) ? 0x1000 : 0x2000);
 }
 
 static const struct snd_kcontrol_new snd_ac97_cm9739_controls[] = {
@@ -2581,8 +2595,8 @@ static void cm9761_update_jacks(struct s
 
 	val |= surr_on[ac97->spec.dev_flags][is_surround_on(ac97)];
 	val |= clfe_on[ac97->spec.dev_flags][is_clfe_on(ac97)];
-	val |= surr_shared[ac97->spec.dev_flags][is_shared_linein(ac97)];
-	val |= clfe_shared[ac97->spec.dev_flags][is_shared_micin(ac97)];
+	val |= surr_shared[ac97->spec.dev_flags][is_shared_surrout(ac97)];
+	val |= clfe_shared[ac97->spec.dev_flags][is_shared_clfeout(ac97)];
 
 	snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x3c88, val);
 }
@@ -2829,12 +2843,12 @@ int patch_vt1617a(struct snd_ac97 * ac97
  */
 static void it2646_update_jacks(struct snd_ac97 *ac97)
 {
-	/* shared Line-In */
+	/* shared Line-In / Surround Out */
 	snd_ac97_update_bits(ac97, 0x76, 1 << 9,

pci/ac97/ac97_patch.c int patch_vt1617a(struct snd_ac97 * ac97 · line 2854

Quoted 10 lines
pci/ac97/ac97_patch.c +3 -3
-			     is_shared_linein(ac97) ? (1<<9) : 0);
-	/* shared Mic */
+			     is_shared_surrout(ac97) ? (1<<9) : 0);
+	/* shared Mic / Center/LFE Out */
 	snd_ac97_update_bits(ac97, 0x76, 1 << 10,
-			     is_shared_micin(ac97) ? (1<<10) : 0);
+			     is_shared_clfeout(ac97) ? (1<<10) : 0);
 }
 
 static const struct snd_kcontrol_new snd_ac97_controls_it2646[] = {

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

#6 lore raw

Re: Patch for AC97 AD CODEC shared jacks

Minor request implemented.

Randy Cushman

Quoted 255 lines · Takashi Iwai

At Tue, 19 Dec 2006 11:51:29 -0500,

Quoted 2 lines · Randy Cushman

Attached is the first of my split submissions.

Thanks!

Quoted 2 lines

Apparently you are correct. I compared the ALC650 datasheet with the corresponding code in ac97_patch.c. This analysis indicates that my change would have broken support for this chipset. Part of my confusion stemmed from the names of the functions in question, which I find to be counterintuitive.

Ah yes, the names are confusing.

Quoted 6 lines

Since some of your comments suggest to me that changes that improve code maintainability are sometimes preferable to changes that affect the fewest lines of code, in the attached patch I have taken the liberty of renaming functions to names that I find to be more meaningful.

I'll hold off on creating the remaining patches for now because my other patches may need to be changed if this patch is not accepted.

Please let me know what you think.

Then change looks fine. One minor request is not to put a space between '!' and the rest in the new codes. I used this style, but apparently it's no major and kernel people tend to dislike it.

[BTW, I added Cc to alsa-devel ML again, supposing that you forgot
it.]

Takashi

Quoted 220 lines

Randy Cushman

(From "Re: [Alsa-devel] Patch for AD1985 AC97 CODEC")

Quoted 38 lines · Takashi Iwai

Hi,

thanks for the patch.
For the ease of review, could you split your change to several patches? Please post one patch per mail, then.

Anyway, a quick review through the patch is below.

At Tue, 12 Dec 2006 19:31:33 -0500,

Quoted 10 lines · Randy Cushman

Summary: fix microphone and line_in selection logic

This patch fixes the Microphone and LINE_IN select logic for surround codecs with shared jacks. This issue appears to apply to most, if not all AC'97 surround codecs. The existing code can never utilize the shared jacks for Microphone and LINE_IN due to the reversed jack selection logic. The patched code correctly selects the shared jack for input if the "Channel Mode" selector does not specify that the jack is to be used for output.

Quoted 9 lines

Specifically, in "2ch" mode the Center/LFE jack is used for microphone input and the Surround jack is used for LINE_IN, in "4ch" mode the Center/LFE jack is used for microphone input and the Surround jack is used for output, and in "6ch" mode both jacks are used for output.

This hunk likely breaks other codec support.

is_shared_linein() returns true if the line-in jack is shared with surround output _and_ being used as the surround output. Maybe the AD codec support is wrongly implemented.

(snip)

Quoted 7 lines

thanks,

Takashi

[2 ac97_shared_1.patch <text/plain (7bit)>]
Summary: fix microphone and line_in selection logic

This patch fixes the Microphone and LINE_IN select logic for Analog Devices surround codecs with shared jacks. The existing code can never utilize the shared jacks for Microphone and LINE_IN due to the reversed jack selection logic. The patched code correctly selects the shared jack for input if the "Channel Mode" selector does not specify that the jack is to be used for output.

Specifically, in "2ch" mode the Center/LFE jack is used for microphone input and the Surround jack is used for LINE_IN, in "4ch" mode the Center/LFE jack is used for microphone input and the Surround jack is used for output, and in "6ch" mode both jacks are used for output.

diff -r cdbbd773cd9e pci/ac97/ac97_patch.c

pci/ac97/ac97_patch.c +42 -28
@@ -190,14 +190,28 @@ static inline int is_clfe_on(struct snd_
 	return ac97->channel_mode >= 2;
 }
 
+/* system has shared jacks with surround out enabled */
+static inline int is_shared_surrout(struct snd_ac97 *ac97)
+{
+	return ! ac97->indep_surround && is_surround_on(ac97);
+}
+
+/* system has shared jacks with center/lfe out enabled */
+static inline int is_shared_clfeout(struct snd_ac97 *ac97)
+{
+	return ! ac97->indep_surround && is_clfe_on(ac97);
+}
+
+/* system has shared jacks with line in enabled */
 static inline int is_shared_linein(struct snd_ac97 *ac97)
 {
-	return ! ac97->indep_surround && is_surround_on(ac97);
-}
-
+	return ! ac97->indep_surround && ! is_surround_on(ac97);
+}
+
+/* system has shared jacks with mic in enabled */
 static inline int is_shared_micin(struct snd_ac97 *ac97)
 {
-	return ! ac97->indep_surround && is_clfe_on(ac97);
+	return ! ac97->indep_surround && ! is_clfe_on(ac97);
 }
 
 
@@ -2014,12 +2028,12 @@ static void alc650_update_jacks(struct s
 {
 	int shared;
 
-	/* shared Line-In */
-	shared = is_shared_linein(ac97);
+	/* shared Line-In / Surround Out */
+	shared = is_shared_surrout(ac97);
 	snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 9,
 			     shared ? (1 << 9) : 0);
-	/* update shared Mic */
-	shared = is_shared_micin(ac97);
+	/* update shared Mic In / Center/LFE Out */
+	shared = is_shared_clfeout(ac97);
 	/* disable/enable vref */
 	snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
 			     shared ? (1 << 12) : 0);
@@ -2149,12 +2163,12 @@ static void alc655_update_jacks(struct s
 {
 	int shared;
 
-	/* shared Line-In */
-	shared = is_shared_linein(ac97);
+	/* shared Line-In / Surround Out */
+	shared = is_shared_surrout(ac97);
 	ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 9,
 			      shared ? (1 << 9) : 0, 0);
-	/* update shared mic */
-	shared = is_shared_micin(ac97);
+	/* update shared Mic In / Center/LFE Out */
+	shared = is_shared_clfeout(ac97);
 	/* misc control; vrefout disable */
 	snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
 			     shared ? (1 << 12) : 0);
@@ -2298,16 +2312,16 @@ static void alc850_update_jacks(struct s
 {
 	int shared;
 
-	/* shared Line-In */
-	shared = is_shared_linein(ac97);
+	/* shared Line-In / Surround Out */
+	shared = is_shared_surrout(ac97);
 	/* SURR 1kOhm (bit4), Amp (bit5) */
 	snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<4)|(1<<5),
 			     shared ? (1<<5) : (1<<4));
 	/* LINE-IN = 0, SURROUND = 2 */
 	snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 12,
 			     shared ? (2<<12) : (0<<12));
-	/* update shared mic */
-	shared = is_shared_micin(ac97);
+	/* update shared Mic In / Center/LFE Out */
+	shared = is_shared_clfeout(ac97);
 	/* Vref disable (bit12), 1kOhm (bit13) */
 	snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<12)|(1<<13),
 			     shared ? (1<<12) : (1<<13));
@@ -2380,9 +2394,9 @@ int patch_alc850(struct snd_ac97 *ac97)
  */
 static void cm9738_update_jacks(struct snd_ac97 *ac97)
 {
-	/* shared Line-In */
+	/* shared Line-In / Surround Out */
 	snd_ac97_update_bits(ac97, AC97_CM9738_VENDOR_CTRL, 1 << 10,
-			     is_shared_linein(ac97) ? (1 << 10) : 0);
+			     is_shared_surrout(ac97) ? (1 << 10) : 0);
 }
 
 static const struct snd_kcontrol_new snd_ac97_cm9738_controls[] = {
@@ -2464,12 +2478,12 @@ static const struct snd_kcontrol_new snd
 
 static void cm9739_update_jacks(struct snd_ac97 *ac97)
 {
-	/* shared Line-In */
+	/* shared Line-In / Surround Out */
 	snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 1 << 10,
-			     is_shared_linein(ac97) ? (1 << 10) : 0);
-	/* shared Mic */
+			     is_shared_surrout(ac97) ? (1 << 10) : 0);
+	/* shared Mic In / Center/LFE Out **/
 	snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 0x3000,
-			     is_shared_micin(ac97) ? 0x1000 : 0x2000);
+			     is_shared_clfeout(ac97) ? 0x1000 : 0x2000);
 }
 
 static const struct snd_kcontrol_new snd_ac97_cm9739_controls[] = {
@@ -2581,8 +2595,8 @@ static void cm9761_update_jacks(struct s
 
 	val |= surr_on[ac97->spec.dev_flags][is_surround_on(ac97)];
 	val |= clfe_on[ac97->spec.dev_flags][is_clfe_on(ac97)];
-	val |= surr_shared[ac97->spec.dev_flags][is_shared_linein(ac97)];
-	val |= clfe_shared[ac97->spec.dev_flags][is_shared_micin(ac97)];
+	val |= surr_shared[ac97->spec.dev_flags][is_shared_surrout(ac97)];
+	val |= clfe_shared[ac97->spec.dev_flags][is_shared_clfeout(ac97)];
 
 	snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x3c88, val);
 }
@@ -2829,12 +2843,12 @@ int patch_vt1617a(struct snd_ac97 * ac97
  */
 static void it2646_update_jacks(struct snd_ac97 *ac97)
 {
-	/* shared Line-In */
+	/* shared Line-In / Surround Out */
 	snd_ac97_update_bits(ac97, 0x76, 1 << 9,
-			     is_shared_linein(ac97) ? (1<<9) : 0);
-	/* shared Mic */
+			     is_shared_surrout(ac97) ? (1<<9) : 0);
+	/* shared Mic / Center/LFE Out */
 	snd_ac97_update_bits(ac97, 0x76, 1 << 10,
-			     is_shared_micin(ac97) ? (1<<10) : 0);
+			     is_shared_clfeout(ac97) ? (1<<10) : 0);
 }
 
Quoted 5 lines

pci/ac97/ac97_patch.c int patch_vt1617a(struct snd_ac97 * ac97 · line 2854

Quoted 2 lines
pci/ac97/ac97_patch.c +0 -0
 static const struct snd_kcontrol_new snd_ac97_controls_it2646[] = {

Summary: fix microphone and line_in selection logic

This patch fixes the Microphone and LINE_IN select logic for Analog Devices surround codecs with shared jacks. The existing code can never utilize the shared jacks for Microphone and LINE_IN due to the reversed jack selection logic. The patched code correctly selects the shared jack for input if the "Channel Mode" selector does not specify that the jack is to be used for output.

Specifically, in "2ch" mode the Center/LFE jack is used for microphone input and the Surround jack is used for LINE_IN, in "4ch" mode the Center/LFE jack is used for microphone input and the Surround jack is used for output, and in "6ch" mode both jacks are used for output.

pci/ac97/ac97_patch.c +42 -28
diff -r cdbbd773cd9e pci/ac97/ac97_patch.c
@@ -190,14 +190,28 @@ static inline int is_clfe_on(struct snd_
 	return ac97->channel_mode >= 2;
 }
 
+/* system has shared jacks with surround out enabled */
+static inline int is_shared_surrout(struct snd_ac97 *ac97)
+{
+	return !ac97->indep_surround && is_surround_on(ac97);
+}
+
+/* system has shared jacks with center/lfe out enabled */
+static inline int is_shared_clfeout(struct snd_ac97 *ac97)
+{
+	return !ac97->indep_surround && is_clfe_on(ac97);
+}
+
+/* system has shared jacks with line in enabled */
 static inline int is_shared_linein(struct snd_ac97 *ac97)
 {
-	return ! ac97->indep_surround && is_surround_on(ac97);
-}
-
+	return !ac97->indep_surround && !is_surround_on(ac97);
+}
+
+/* system has shared jacks with mic in enabled */
 static inline int is_shared_micin(struct snd_ac97 *ac97)
 {
-	return ! ac97->indep_surround && is_clfe_on(ac97);
+	return !ac97->indep_surround && !is_clfe_on(ac97);
 }
 
 
@@ -2014,12 +2028,12 @@ static void alc650_update_jacks(struct s
 {
 	int shared;
 	
-	/* shared Line-In */
-	shared = is_shared_linein(ac97);
+	/* shared Line-In / Surround Out */
+	shared = is_shared_surrout(ac97);
 	snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 9,
 			     shared ? (1 << 9) : 0);
-	/* update shared Mic */
-	shared = is_shared_micin(ac97);
+	/* update shared Mic In / Center/LFE Out */
+	shared = is_shared_clfeout(ac97);
 	/* disable/enable vref */
 	snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
 			     shared ? (1 << 12) : 0);
@@ -2149,12 +2163,12 @@ static void alc655_update_jacks(struct s
 {
 	int shared;
 	
-	/* shared Line-In */
-	shared = is_shared_linein(ac97);
+	/* shared Line-In / Surround Out */
+	shared = is_shared_surrout(ac97);
 	ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 9,
 			      shared ? (1 << 9) : 0, 0);
-	/* update shared mic */
-	shared = is_shared_micin(ac97);
+	/* update shared Mic In / Center/LFE Out */
+	shared = is_shared_clfeout(ac97);
 	/* misc control; vrefout disable */
 	snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
 			     shared ? (1 << 12) : 0);
@@ -2298,16 +2312,16 @@ static void alc850_update_jacks(struct s
 {
 	int shared;
 	
-	/* shared Line-In */
-	shared = is_shared_linein(ac97);
+	/* shared Line-In / Surround Out */
+	shared = is_shared_surrout(ac97);
 	/* SURR 1kOhm (bit4), Amp (bit5) */
 	snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<4)|(1<<5),
 			     shared ? (1<<5) : (1<<4));
 	/* LINE-IN = 0, SURROUND = 2 */
 	snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 12,
 			     shared ? (2<<12) : (0<<12));
-	/* update shared mic */
-	shared = is_shared_micin(ac97);
+	/* update shared Mic In / Center/LFE Out */
+	shared = is_shared_clfeout(ac97);
 	/* Vref disable (bit12), 1kOhm (bit13) */
 	snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<12)|(1<<13),
 			     shared ? (1<<12) : (1<<13));
@@ -2380,9 +2394,9 @@ int patch_alc850(struct snd_ac97 *ac97)
  */
 static void cm9738_update_jacks(struct snd_ac97 *ac97)
 {
-	/* shared Line-In */
+	/* shared Line-In / Surround Out */
 	snd_ac97_update_bits(ac97, AC97_CM9738_VENDOR_CTRL, 1 << 10,
-			     is_shared_linein(ac97) ? (1 << 10) : 0);
+			     is_shared_surrout(ac97) ? (1 << 10) : 0);
 }
 
 static const struct snd_kcontrol_new snd_ac97_cm9738_controls[] = {
@@ -2464,12 +2478,12 @@ static const struct snd_kcontrol_new snd
 
 static void cm9739_update_jacks(struct snd_ac97 *ac97)
 {
-	/* shared Line-In */
+	/* shared Line-In / Surround Out */
 	snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 1 << 10,
-			     is_shared_linein(ac97) ? (1 << 10) : 0);
-	/* shared Mic */
+			     is_shared_surrout(ac97) ? (1 << 10) : 0);
+	/* shared Mic In / Center/LFE Out **/
 	snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 0x3000,
-			     is_shared_micin(ac97) ? 0x1000 : 0x2000);
+			     is_shared_clfeout(ac97) ? 0x1000 : 0x2000);
 }
 
 static const struct snd_kcontrol_new snd_ac97_cm9739_controls[] = {
@@ -2581,8 +2595,8 @@ static void cm9761_update_jacks(struct s
 
 	val |= surr_on[ac97->spec.dev_flags][is_surround_on(ac97)];
 	val |= clfe_on[ac97->spec.dev_flags][is_clfe_on(ac97)];
-	val |= surr_shared[ac97->spec.dev_flags][is_shared_linein(ac97)];
-	val |= clfe_shared[ac97->spec.dev_flags][is_shared_micin(ac97)];
+	val |= surr_shared[ac97->spec.dev_flags][is_shared_surrout(ac97)];
+	val |= clfe_shared[ac97->spec.dev_flags][is_shared_clfeout(ac97)];
 
 	snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x3c88, val);
 }
@@ -2829,12 +2843,12 @@ int patch_vt1617a(struct snd_ac97 * ac97
  */
 static void it2646_update_jacks(struct snd_ac97 *ac97)
 {
-	/* shared Line-In */
+	/* shared Line-In / Surround Out */
 	snd_ac97_update_bits(ac97, 0x76, 1 << 9,
-			     is_shared_linein(ac97) ? (1<<9) : 0);
-	/* shared Mic */
+			     is_shared_surrout(ac97) ? (1<<9) : 0);
+	/* shared Mic / Center/LFE Out */
 	snd_ac97_update_bits(ac97, 0x76, 1 << 10,
-			     is_shared_micin(ac97) ? (1<<10) : 0);
+			     is_shared_clfeout(ac97) ? (1<<10) : 0);
 }
 
 static const struct snd_kcontrol_new snd_ac97_controls_it2646[] = {

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel

#7 lore raw

Re: Patch for AC97 AD CODEC shared jacks

At Tue, 19 Dec 2006 12:37:46 -0500,

Quoted 2 lines · Randy Cushman

Minor request implemented.

Thanks, now I applied it to ALSA HG repo.

Takashi

Quoted 431 lines

Randy Cushman

Quoted 263 lines · Takashi Iwai

At Tue, 19 Dec 2006 11:51:29 -0500,

Quoted 2 lines · Randy Cushman

Attached is the first of my split submissions.

Thanks!

Quoted 6 lines

Apparently you are correct. I compared the ALC650 datasheet with the corresponding code in ac97_patch.c. This analysis indicates that my change would have broken support for this chipset. Part of my confusion stemmed from the names of the functions in question, which I find to be counterintuitive.

Ah yes, the names are confusing.

Quoted 10 lines

Since some of your comments suggest to me that changes that improve code maintainability are sometimes preferable to changes that affect the fewest lines of code, in the attached patch I have taken the liberty of renaming functions to names that I find to be more meaningful.

I'll hold off on creating the remaining patches for now because my other patches may need to be changed if this patch is not accepted.

Please let me know what you think.

Then change looks fine. One minor request is not to put a space between '!' and the rest in the new codes. I used this style, but apparently it's no major and kernel people tend to dislike it.

[BTW, I added Cc to alsa-devel ML again, supposing that you forgot
it.]

Takashi

Quoted 220 lines

Randy Cushman

(From "Re: [Alsa-devel] Patch for AD1985 AC97 CODEC")

Quoted 38 lines · Takashi Iwai

Hi,

thanks for the patch.
For the ease of review, could you split your change to several patches? Please post one patch per mail, then.

Anyway, a quick review through the patch is below.

At Tue, 12 Dec 2006 19:31:33 -0500,

Quoted 10 lines · Randy Cushman

Summary: fix microphone and line_in selection logic

This patch fixes the Microphone and LINE_IN select logic for surround codecs with shared jacks. This issue appears to apply to most, if not all AC'97 surround codecs. The existing code can never utilize the shared jacks for Microphone and LINE_IN due to the reversed jack selection logic. The patched code correctly selects the shared jack for input if the "Channel Mode" selector does not specify that the jack is to be used for output.

Quoted 9 lines

Specifically, in "2ch" mode the Center/LFE jack is used for microphone input and the Surround jack is used for LINE_IN, in "4ch" mode the Center/LFE jack is used for microphone input and the Surround jack is used for output, and in "6ch" mode both jacks are used for output.

This hunk likely breaks other codec support.

is_shared_linein() returns true if the line-in jack is shared with surround output _and_ being used as the surround output. Maybe the AD codec support is wrongly implemented.

(snip)

Quoted 7 lines

thanks,

Takashi

[2 ac97_shared_1.patch <text/plain (7bit)>]
Summary: fix microphone and line_in selection logic

This patch fixes the Microphone and LINE_IN select logic for Analog Devices surround codecs with shared jacks. The existing code can never utilize the shared jacks for Microphone and LINE_IN due to the reversed jack selection logic. The patched code correctly selects the shared jack for input if the "Channel Mode" selector does not specify that the jack is to be used for output.

Specifically, in "2ch" mode the Center/LFE jack is used for microphone input and the Surround jack is used for LINE_IN, in "4ch" mode the Center/LFE jack is used for microphone input and the Surround jack is used for output, and in "6ch" mode both jacks are used for output.

diff -r cdbbd773cd9e pci/ac97/ac97_patch.c

pci/ac97/ac97_patch.c +42 -28
@@ -190,14 +190,28 @@ static inline int is_clfe_on(struct snd_
 	return ac97->channel_mode >= 2;
 }
 
+/* system has shared jacks with surround out enabled */
+static inline int is_shared_surrout(struct snd_ac97 *ac97)
+{
+	return ! ac97->indep_surround && is_surround_on(ac97);
+}
+
+/* system has shared jacks with center/lfe out enabled */
+static inline int is_shared_clfeout(struct snd_ac97 *ac97)
+{
+	return ! ac97->indep_surround && is_clfe_on(ac97);
+}
+
+/* system has shared jacks with line in enabled */
 static inline int is_shared_linein(struct snd_ac97 *ac97)
 {
-	return ! ac97->indep_surround && is_surround_on(ac97);
-}
-
+	return ! ac97->indep_surround && ! is_surround_on(ac97);
+}
+
+/* system has shared jacks with mic in enabled */
 static inline int is_shared_micin(struct snd_ac97 *ac97)
 {
-	return ! ac97->indep_surround && is_clfe_on(ac97);
+	return ! ac97->indep_surround && ! is_clfe_on(ac97);
 }
 
 
@@ -2014,12 +2028,12 @@ static void alc650_update_jacks(struct s
 {
 	int shared;
 
-	/* shared Line-In */
-	shared = is_shared_linein(ac97);
+	/* shared Line-In / Surround Out */
+	shared = is_shared_surrout(ac97);
 	snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 9,
 			     shared ? (1 << 9) : 0);
-	/* update shared Mic */
-	shared = is_shared_micin(ac97);
+	/* update shared Mic In / Center/LFE Out */
+	shared = is_shared_clfeout(ac97);
 	/* disable/enable vref */
 	snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
 			     shared ? (1 << 12) : 0);
@@ -2149,12 +2163,12 @@ static void alc655_update_jacks(struct s
 {
 	int shared;
 
-	/* shared Line-In */
-	shared = is_shared_linein(ac97);
+	/* shared Line-In / Surround Out */
+	shared = is_shared_surrout(ac97);
 	ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 9,
 			      shared ? (1 << 9) : 0, 0);
-	/* update shared mic */
-	shared = is_shared_micin(ac97);
+	/* update shared Mic In / Center/LFE Out */
+	shared = is_shared_clfeout(ac97);
 	/* misc control; vrefout disable */
 	snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
 			     shared ? (1 << 12) : 0);
@@ -2298,16 +2312,16 @@ static void alc850_update_jacks(struct s
 {
 	int shared;
 
-	/* shared Line-In */
-	shared = is_shared_linein(ac97);
+	/* shared Line-In / Surround Out */
+	shared = is_shared_surrout(ac97);
 	/* SURR 1kOhm (bit4), Amp (bit5) */
 	snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<4)|(1<<5),
 			     shared ? (1<<5) : (1<<4));
 	/* LINE-IN = 0, SURROUND = 2 */
 	snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 12,
 			     shared ? (2<<12) : (0<<12));
-	/* update shared mic */
-	shared = is_shared_micin(ac97);
+	/* update shared Mic In / Center/LFE Out */
+	shared = is_shared_clfeout(ac97);
 	/* Vref disable (bit12), 1kOhm (bit13) */
 	snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<12)|(1<<13),
 			     shared ? (1<<12) : (1<<13));
@@ -2380,9 +2394,9 @@ int patch_alc850(struct snd_ac97 *ac97)
  */
 static void cm9738_update_jacks(struct snd_ac97 *ac97)
 {
-	/* shared Line-In */
+	/* shared Line-In / Surround Out */
 	snd_ac97_update_bits(ac97, AC97_CM9738_VENDOR_CTRL, 1 << 10,
-			     is_shared_linein(ac97) ? (1 << 10) : 0);
+			     is_shared_surrout(ac97) ? (1 << 10) : 0);
 }
 
 static const struct snd_kcontrol_new snd_ac97_cm9738_controls[] = {
@@ -2464,12 +2478,12 @@ static const struct snd_kcontrol_new snd
 
 static void cm9739_update_jacks(struct snd_ac97 *ac97)
 {
-	/* shared Line-In */
+	/* shared Line-In / Surround Out */
 	snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 1 << 10,
-			     is_shared_linein(ac97) ? (1 << 10) : 0);
-	/* shared Mic */
+			     is_shared_surrout(ac97) ? (1 << 10) : 0);
+	/* shared Mic In / Center/LFE Out **/
 	snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 0x3000,
-			     is_shared_micin(ac97) ? 0x1000 : 0x2000);
+			     is_shared_clfeout(ac97) ? 0x1000 : 0x2000);
 }
 
 static const struct snd_kcontrol_new snd_ac97_cm9739_controls[] = {
@@ -2581,8 +2595,8 @@ static void cm9761_update_jacks(struct s
 
 	val |= surr_on[ac97->spec.dev_flags][is_surround_on(ac97)];
 	val |= clfe_on[ac97->spec.dev_flags][is_clfe_on(ac97)];
-	val |= surr_shared[ac97->spec.dev_flags][is_shared_linein(ac97)];
-	val |= clfe_shared[ac97->spec.dev_flags][is_shared_micin(ac97)];
+	val |= surr_shared[ac97->spec.dev_flags][is_shared_surrout(ac97)];
+	val |= clfe_shared[ac97->spec.dev_flags][is_shared_clfeout(ac97)];
 
 	snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x3c88, val);
 }
@@ -2829,12 +2843,12 @@ int patch_vt1617a(struct snd_ac97 * ac97
  */
 static void it2646_update_jacks(struct snd_ac97 *ac97)
 {
-	/* shared Line-In */
+	/* shared Line-In / Surround Out */
 	snd_ac97_update_bits(ac97, 0x76, 1 << 9,
-			     is_shared_linein(ac97) ? (1<<9) : 0);
-	/* shared Mic */
+			     is_shared_surrout(ac97) ? (1<<9) : 0);
+	/* shared Mic / Center/LFE Out */
 	snd_ac97_update_bits(ac97, 0x76, 1 << 10,
-			     is_shared_micin(ac97) ? (1<<10) : 0);
+			     is_shared_clfeout(ac97) ? (1<<10) : 0);
 }
 
Quoted 5 lines

pci/ac97/ac97_patch.c int patch_vt1617a(struct snd_ac97 * ac97 · line 2854

Quoted 2 lines
pci/ac97/ac97_patch.c +0 -0
 static const struct snd_kcontrol_new snd_ac97_controls_it2646[] = {

[2 ac97_shared_2.patch <text/plain (7bit)>]
Summary: fix microphone and line_in selection logic

This patch fixes the Microphone and LINE_IN select logic for Analog Devices surround codecs with shared jacks. The existing code can never utilize the shared jacks for Microphone and LINE_IN due to the reversed jack selection logic. The patched code correctly selects the shared jack for input if the "Channel Mode" selector does not specify that the jack is to be used for output.

Specifically, in "2ch" mode the Center/LFE jack is used for microphone input and the Surround jack is used for LINE_IN, in "4ch" mode the Center/LFE jack is used for microphone input and the Surround jack is used for output, and in "6ch" mode both jacks are used for output.

diff -r cdbbd773cd9e pci/ac97/ac97_patch.c

pci/ac97/ac97_patch.c +39 -25
@@ -190,14 +190,28 @@ static inline int is_clfe_on(struct snd_
 	return ac97->channel_mode >= 2;
 }
 
+/* system has shared jacks with surround out enabled */
+static inline int is_shared_surrout(struct snd_ac97 *ac97)
+{
+	return !ac97->indep_surround && is_surround_on(ac97);
+}
+
+/* system has shared jacks with center/lfe out enabled */
+static inline int is_shared_clfeout(struct snd_ac97 *ac97)
+{
+	return !ac97->indep_surround && is_clfe_on(ac97);
+}
+
+/* system has shared jacks with line in enabled */
 static inline int is_shared_linein(struct snd_ac97 *ac97)
 {
-	return ! ac97->indep_surround && is_surround_on(ac97);
-}
-
+	return !ac97->indep_surround && !is_surround_on(ac97);
+}
+
+/* system has shared jacks with mic in enabled */
 static inline int is_shared_micin(struct snd_ac97 *ac97)
 {
-	return ! ac97->indep_surround && is_clfe_on(ac97);
+	return !ac97->indep_surround && !is_clfe_on(ac97);
 }
 
 
@@ -2014,12 +2028,12 @@ static void alc650_update_jacks(struct s
 {
 	int shared;
 
-	/* shared Line-In */
-	shared = is_shared_linein(ac97);
+	/* shared Line-In / Surround Out */
+	shared = is_shared_surrout(ac97);
 	snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 9,
 			     shared ? (1 << 9) : 0);
-	/* update shared Mic */
-	shared = is_shared_micin(ac97);
+	/* update shared Mic In / Center/LFE Out */
+	shared = is_shared_clfeout(ac97);
 	/* disable/enable vref */
 	snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
 			     shared ? (1 << 12) : 0);
@@ -2149,12 +2163,12 @@ static void alc655_update_jacks(struct s
 {
 	int shared;
 
-	/* shared Line-In */
-	shared = is_shared_linein(ac97);
+	/* shared Line-In / Surround Out */
+	shared = is_shared_surrout(ac97);
 	ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 9,
 			      shared ? (1 << 9) : 0, 0);
-	/* update shared mic */
-	shared = is_shared_micin(ac97);
+	/* update shared Mic In / Center/LFE Out */
+	shared = is_shared_clfeout(ac97);
 	/* misc control; vrefout disable */
 	snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
 			     shared ? (1 << 12) : 0);
@@ -2298,16 +2312,16 @@ static void alc850_update_jacks(struct s
 {
 	int shared;
 
-	/* shared Line-In */
-	shared = is_shared_linein(ac97);
+	/* shared Line-In / Surround Out */
+	shared = is_shared_surrout(ac97);
 	/* SURR 1kOhm (bit4), Amp (bit5) */
 	snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<4)|(1<<5),
 			     shared ? (1<<5) : (1<<4));
 	/* LINE-IN = 0, SURROUND = 2 */
 	snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 12,
 			     shared ? (2<<12) : (0<<12));
-	/* update shared mic */
-	shared = is_shared_micin(ac97);
+	/* update shared Mic In / Center/LFE Out */
+	shared = is_shared_clfeout(ac97);
 	/* Vref disable (bit12), 1kOhm (bit13) */
 	snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<12)|(1<<13),
 			     shared ? (1<<12) : (1<<13));
@@ -2380,9 +2394,9 @@ int patch_alc850(struct snd_ac97 *ac97)
  */
 static void cm9738_update_jacks(struct snd_ac97 *ac97)
 {
-	/* shared Line-In */
+	/* shared Line-In / Surround Out */
 	snd_ac97_update_bits(ac97, AC97_CM9738_VENDOR_CTRL, 1 << 10,
-			     is_shared_linein(ac97) ? (1 << 10) : 0);
+			     is_shared_surrout(ac97) ? (1 << 10) : 0);
 }
 
 static const struct snd_kcontrol_new snd_ac97_cm9738_controls[] = {
@@ -2464,12 +2478,12 @@ static const struct snd_kcontrol_new snd
 
 static void cm9739_update_jacks(struct snd_ac97 *ac97)
 {
-	/* shared Line-In */
+	/* shared Line-In / Surround Out */
 	snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 1 << 10,
-			     is_shared_linein(ac97) ? (1 << 10) : 0);
-	/* shared Mic */
+			     is_shared_surrout(ac97) ? (1 << 10) : 0);
+	/* shared Mic In / Center/LFE Out **/
 	snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 0x3000,
-			     is_shared_micin(ac97) ? 0x1000 : 0x2000);
+			     is_shared_clfeout(ac97) ? 0x1000 : 0x2000);
 }
 
 static const struct snd_kcontrol_new snd_ac97_cm9739_controls[] = {
@@ -2581,8 +2595,8 @@ static void cm9761_update_jacks(struct s
 
 	val |= surr_on[ac97->spec.dev_flags][is_surround_on(ac97)];
 	val |= clfe_on[ac97->spec.dev_flags][is_clfe_on(ac97)];
-	val |= surr_shared[ac97->spec.dev_flags][is_shared_linein(ac97)];
-	val |= clfe_shared[ac97->spec.dev_flags][is_shared_micin(ac97)];
+	val |= surr_shared[ac97->spec.dev_flags][is_shared_surrout(ac97)];
+	val |= clfe_shared[ac97->spec.dev_flags][is_shared_clfeout(ac97)];
 
 	snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x3c88, val);
 }
@@ -2829,12 +2843,12 @@ int patch_vt1617a(struct snd_ac97 * ac97
  */
 static void it2646_update_jacks(struct snd_ac97 *ac97)
 {
-	/* shared Line-In */
+	/* shared Line-In / Surround Out */
 	snd_ac97_update_bits(ac97, 0x76, 1 << 9,

pci/ac97/ac97_patch.c int patch_vt1617a(struct snd_ac97 * ac97 · line 2854

Quoted 10 lines
pci/ac97/ac97_patch.c +3 -3
-			     is_shared_linein(ac97) ? (1<<9) : 0);
-	/* shared Mic */
+			     is_shared_surrout(ac97) ? (1<<9) : 0);
+	/* shared Mic / Center/LFE Out */
 	snd_ac97_update_bits(ac97, 0x76, 1 << 10,
-			     is_shared_micin(ac97) ? (1<<10) : 0);
+			     is_shared_clfeout(ac97) ? (1<<10) : 0);
 }
 
 static const struct snd_kcontrol_new snd_ac97_controls_it2646[] = {

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

#8 lore raw
In reply to Takashi Iwai

Takashi,

Some general questions, before I proceed:

Quoted 27 lines · Takashi Iwai

Hi,

thanks for the patch.
For the ease of review, could you split your change to several patches? Please post one patch per mail, then.

Anyway, a quick review through the patch is below.

At Tue, 12 Dec 2006 19:31:33 -0500,

Quoted 16 lines · Randy Cushman

Summary: fix microphone and line_in selection logic

This patch fixes the Microphone and LINE_IN select logic for surround codecs with shared jacks. This issue appears to apply to most, if not all AC'97 surround codecs. The existing code can never utilize the shared jacks for Microphone and LINE_IN due to the reversed jack selection logic. The patched code correctly selects the shared jack for input if the "Channel Mode" selector does not specify that the jack is to be used for output.

Specifically, in "2ch" mode the Center/LFE jack is used for microphone input and the Surround jack is used for LINE_IN, in "4ch" mode the Center/LFE jack is used for microphone input and the Surround jack is used for output, and in "6ch" mode both jacks are used for output.

Quoted 10 lines
Quoted 2 lines

This hunk likely breaks other codec support.

is_shared_linein() returns true if the line-in jack is shared with surround output _and_ being used as the surround output. Maybe the AD codec support is wrongly implemented.

(addressed in another thread)

Quoted 40 lines
Quoted 12 lines

Summary: fix malfunctioning mixer controls for AD1985

This patch replaces the "V_REFOUT Enable" mixer switch control with a listbox control for the AD1985 CODEC.

Previous patch "AD1888 mixer controls for DC mode" added controls that were propogated to multiple codecs. For the AD1985 codec, the bits VREFH and VREFD function differently, preventing the "V_REFOUT Enable" control from setting V_REFOUT to Hi-Z.

Quoted 8 lines

This patch also corrects an issue in which register bits relating to mixer controls "Surround Jack Mode" and "Channel Mode". The register bits controlled by these controls were being set at boot time to states inconsistent with the stored values of these controls.

This change looks fine.

Quoted 15 lines

Summary: fix various issues with AD1986/AD1986A support

Previously, ac97_codec.c was coded to support AD1986 and AD1986A CODECs using code written for the AD1985 CODEC. This allowed the LINE_OUT and HEADPHONE jacks to function properly, however register differences between the CODECs prevented line and microphone inputs from functioning.

Specifically, this patch fixes issues with the following mixer
controls: 'V_REFOUT', 'Spread Front to Surround and Center/LFE', 'Exchange Front/Surround', 'Surround Jack Mode', and 'Channel Mode'. This patch removes the undocumented AD1888 control
'High Pass Filter Enable' and adds the new control 'Exchange Mic/Line In'.

Quoted 6 lines
Quoted 2 lines

This sounds fine, too.

I noticed in reviewing support for other chipsets in ac97_patch.c, I found samples of code that sets V_REFOUT to High-Z when the corresponding jack is not currently configured for microphone input.

Is this something I should be doing? I'm not sure I understand how V_REFOUT is used. Is it physically connected to the microphone jack?

Part of my confusion is that on the AD1986/AD1986A, there is a separate V_REFOUT pin for each jack that allows connection to microphone(s), but on the AD1985 there are 2 possible microphone jacks and 1 V_REFOUT pin.

Quoted 9 lines
Quoted 9 lines

diff -r bc7ef767d0cf include/ac97_codec.h

include/ac97_codec.h +1 -0
@@ -282,9 +282,11 @@
 #define AC97_AD_TEST		0x5a	/* test register */
 #define AC97_AD_TEST2		0x5c	/* undocumented test register 2 */
 #define AC97_AD_CODEC_CFG	0x70	/* codec configuration */
+#define AC97_AD_MISC2		0x70	/* Misc Control Bits 2 (AD1986) */
 #define AC97_AD_JACK_SPDIF	0x72	/* Jack Sense & S/PDIF */
Quoted 10 lines

include/ac97_codec.h line 290

Quoted 4 lines
include/ac97_codec.h +1 -0
 #define AC97_AD_SERIAL_CFG	0x74	/* Serial Configuration */
 #define AC97_AD_MISC		0x76	/* Misc Control Bits */
+#define AC97_AD_MISC3		0x7a	/* Misc Control Bits 3 (AD1986) */
 

These don't have to be defined in the public header. (I'd rather like to move all these codec-speicific definitions to
local file, i.e. ac97_patch.c or local headers.)

I realize that the above macros don't need to be defined in ac97_codec.h, however I figured the best place for my new macros was alongside related macros, which unfortunately are located here. My minimal change philosophy overrode any temptation to move the existing 6 AC97_AD_* macros to another location. If I moved those 6 macros, then I'd also want to move the similar macros defined for other chipsets. Additionally, there is the quandary that although it may be possible to move some of the other macros to ac97_patch.c, (at least some of) the AD macros would need to go into ac97_patch.h, since ac97_codec.c (inappropriately?) contains some AD-specific code that references these macros.

Here are the choices I see:
1) Add the new macros to ac97_codec.h
2) Leave ac97_codec.h untouched and add the new macros to ac97_patch.c
3) Move the above macros (ac97_codec.h lines 281-287) and add the new macros to ac97_patch.h
4) Move all related macros (ac97_codec.h lines 268-363) and add the new macros to ac97_patch.h
etc.

Thoughts?

Quoted 12 lines

include/ac97_codec.h struct snd_ac97 { · line 509

Quoted 8 lines
include/ac97_codec.h +1 -0
 /* specific - Cirrus Logic */
 #define AC97_CSR_ACMODE		0x5e	/* AC Mode Register */
@@ -503,6 +505,7 @@ struct snd_ac97 {
 			unsigned short id[3];		// codec IDs (lower 16-bit word)
 			unsigned short pcmreg[3];	// PCM registers
 			unsigned short codec_cfg[3];	// CODEC_CFG bits
+			unsigned short swap_mic_linein;
 

Any need to be unsigned short?

I used unsigned short because it made the union an even 32 bytes. There is no reason it cannot be an unsigned char.

(I'm tempted to add an extra byte of filler. Thoughts?)

Quoted 21 lines
Quoted 7 lines

diff -r bc7ef767d0cf pci/ac97/ac97_patch.c

pci/ac97/ac97_patch.c +0 -0
@@ -192,12 +192,12 @@ static inline int is_clfe_on(struct snd_
 
 static inline int is_shared_linein(struct snd_ac97 *ac97)
 {

pci/ac97/ac97_patch.c static inline int is_clfe_on(struct snd_ · line 202

Quoted 10 lines
pci/ac97/ac97_patch.c +2 -2
-	return ! ac97->indep_surround && is_surround_on(ac97);
+	return ! ac97->indep_surround && ! is_surround_on(ac97);
 }
 
 static inline int is_shared_micin(struct snd_ac97 *ac97)
 {
-	return ! ac97->indep_surround && is_clfe_on(ac97);
+	return ! ac97->indep_surround && ! is_clfe_on(ac97);
 }
 

Dangerous changes as I mentioned.

Quoted 6 lines

pci/ac97/ac97_patch.c int patch_ad1980(struct snd_ac97 * ac97) · line 2019

Quoted 2 lines
pci/ac97/ac97_patch.c +1 -0
+static int snd_ac97_ad1985_vrefout_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)

Please fold lines to keep the (new) code within 80 columns.

no problem

Quoted 5 lines
Quoted 5 lines
pci/ac97/ac97_patch.c +0 -0
 static void ad1985_update_jacks(struct snd_ac97 *ac97)
@@ -1967,8 +2098,13 @@ static int patch_ad1985_specific(struct 
 {
 	int err;
 
Quoted 10 lines

pci/ac97/ac97_patch.c static int patch_ad1985_specific(struct · line 2110

Quoted 5 lines
pci/ac97/ac97_patch.c +3 -1
-	if ((err = patch_ad1980_specific(ac97)) < 0)
+	/* rename 0x04 as "Master" and 0x02 as "Master Surround" */
+	snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Master Surround Playback");
+	snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback");
 

This rename would break many other boards since the renaming of master/headphone is usually done via ac97_quirk.

Actually this maintains existing functionality, as patch_ad1985_specific currently calls patch_ad1980_specific, which calls patch_ad1888_specific, which renames the controls. If you'd like I can change the functionality.

Quoted 10 lines

pci/ac97/ac97_patch.c int patch_ad1985(struct snd_ac97 * ac97) · line 2396

Quoted 7 lines
pci/ac97/ac97_patch.c +6 -0
+static int patch_ad1986_specific(struct snd_ac97 *ac97)
+{
+	int err;
+
+	/* rename 0x02 as "Master Surround" */
+	snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Master Surround Playback");

Ditto.

Ditto for me too, although here I left out the "Headphone" rename because chipset differences suggest to me that there would be no use in wiring the headphone pins as Line Out on the AD1986/AD1986A, unlike the other chipsets.

Quoted 6 lines

thanks,

Takashi

I appreciate the input.

Randy Cushman

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

#10 lore raw
In reply to Takashi Iwai

Takashi,

Attached please find the second installment of separated patches you requested.

I decided to submit this patch before receiving your response to my questions because only one of the questions pertained to this patch (the question regarding the renaming of volume controls), and I have come to the conclusion that this patch should maintain existing functionality regarding the volume controls.

My reasoning for this is that the mixer controls for the Analog Devices surround CODECs appear to have multiple problems that justify a separate project, time permitting. I'd rather focus this patch on the work I've done so far, and save these other enhancements for another time.

Randy Cushman

Summary: fix microphone and line_in selection logic

This patch fixes the Microphone and LINE_IN select logic for surround codecs with shared jacks. This issue appears to apply to most, if not all AC'97 surround codecs. The existing code can never utilize the shared jacks for Microphone and LINE_IN due to the reversed jack selection logic. The patched code correctly selects the shared jack for input if the "Channel Mode" selector does not specify that the jack is to be used for output.

Specifically, in "2ch" mode the Center/LFE jack is used for microphone input and the Surround jack is used for LINE_IN, in "4ch" mode the Center/LFE jack is used for microphone input and the Surround jack is used for output, and in "6ch" mode both jacks are used for output.

Summary: replace malfunctioning mixer control for AD1985

This patch replacing the "V_REFOUT Enable" mixer switch control with a listbox control for the AD1985 CODEC.

Previous patch "AD1888 mixer controls for DC mode" added controls that were propogated to multiple codecs. For the AD1985 codec, the bits VREFH and VREFD function differently, preventing the "V_REFOUT Enable" control from setting V_REFOUT to Hi-Z.

b/alsa-kernel/pci/ac97/ac97_patch.c renamed from a/alsa-kernel/pci/ac97/ac97_patch.c +81 -8
@@ -192,12 +192,12 @@
 
 static inline int is_shared_linein(struct snd_ac97 *ac97)
 {
-	return ! ac97->indep_surround && is_surround_on(ac97);
+	return ! ac97->indep_surround && ! is_surround_on(ac97);
 }
 
 static inline int is_shared_micin(struct snd_ac97 *ac97)
 {
-	return ! ac97->indep_surround && is_clfe_on(ac97);
+	return ! ac97->indep_surround && ! is_clfe_on(ac97);
 }
 
 
@@ -1615,8 +1615,10 @@
 #define AC97_AD198X_MBC_10	0x0001	/* +10dB */
 #define AC97_AD198X_MBC_30	0x0002	/* +30dB */
 #define AC97_AD198X_VREFD	0x0004	/* VREF high-Z */
-#define AC97_AD198X_VREFH	0x0008	/* 2.25V, 3.7V */
-#define AC97_AD198X_VREF_0	0x000c	/* 0V */
+#define AC97_AD198X_VREFH	0x0008	/* 0=2.25V, 1=3.7V */
+#define AC97_AD198X_VREF_0	0x000c	/* 0V (AD1985 only) */
+#define AC97_AD198X_VREF_MASK	(AC97_AD198X_VREFH | AC97_AD198X_VREFD)
+#define AC97_AD198X_VREF_OFFSET 2
 #define AC97_AD198X_SRU		0x0010	/* sample rate unlock */
 #define AC97_AD198X_LOSEL	0x0020	/* LINE_OUT amplifiers input select */
 #define AC97_AD198X_2MIC	0x0040	/* 2-channel mic select */
@@ -1952,8 +1954,75 @@
 	return 0;
 }
 
+static int snd_ac97_ad1985_vrefout_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
+{
+	static char *texts[4] = {"High-Z", "3.7 V", "2.25 V", "0 V"};
+
+	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
+	uinfo->count = 1;
+	uinfo->value.enumerated.items = 4;
+	if (uinfo->value.enumerated.item > 3)
+		uinfo->value.enumerated.item = 3;
+	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
+	return 0;
+}
+
+static int snd_ac97_ad1985_vrefout_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
+{
+	static const int reg2ctrl[4] = {2, 0, 1, 3};
+	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
+	unsigned short val;
+	val = (ac97->regs[AC97_AD_MISC] & AC97_AD198X_VREF_MASK)
+	      >> AC97_AD198X_VREF_OFFSET;
+	ucontrol->value.enumerated.item[0] = reg2ctrl[val];
+	return 0;
+}
+
+static int snd_ac97_ad1985_vrefout_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
+{
+	static const int ctrl2reg[4] = {1, 2, 0, 3};
+	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
+	unsigned short val;
+
+	if (ucontrol->value.enumerated.item[0] > 3
+	    || ucontrol->value.enumerated.item[0] < 0)
+		return -EINVAL;
+	val = ctrl2reg[ucontrol->value.enumerated.item[0]]
+	      << AC97_AD198X_VREF_OFFSET;
+	return snd_ac97_update_bits(ac97, AC97_AD_MISC,
+				    AC97_AD198X_VREF_MASK, val);
+}
+
 static const struct snd_kcontrol_new snd_ac97_ad1985_controls[] = {
-	AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0)
+	AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0),
+	{
+		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+		.name = "Exchange Front/Surround",
+		.info = snd_ac97_ad1888_lohpsel_info,
+		.get = snd_ac97_ad1888_lohpsel_get,
+		.put = snd_ac97_ad1888_lohpsel_put
+	},
+	AC97_SINGLE("High Pass Filter Enable", AC97_AD_TEST2, 12, 1, 1),
+	AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC, 7, 1, 0),
+	{
+		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+		.name = "Downmix",
+		.info = snd_ac97_ad1888_downmix_info,
+		.get = snd_ac97_ad1888_downmix_get,
+		.put = snd_ac97_ad1888_downmix_put
+	},
+	{
+		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+		.name = "V_REFOUT",
+		.info = snd_ac97_ad1985_vrefout_info,
+		.get = snd_ac97_ad1985_vrefout_get,
+		.put = snd_ac97_ad1985_vrefout_put
+	},
+	AC97_SURROUND_JACK_MODE_CTL,
+	AC97_CHANNEL_MODE_CTL,
+
+	AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0),
+	AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
 };
 
 static void ad1985_update_jacks(struct snd_ac97 *ac97)
@@ -1967,8 +2036,13 @@
 {
 	int err;
 
-	if ((err = patch_ad1980_specific(ac97)) < 0)
+	/* rename 0x04 as "Master" and 0x02 as "Master Surround" */
+	snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Master Surround Playback");
+	snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback");
+
+	if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0)
 		return err;
+
 	return patch_build_controls(ac97, snd_ac97_ad1985_controls, ARRAY_SIZE(snd_ac97_ad1985_controls));
 }
 
@@ -1989,12 +2063,11 @@
 	ac97->build_ops = &patch_ad1985_build_ops;
 	misc = snd_ac97_read(ac97, AC97_AD_MISC);
 	/* switch front/surround line-out/hp-out */
-	/* center/LFE, mic in 3.75V mode */
+	/* center/LFE */
 	/* AD-compatible mode */
 	/* Stereo mutes enabled */
 	/* in accordance with ADI driver: misc | 0x5c28 */
 	snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
-			     AC97_AD198X_VREFH |
 			     AC97_AD198X_LOSEL |
 			     AC97_AD198X_HPSEL |
 			     AC97_AD198X_CLDIS |

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel

#9 lore raw
In reply to Randy Cushman

At Tue, 19 Dec 2006 13:40:32 -0500,

Quoted 26 lines · Randy Cushman
Quoted 16 lines
Quoted 16 lines

Summary: fix various issues with AD1986/AD1986A support

Previously, ac97_codec.c was coded to support AD1986 and AD1986A CODECs using code written for the AD1985 CODEC. This allowed the LINE_OUT and HEADPHONE jacks to function properly, however register differences between the CODECs prevented line and microphone inputs from functioning.

Specifically, this patch fixes issues with the following mixer
controls: 'V_REFOUT', 'Spread Front to Surround and Center/LFE', 'Exchange Front/Surround', 'Surround Jack Mode', and 'Channel Mode'. This patch removes the undocumented AD1888 control
'High Pass Filter Enable' and adds the new control 'Exchange Mic/Line In'.

Quoted 6 lines
Quoted 2 lines

This sounds fine, too.

I noticed in reviewing support for other chipsets in ac97_patch.c, I found samples of code that sets V_REFOUT to High-Z when the corresponding jack is not currently configured for microphone input.

Quoted 6 lines

Is this something I should be doing? I'm not sure I understand how V_REFOUT is used. Is it physically connected to the microphone jack?

Part of my confusion is that on the AD1986/AD1986A, there is a separate V_REFOUT pin for each jack that allows connection to microphone(s), but on the AD1985 there are 2 possible microphone jacks and 1 V_REFOUT pin.

AFAIK, such VREF changes are needed to reduce the possible noises on the surround output jacks. It's highly depending on the board implementation. So, if the driver works fine without vref change, it should be OK :)

Quoted 40 lines
Quoted 9 lines
Quoted 9 lines

diff -r bc7ef767d0cf include/ac97_codec.h

include/ac97_codec.h +1 -0
@@ -282,9 +282,11 @@
 #define AC97_AD_TEST		0x5a	/* test register */
 #define AC97_AD_TEST2		0x5c	/* undocumented test register 2 */
 #define AC97_AD_CODEC_CFG	0x70	/* codec configuration */
+#define AC97_AD_MISC2		0x70	/* Misc Control Bits 2 (AD1986) */
 #define AC97_AD_JACK_SPDIF	0x72	/* Jack Sense & S/PDIF */
Quoted 10 lines

include/ac97_codec.h line 290

Quoted 4 lines
include/ac97_codec.h +1 -0
 #define AC97_AD_SERIAL_CFG	0x74	/* Serial Configuration */
 #define AC97_AD_MISC		0x76	/* Misc Control Bits */
+#define AC97_AD_MISC3		0x7a	/* Misc Control Bits 3 (AD1986) */
 

These don't have to be defined in the public header. (I'd rather like to move all these codec-speicific definitions to
local file, i.e. ac97_patch.c or local headers.)

I realize that the above macros don't need to be defined in ac97_codec.h, however I figured the best place for my new macros was alongside related macros, which unfortunately are located here. My minimal change philosophy overrode any temptation to move the existing 6 AC97_AD_* macros to another location. If I moved those 6 macros, then I'd also want to move the similar macros defined for other chipsets. Additionally, there is the quandary that although it may be possible to move some of the other macros to ac97_patch.c, (at least some of) the AD macros would need to go into ac97_patch.h, since ac97_codec.c (inappropriately?) contains some AD-specific code that references these macros.

Here are the choices I see:
1) Add the new macros to ac97_codec.h
2) Leave ac97_codec.h untouched and add the new macros to ac97_patch.c
3) Move the above macros (ac97_codec.h lines 281-287) and add the new macros to ac97_patch.h
4) Move all related macros (ac97_codec.h lines 268-363) and add the new macros to ac97_patch.h
etc.

Quoted 1 line

Thoughts?

I'd like 2. Let's make a working version first, then clean up these things, e.g. by moving codec-specific defines to ac97_local.h. There are also defines in ac97_patch.c, and could be better placed in ac97_local.h.

Quoted 12 lines
Quoted 12 lines

include/ac97_codec.h struct snd_ac97 { · line 509

Quoted 8 lines
include/ac97_codec.h +1 -0
 /* specific - Cirrus Logic */
 #define AC97_CSR_ACMODE		0x5e	/* AC Mode Register */
@@ -503,6 +505,7 @@ struct snd_ac97 {
 			unsigned short id[3];		// codec IDs (lower 16-bit word)
 			unsigned short pcmreg[3];	// PCM registers
 			unsigned short codec_cfg[3];	// CODEC_CFG bits
+			unsigned short swap_mic_linein;
 

Any need to be unsigned short?

Quoted 4 lines

I used unsigned short because it made the union an even 32 bytes. There is no reason it cannot be an unsigned char.

(I'm tempted to add an extra byte of filler. Thoughts?)

Compilers would care such a thing, so you don't have to worry much, I guess. I don't mind so much what type is there, though.

Quoted 15 lines
Quoted 5 lines
Quoted 5 lines
include/ac97_codec.h +0 -0
 static void ad1985_update_jacks(struct snd_ac97 *ac97)
@@ -1967,8 +2098,13 @@ static int patch_ad1985_specific(struct 
 {
 	int err;
 
Quoted 10 lines

include/ac97_codec.h static int patch_ad1985_specific(struct · line 2104

Quoted 5 lines
include/ac97_codec.h +3 -1
-	if ((err = patch_ad1980_specific(ac97)) < 0)
+	/* rename 0x04 as "Master" and 0x02 as "Master Surround" */
+	snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Master Surround Playback");
+	snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback");
 

This rename would break many other boards since the renaming of master/headphone is usually done via ac97_quirk.

Quoted 4 lines

Actually this maintains existing functionality, as patch_ad1985_specific currently calls patch_ad1980_specific, which calls patch_ad1888_specific, which renames the controls. If you'd like I can change the functionality.

Ah OK, then I overlooked that part.

thanks,

Takashi

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

#11 lore raw
In reply to Randy Cushman

Takashi,

Sorry about that. I managed to attach the wrong patch file for my second installment.

This should be the correct patch.

Randy Cushman

Quoted 10 lines · Randy Cushman

Takashi,

Attached please find the second installment of separated patches you requested.

I decided to submit this patch before receiving your response to my questions because only one of the questions pertained to this patch (the question regarding the renaming of volume controls), and I have come to the conclusion that this patch should maintain existing functionality regarding the volume controls.

My reasoning for this is that the mixer controls for the Analog Devices surround CODECs appear to have multiple problems that justify a separate project, time permitting. I'd rather focus this patch on the work I've done so far, and save these other enhancements for another time.

Randy Cushman

Summary: fix malfunctioning mixer controls for AD1985

This patch replaces the "V_REFOUT Enable" mixer switch control with a listbox control for the AD1985 CODEC.

Previous patch "AD1888 mixer controls for DC mode" added controls that were propogated to multiple codecs. For the AD1985 codec, the bits VREFH and VREFD function differently, preventing the "V_REFOUT Enable" control from setting V_REFOUT to Hi-Z.

This patch also corrects an issue in which register bits relating to mixer controls "Surround Jack Mode" and "Channel Mode". The register bits controlled by these controls were being set at boot time to states inconsistent with the stored values of these controls.

alsa-kernel/pci/ac97/ac97_patch.c +92 -11
@@ -1629,13 +1629,16 @@
 #define AC97_AD198X_MBC_10	0x0001	/* +10dB */
 #define AC97_AD198X_MBC_30	0x0002	/* +30dB */
 #define AC97_AD198X_VREFD	0x0004	/* VREF high-Z */
-#define AC97_AD198X_VREFH	0x0008	/* 2.25V, 3.7V */
-#define AC97_AD198X_VREF_0	0x000c	/* 0V */
+#define AC97_AD198X_VREFH	0x0008	/* 0=2.25V, 1=3.7V */
+#define AC97_AD198X_VREF_0	0x000c	/* 0V (AD1985 only) */
+#define AC97_AD198X_VREF_MASK	(AC97_AD198X_VREFH | AC97_AD198X_VREFD)
+#define AC97_AD198X_VREF_SHIFT	2
 #define AC97_AD198X_SRU		0x0010	/* sample rate unlock */
 #define AC97_AD198X_LOSEL	0x0020	/* LINE_OUT amplifiers input select */
 #define AC97_AD198X_2MIC	0x0040	/* 2-channel mic select */
 #define AC97_AD198X_SPRD	0x0080	/* SPREAD enable */
-#define AC97_AD198X_DMIX0	0x0100	/* downmix mode: 0 = 6-to-4, 1 = 6-to-2 downmix */
+#define AC97_AD198X_DMIX0	0x0100	/* downmix mode: */
+					/*  0 = 6-to-4, 1 = 6-to-2 downmix */
 #define AC97_AD198X_DMIX1	0x0200	/* downmix mode: 1 = enabled */
 #define AC97_AD198X_HPSEL	0x0400	/* headphone amplifier input select */
 #define AC97_AD198X_CLDIS	0x0800	/* center/lfe disable */
@@ -1966,8 +1969,80 @@
 	return 0;
 }
 
+static int snd_ac97_ad1985_vrefout_info(struct snd_kcontrol *kcontrol,
+					struct snd_ctl_elem_info *uinfo)
+{
+	static char *texts[4] = {"High-Z", "3.7 V", "2.25 V", "0 V"};
+
+	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
+	uinfo->count = 1;
+	uinfo->value.enumerated.items = 4;
+	if (uinfo->value.enumerated.item > 3)
+		uinfo->value.enumerated.item = 3;
+	strcpy(uinfo->value.enumerated.name,
+	       texts[uinfo->value.enumerated.item]);
+	return 0;
+}
+
+static int snd_ac97_ad1985_vrefout_get(struct snd_kcontrol *kcontrol,
+				       struct snd_ctl_elem_value *ucontrol)
+{
+	static const int reg2ctrl[4] = {2, 0, 1, 3};
+	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
+	unsigned short val;
+	val = (ac97->regs[AC97_AD_MISC] & AC97_AD198X_VREF_MASK)
+	      >> AC97_AD198X_VREF_SHIFT;
+	ucontrol->value.enumerated.item[0] = reg2ctrl[val];
+	return 0;
+}
+
+static int snd_ac97_ad1985_vrefout_put(struct snd_kcontrol *kcontrol, 
+				       struct snd_ctl_elem_value *ucontrol)
+{
+	static const int ctrl2reg[4] = {1, 2, 0, 3};
+	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
+	unsigned short val;
+
+	if (ucontrol->value.enumerated.item[0] > 3
+	    || ucontrol->value.enumerated.item[0] < 0)
+		return -EINVAL;
+	val = ctrl2reg[ucontrol->value.enumerated.item[0]]
+	      << AC97_AD198X_VREF_SHIFT;
+	return snd_ac97_update_bits(ac97, AC97_AD_MISC,
+				    AC97_AD198X_VREF_MASK, val);
+}
+
 static const struct snd_kcontrol_new snd_ac97_ad1985_controls[] = {
-	AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0)
+	AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0),
+	{
+		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+		.name = "Exchange Front/Surround",
+		.info = snd_ac97_ad1888_lohpsel_info,
+		.get = snd_ac97_ad1888_lohpsel_get,
+		.put = snd_ac97_ad1888_lohpsel_put
+	},
+	AC97_SINGLE("High Pass Filter Enable", AC97_AD_TEST2, 12, 1, 1),
+	AC97_SINGLE("Spread Front to Surround and Center/LFE",
+		    AC97_AD_MISC, 7, 1, 0),
+	{
+		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+		.name = "Downmix",
+		.info = snd_ac97_ad1888_downmix_info,
+		.get = snd_ac97_ad1888_downmix_get,
+		.put = snd_ac97_ad1888_downmix_put
+	},
+	{
+		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+		.name = "V_REFOUT",
+		.info = snd_ac97_ad1985_vrefout_info,
+		.get = snd_ac97_ad1985_vrefout_get,
+		.put = snd_ac97_ad1985_vrefout_put
+	},
+	AC97_SURROUND_JACK_MODE_CTL,
+	AC97_CHANNEL_MODE_CTL,
+
+	AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0),
+	AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
 };
 
 static void ad1985_update_jacks(struct snd_ac97 *ac97)
@@ -1981,9 +2056,16 @@
 {
 	int err;
 
-	if ((err = patch_ad1980_specific(ac97)) < 0)
+	/* rename 0x04 as "Master" and 0x02 as "Master Surround" */
+	snd_ac97_rename_vol_ctl(ac97, "Master Playback",
+				"Master Surround Playback");
+	snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback");
+
+	if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0)
 		return err;
-	return patch_build_controls(ac97, snd_ac97_ad1985_controls, ARRAY_SIZE(snd_ac97_ad1985_controls));
+
+	return patch_build_controls(ac97, snd_ac97_ad1985_controls,
+				    ARRAY_SIZE(snd_ac97_ad1985_controls));
 }
 
 static struct snd_ac97_build_ops patch_ad1985_build_ops = {
@@ -2003,19 +2085,18 @@
 	ac97->build_ops = &patch_ad1985_build_ops;
 	misc = snd_ac97_read(ac97, AC97_AD_MISC);
 	/* switch front/surround line-out/hp-out */
-	/* center/LFE, mic in 3.75V mode */
 	/* AD-compatible mode */
 	/* Stereo mutes enabled */
-	/* in accordance with ADI driver: misc | 0x5c28 */
 	snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
-			     AC97_AD198X_VREFH |
 			     AC97_AD198X_LOSEL |
 			     AC97_AD198X_HPSEL |
-			     AC97_AD198X_CLDIS |
-			     AC97_AD198X_LODIS |
 			     AC97_AD198X_MSPLT |
 			     AC97_AD198X_AC97NC);
 	ac97->flags |= AC97_STEREO_MUTES;
+
+	/* update current jack configuration */
+	ad1985_update_jacks(ac97);
+
 	/* on AD1985 rev. 3, AC'97 revision bits are zero */
 	ac97->ext_id = (ac97->ext_id & ~AC97_EI_REV_MASK) | AC97_EI_REV_23;
 	return 0;

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel

#12 lore raw

At Thu, 21 Dec 2006 11:17:28 -0500,

Quoted 7 lines · Randy Cushman

Takashi,

Sorry about that. I managed to attach the wrong patch file for my second installment.

This should be the correct patch.

Thanks, the patch looks OK.
Applied it to ALSA HG tree now.

Takashi

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV