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

📄 ac97_patch.c

📁 h内核
💻 C
📖 第 1 页 / 共 5 页
字号:
/* *  Copyright (c) by Jaroslav Kysela <perex@suse.cz> *  Universal interface for Audio Codec '97 * *  For more details look to AC '97 component specification revision 2.2 *  by Intel Corporation (http://developer.intel.com) and to datasheets *  for specific codecs. * * *   This program is free software; you can redistribute it and/or modify *   it under the terms of the GNU General Public License as published by *   the Free Software Foundation; either version 2 of the License, or *   (at your option) any later version. * *   This program is distributed in the hope that it will be useful, *   but WITHOUT ANY WARRANTY; without even the implied warranty of *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *   GNU General Public License for more details. * *   You should have received a copy of the GNU General Public License *   along with this program; if not, write to the Free Software *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA * */#include <sound/driver.h>#include <linux/delay.h>#include <linux/init.h>#include <linux/slab.h>#include <sound/core.h>#include <sound/pcm.h>#include <sound/control.h>#include <sound/ac97_codec.h>#include "ac97_patch.h"#include "ac97_id.h"#include "ac97_local.h"/* *  Chip specific initialization */static int patch_build_controls(ac97_t * ac97, const snd_kcontrol_new_t *controls, int count){	int idx, err;	for (idx = 0; idx < count; idx++)		if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&controls[idx], ac97))) < 0)			return err;	return 0;}/* set to the page, update bits and restore the page */static int ac97_update_bits_page(ac97_t *ac97, unsigned short reg, unsigned short mask, unsigned short value, unsigned short page){	unsigned short page_save;	int ret;	down(&ac97->page_mutex);	page_save = snd_ac97_read(ac97, AC97_INT_PAGING) & AC97_PAGE_MASK;	snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page);	ret = snd_ac97_update_bits(ac97, reg, mask, value);	snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page_save);	up(&ac97->page_mutex); /* unlock paging */	return ret;}/* The following snd_ac97_ymf753_... items added by David Shust (dshust@shustring.com) *//* It is possible to indicate to the Yamaha YMF753 the type of speakers being used. */static int snd_ac97_ymf753_info_speaker(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo){	static char *texts[3] = {		"Standard", "Small", "Smaller"	};	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_ymf753_get_speaker(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){	ac97_t *ac97 = snd_kcontrol_chip(kcontrol);	unsigned short val;	val = ac97->regs[AC97_YMF753_3D_MODE_SEL];	val = (val >> 10) & 3;	if (val > 0)    /* 0 = invalid */		val--;	ucontrol->value.enumerated.item[0] = val;	return 0;}static int snd_ac97_ymf753_put_speaker(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){	ac97_t *ac97 = snd_kcontrol_chip(kcontrol);	unsigned short val;	if (ucontrol->value.enumerated.item[0] > 2)		return -EINVAL;	val = (ucontrol->value.enumerated.item[0] + 1) << 10;	return snd_ac97_update(ac97, AC97_YMF753_3D_MODE_SEL, val);}static const snd_kcontrol_new_t snd_ac97_ymf753_controls_speaker ={	.iface  = SNDRV_CTL_ELEM_IFACE_MIXER,	.name   = "3D Control - Speaker",	.info   = snd_ac97_ymf753_info_speaker,	.get    = snd_ac97_ymf753_get_speaker,	.put    = snd_ac97_ymf753_put_speaker,};/* It is possible to indicate to the Yamaha YMF753 the source to direct to the S/PDIF output. */static int snd_ac97_ymf753_spdif_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * 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_ymf753_spdif_source_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){	ac97_t *ac97 = snd_kcontrol_chip(kcontrol);	unsigned short val;	val = ac97->regs[AC97_YMF753_DIT_CTRL2];	ucontrol->value.enumerated.item[0] = (val >> 1) & 1;	return 0;}static int snd_ac97_ymf753_spdif_source_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){	ac97_t *ac97 = snd_kcontrol_chip(kcontrol);	unsigned short val;	if (ucontrol->value.enumerated.item[0] > 1)		return -EINVAL;	val = ucontrol->value.enumerated.item[0] << 1;	return snd_ac97_update_bits(ac97, AC97_YMF753_DIT_CTRL2, 0x0002, val);}/* The AC'97 spec states that the S/PDIF signal is to be output at pin 48.   The YMF753 will output the S/PDIF signal to pin 43, 47 (EAPD), or 48.   By default, no output pin is selected, and the S/PDIF signal is not output.   There is also a bit to mute S/PDIF output in a vendor-specific register. */static int snd_ac97_ymf753_spdif_output_pin_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo){	static char *texts[3] = { "Disabled", "Pin 43", "Pin 48" };	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_ymf753_spdif_output_pin_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){	ac97_t *ac97 = snd_kcontrol_chip(kcontrol);	unsigned short val;	val = ac97->regs[AC97_YMF753_DIT_CTRL2];	ucontrol->value.enumerated.item[0] = (val & 0x0008) ? 2 : (val & 0x0020) ? 1 : 0;	return 0;}static int snd_ac97_ymf753_spdif_output_pin_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){	ac97_t *ac97 = snd_kcontrol_chip(kcontrol);	unsigned short val;	if (ucontrol->value.enumerated.item[0] > 2)		return -EINVAL;	val = (ucontrol->value.enumerated.item[0] == 2) ? 0x0008 :	      (ucontrol->value.enumerated.item[0] == 1) ? 0x0020 : 0;	return snd_ac97_update_bits(ac97, AC97_YMF753_DIT_CTRL2, 0x0028, val);	/* The following can be used to direct S/PDIF output to pin 47 (EAPD).	   snd_ac97_write_cache(ac97, 0x62, snd_ac97_read(ac97, 0x62) | 0x0008); */}static const snd_kcontrol_new_t snd_ac97_ymf753_controls_spdif[3] = {	{		.iface	= SNDRV_CTL_ELEM_IFACE_MIXER,		.name	= SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",		.info	= snd_ac97_ymf753_spdif_source_info,		.get	= snd_ac97_ymf753_spdif_source_get,		.put	= snd_ac97_ymf753_spdif_source_put,	},	{		.iface	= SNDRV_CTL_ELEM_IFACE_MIXER,		.name	= SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Output Pin",		.info	= snd_ac97_ymf753_spdif_output_pin_info,		.get	= snd_ac97_ymf753_spdif_output_pin_get,		.put	= snd_ac97_ymf753_spdif_output_pin_put,	},	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",NONE,NONE) "Mute", AC97_YMF753_DIT_CTRL2, 2, 1, 1)};static int patch_yamaha_ymf753_3d(ac97_t * ac97){	snd_kcontrol_t *kctl;	int err;	if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)		return err;	strcpy(kctl->id.name, "3D Control - Wide");	kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 9, 7, 0);	snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);	if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&snd_ac97_ymf753_controls_speaker, ac97))) < 0)		return err;	snd_ac97_write_cache(ac97, AC97_YMF753_3D_MODE_SEL, 0x0c00);	return 0;}static int patch_yamaha_ymf753_post_spdif(ac97_t * ac97){	int err;	if ((err = patch_build_controls(ac97, snd_ac97_ymf753_controls_spdif, ARRAY_SIZE(snd_ac97_ymf753_controls_spdif))) < 0)		return err;	return 0;}static struct snd_ac97_build_ops patch_yamaha_ymf753_ops = {	.build_3d	= patch_yamaha_ymf753_3d,	.build_post_spdif = patch_yamaha_ymf753_post_spdif};int patch_yamaha_ymf753(ac97_t * ac97){	/* Patch for Yamaha YMF753, Copyright (c) by David Shust, dshust@shustring.com.	   This chip has nonstandard and extended behaviour with regard to its S/PDIF output.	   The AC'97 spec states that the S/PDIF signal is to be output at pin 48.	   The YMF753 will ouput the S/PDIF signal to pin 43, 47 (EAPD), or 48.	   By default, no output pin is selected, and the S/PDIF signal is not output.	   There is also a bit to mute S/PDIF output in a vendor-specific register.	*/	ac97->build_ops = &patch_yamaha_ymf753_ops;	ac97->caps |= AC97_BC_BASS_TREBLE;	ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */	return 0;}/* * May 2, 2003 Liam Girdwood <liam.girdwood@wolfsonmicro.com> *  removed broken wolfson00 patch. *  added support for WM9705,WM9708,WM9709,WM9710,WM9711,WM9712 and WM9717. */int patch_wolfson03(ac97_t * ac97){	/* This is known to work for the ViewSonic ViewPad 1000	   Randolph Bentson <bentson@holmsjoen.com> */	// WM9703/9707/9708/9717	snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808);	snd_ac97_write_cache(ac97, AC97_GENERAL_PURPOSE, 0x8000);	return 0;}  int patch_wolfson04(ac97_t * ac97){	// WM9704M/9704Q	// set front and rear mixer volume	snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808);	snd_ac97_write_cache(ac97, AC97_WM9704_RMIXER_VOL, 0x0808);		// patch for DVD noise	snd_ac97_write_cache(ac97, AC97_WM9704_TEST, 0x0200); 	// init vol	snd_ac97_write_cache(ac97, AC97_WM9704_RPCM_VOL, 0x0808); 	// set rear surround volume	snd_ac97_write_cache(ac97, AC97_SURROUND_MASTER, 0x0000);	return 0;}  int patch_wolfson05(ac97_t * ac97){	// WM9705, WM9710	// set front mixer volume	snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808);	return 0;}int patch_wolfson11(ac97_t * ac97){	// WM9711, WM9712	// set out3 volume	snd_ac97_write_cache(ac97, AC97_WM9711_OUT3VOL, 0x0808);	return 0;}/* * Tritech codec */int patch_tritech_tr28028(ac97_t * ac97){	snd_ac97_write_cache(ac97, 0x26, 0x0300);	snd_ac97_write_cache(ac97, 0x26, 0x0000);	snd_ac97_write_cache(ac97, AC97_SURROUND_MASTER, 0x0000);	snd_ac97_write_cache(ac97, AC97_SPDIF, 0x0000);	return 0;}/* * Sigmatel STAC97xx codecs */static int patch_sigmatel_stac9700_3d(ac97_t * ac97){	snd_kcontrol_t *kctl;	int err;	if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)		return err;	strcpy(kctl->id.name, "3D Control Sigmatel - Depth");	kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);	snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);	return 0;}static int patch_sigmatel_stac9708_3d(ac97_t * ac97){	snd_kcontrol_t *kctl;	int err;	if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)		return err;	strcpy(kctl->id.name, "3D Control Sigmatel - Depth");	kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 0, 3, 0);	if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)		return err;	strcpy(kctl->id.name, "3D Control Sigmatel - Rear Depth");	kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);	snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);	return 0;}static const snd_kcontrol_new_t snd_ac97_sigmatel_4speaker =AC97_SINGLE("Sigmatel 4-Speaker Stereo Playback Switch", AC97_SIGMATEL_DAC2INVERT, 2, 1, 0);static const snd_kcontrol_new_t snd_ac97_sigmatel_phaseinvert =AC97_SINGLE("Sigmatel Surround Phase Inversion Playback Switch", AC97_SIGMATEL_DAC2INVERT, 3, 1, 0);static const snd_kcontrol_new_t snd_ac97_sigmatel_controls[] = {AC97_SINGLE("Sigmatel DAC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 1, 1, 0),AC97_SINGLE("Sigmatel ADC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 0, 1, 0)};static int patch_sigmatel_stac97xx_specific(ac97_t * ac97){	int err;	snd_ac97_write_cache(ac97, AC97_SIGMATEL_ANALOG, snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) & ~0x0003);	if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 1))		if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[0], 1)) < 0)			return err;	if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 0))		if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[1], 1)) < 0)			return err;	if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 2))		if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_4speaker, 1)) < 0)			return err;	if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 3))		if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_phaseinvert, 1)) < 0)			return err;	return 0;}static struct snd_ac97_build_ops patch_sigmatel_stac9700_ops = {	.build_3d	= patch_sigmatel_stac9700_3d,	.build_specific	= patch_sigmatel_stac97xx_specific};int patch_sigmatel_stac9700(ac97_t * ac97){	ac97->build_ops = &patch_sigmatel_stac9700_ops;	return 0;}static int patch_sigmatel_stac9708_specific(ac97_t *ac97){	snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Sigmatel Surround Playback");	return patch_sigmatel_stac97xx_specific(ac97);}static struct snd_ac97_build_ops patch_sigmatel_stac9708_ops = {	.build_3d	= patch_sigmatel_stac9708_3d,	.build_specific	= patch_sigmatel_stac9708_specific};

⌨️ 快捷键说明

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