⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ac97_patch.c

📁 linux2.6.16版本
💻 C
📖 第 1 页 / 共 5 页
字号:
int patch_ad1886(struct snd_ac97 * ac97){	patch_ad1881(ac97);	/* Presario700 workaround */	/* for Jack Sense/SPDIF Register misetting causing */	snd_ac97_write_cache(ac97, AC97_AD_JACK_SPDIF, 0x0010);	return 0;}/* MISC bits */#define AC97_AD198X_MBC		0x0003	/* mic boost */#define AC97_AD198X_MBC_20	0x0000	/* +20dB */#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_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_DMIX1	0x0200	/* downmix mode: 1 = enabled */#define AC97_AD198X_HPSEL	0x0400	/* headphone amplifier input select */#define AC97_AD198X_CLDIS	0x0800	/* center/lfe disable */#define AC97_AD198X_LODIS	0x1000	/* LINE_OUT disable */#define AC97_AD198X_MSPLT	0x2000	/* mute split */#define AC97_AD198X_AC97NC	0x4000	/* AC97 no compatible mode */#define AC97_AD198X_DACZ	0x8000	/* DAC zero-fill mode */static int snd_ac97_ad198x_spdif_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo){	static char *texts[2] = { "AC-Link", "A/D Converter" };	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;	uinfo->count = 1;	uinfo->value.enumerated.items = 2;	if (uinfo->value.enumerated.item > 1)		uinfo->value.enumerated.item = 1;	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);	return 0;}static int snd_ac97_ad198x_spdif_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);	unsigned short val;	val = ac97->regs[AC97_AD_SERIAL_CFG];	ucontrol->value.enumerated.item[0] = (val >> 2) & 1;	return 0;}static int snd_ac97_ad198x_spdif_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);	unsigned short val;	if (ucontrol->value.enumerated.item[0] > 1)		return -EINVAL;	val = ucontrol->value.enumerated.item[0] << 2;	return snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x0004, val);}static const struct snd_kcontrol_new snd_ac97_ad198x_spdif_source = {	.iface	= SNDRV_CTL_ELEM_IFACE_MIXER,	.name	= SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",	.info	= snd_ac97_ad198x_spdif_source_info,	.get	= snd_ac97_ad198x_spdif_source_get,	.put	= snd_ac97_ad198x_spdif_source_put,};static int patch_ad198x_post_spdif(struct snd_ac97 * ac97){ 	return patch_build_controls(ac97, &snd_ac97_ad198x_spdif_source, 1);}static const struct snd_kcontrol_new snd_ac97_ad1981x_jack_sense[] = {	AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 11, 1, 0),	AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),};/* black list to avoid HP/Line jack-sense controls * (SS vendor << 16 | device) */static unsigned int ad1981_jacks_blacklist[] = {	0x10140554, /* Thinkpad T42p/R50p */	0 /* end */};static int check_list(struct snd_ac97 *ac97, const unsigned int *list){	u32 subid = ((u32)ac97->subsystem_vendor << 16) | ac97->subsystem_device;	for (; *list; list++)		if (*list == subid)			return 1;	return 0;}static int patch_ad1981a_specific(struct snd_ac97 * ac97){	if (check_list(ac97, ad1981_jacks_blacklist))		return 0;	return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,				    ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));}static struct snd_ac97_build_ops patch_ad1981a_build_ops = {	.build_post_spdif = patch_ad198x_post_spdif,	.build_specific = patch_ad1981a_specific,#ifdef CONFIG_PM	.resume = ad18xx_resume#endif};/* white list to enable HP jack-sense bits * (SS vendor << 16 | device) */static unsigned int ad1981_jacks_whitelist[] = {	0x0e11005a, /* HP nc4000/4010 */	0x103c0890, /* HP nc6000 */	0x103c0938, /* HP nc4220 */	0x103c099c, /* HP nx6110 */	0x103c0944, /* HP nc6220 */	0x103c0934, /* HP nc8220 */	0x103c006d, /* HP nx9105 */	0x17340088, /* FSC Scenic-W */	0 /* end */};static void check_ad1981_hp_jack_sense(struct snd_ac97 *ac97){	if (check_list(ac97, ad1981_jacks_whitelist))		/* enable headphone jack sense */		snd_ac97_update_bits(ac97, AC97_AD_JACK_SPDIF, 1<<11, 1<<11);}int patch_ad1981a(struct snd_ac97 *ac97){	patch_ad1881(ac97);	ac97->build_ops = &patch_ad1981a_build_ops;	snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);	ac97->flags |= AC97_STEREO_MUTES;	check_ad1981_hp_jack_sense(ac97);	return 0;}static const struct snd_kcontrol_new snd_ac97_ad198x_2cmic =AC97_SINGLE("Stereo Mic", AC97_AD_MISC, 6, 1, 0);static int patch_ad1981b_specific(struct snd_ac97 *ac97){	int err;	if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0)		return err;	if (check_list(ac97, ad1981_jacks_blacklist))		return 0;	return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,				    ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));}static struct snd_ac97_build_ops patch_ad1981b_build_ops = {	.build_post_spdif = patch_ad198x_post_spdif,	.build_specific = patch_ad1981b_specific,#ifdef CONFIG_PM	.resume = ad18xx_resume#endif};int patch_ad1981b(struct snd_ac97 *ac97){	patch_ad1881(ac97);	ac97->build_ops = &patch_ad1981b_build_ops;	snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);	ac97->flags |= AC97_STEREO_MUTES;	check_ad1981_hp_jack_sense(ac97);	return 0;}static int snd_ac97_ad1888_lohpsel_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo){	uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;	uinfo->count = 1;	uinfo->value.integer.min = 0;	uinfo->value.integer.max = 1;	return 0;}static int snd_ac97_ad1888_lohpsel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);	unsigned short val;	val = ac97->regs[AC97_AD_MISC];	ucontrol->value.integer.value[0] = !(val & AC97_AD198X_LOSEL);	return 0;}static int snd_ac97_ad1888_lohpsel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);	unsigned short val;	val = !ucontrol->value.integer.value[0]		? (AC97_AD198X_LOSEL | AC97_AD198X_HPSEL) : 0;	return snd_ac97_update_bits(ac97, AC97_AD_MISC,				    AC97_AD198X_LOSEL | AC97_AD198X_HPSEL, val);}static int snd_ac97_ad1888_downmix_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo){	static char *texts[3] = {"Off", "6 -> 4", "6 -> 2"};	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;	uinfo->count = 1;	uinfo->value.enumerated.items = 3;	if (uinfo->value.enumerated.item > 2)		uinfo->value.enumerated.item = 2;	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);	return 0;}static int snd_ac97_ad1888_downmix_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);	unsigned short val;	val = ac97->regs[AC97_AD_MISC];	if (!(val & AC97_AD198X_DMIX1))		ucontrol->value.enumerated.item[0] = 0;	else		ucontrol->value.enumerated.item[0] = 1 + ((val >> 8) & 1);	return 0;}static int snd_ac97_ad1888_downmix_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){	struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);	unsigned short val;	if (ucontrol->value.enumerated.item[0] > 2)		return -EINVAL;	if (ucontrol->value.enumerated.item[0] == 0)		val = 0;	else		val = AC97_AD198X_DMIX1 |			((ucontrol->value.enumerated.item[0] - 1) << 8);	return snd_ac97_update_bits(ac97, AC97_AD_MISC,				    AC97_AD198X_DMIX0 | AC97_AD198X_DMIX1, val);}static void ad1888_update_jacks(struct snd_ac97 *ac97){	unsigned short val = 0;	if (! is_shared_linein(ac97))		val |= (1 << 12);	if (! is_shared_micin(ac97))		val |= (1 << 11);	/* shared Line-In */	snd_ac97_update_bits(ac97, AC97_AD_MISC, (1 << 11) | (1 << 12), val);}static const struct snd_kcontrol_new snd_ac97_ad1888_controls[] = {	{		.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 int patch_ad1888_specific(struct snd_ac97 *ac97){	/* 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");	return patch_build_controls(ac97, snd_ac97_ad1888_controls, ARRAY_SIZE(snd_ac97_ad1888_controls));}static struct snd_ac97_build_ops patch_ad1888_build_ops = {	.build_post_spdif = patch_ad198x_post_spdif,	.build_specific = patch_ad1888_specific,#ifdef CONFIG_PM	.resume = ad18xx_resume,#endif	.update_jacks = ad1888_update_jacks,};int patch_ad1888(struct snd_ac97 * ac97){	unsigned short misc;		patch_ad1881(ac97);	ac97->build_ops = &patch_ad1888_build_ops;	/* Switch FRONT/SURROUND LINE-OUT/HP-OUT default connection */	/* it seems that most vendors connect line-out connector to headphone out of AC'97 */	/* AD-compatible mode */	/* Stereo mutes enabled */	misc = snd_ac97_read(ac97, AC97_AD_MISC);	snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |			     AC97_AD198X_LOSEL |			     AC97_AD198X_HPSEL |			     AC97_AD198X_MSPLT |			     AC97_AD198X_AC97NC);	ac97->flags |= AC97_STEREO_MUTES;	return 0;}static int patch_ad1980_specific(struct snd_ac97 *ac97){	int err;	if ((err = patch_ad1888_specific(ac97)) < 0)		return err;	return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1);}static struct snd_ac97_build_ops patch_ad1980_build_ops = {	.build_post_spdif = patch_ad198x_post_spdif,	.build_specific = patch_ad1980_specific,#ifdef CONFIG_PM	.resume = ad18xx_resume,#endif	.update_jacks = ad1888_update_jacks,};int patch_ad1980(struct snd_ac97 * ac97){	patch_ad1888(ac97);	ac97->build_ops = &patch_ad1980_build_ops;	return 0;}static const struct snd_kcontrol_new snd_ac97_ad1985_controls[] = {	AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0)};static void ad1985_update_jacks(struct snd_ac97 *ac97){	ad1888_update_jacks(ac97);	snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 1 << 9,			     is_shared_micin(ac97) ? 0 : 1 << 9);}static int patch_ad1985_specific(struct snd_ac97 *ac97){	int err;	if ((err = patch_ad1980_specific(ac97)) < 0)		return err;	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 = {	.build_post_spdif = patch_ad198x_post_spdif,	.build_specific = patch_ad1985_specific,#ifdef CONFIG_PM	.resume = ad18xx_resume,#endif	.update_jacks = ad1985_update_jacks,};int patch_ad1985(struct snd_ac97 * ac97){	unsigned short misc;		patch_ad1881(ac97);	ac97->build_ops = &patch_ad1985_build_ops;	misc = snd_ac

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -