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

📄 ac97_patch.c

📁 linux-2.6.15.6
💻 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;}/* * shared line-in/mic controls */static int ac97_enum_text_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo,			       const char **texts, unsigned int nums){	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;	uinfo->count = 1;	uinfo->value.enumerated.items = nums;	if (uinfo->value.enumerated.item > nums - 1)		uinfo->value.enumerated.item = nums - 1;	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);	return 0;}static int ac97_surround_jack_mode_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo){	static const char *texts[] = { "Shared", "Independent" };	return ac97_enum_text_info(kcontrol, uinfo, texts, 2);}static int ac97_surround_jack_mode_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol){	ac97_t *ac97 = snd_kcontrol_chip(kcontrol);	ucontrol->value.enumerated.item[0] = ac97->indep_surround;	return 0;}static int ac97_surround_jack_mode_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol){	ac97_t *ac97 = snd_kcontrol_chip(kcontrol);	unsigned char indep = !!ucontrol->value.enumerated.item[0];	if (indep != ac97->indep_surround) {		ac97->indep_surround = indep;		if (ac97->build_ops->update_jacks)			ac97->build_ops->update_jacks(ac97);		return 1;	}	return 0;}static int ac97_channel_mode_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo){	static const char *texts[] = { "2ch", "4ch", "6ch" };	if (kcontrol->private_value)		return ac97_enum_text_info(kcontrol, uinfo, texts, 2); /* 4ch only */	return ac97_enum_text_info(kcontrol, uinfo, texts, 3);}static int ac97_channel_mode_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol){	ac97_t *ac97 = snd_kcontrol_chip(kcontrol);	ucontrol->value.enumerated.item[0] = ac97->channel_mode;	return 0;}static int ac97_channel_mode_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol){	ac97_t *ac97 = snd_kcontrol_chip(kcontrol);	unsigned char mode = ucontrol->value.enumerated.item[0];	if (mode != ac97->channel_mode) {		ac97->channel_mode = mode;		if (ac97->build_ops->update_jacks)			ac97->build_ops->update_jacks(ac97);		return 1;	}	return 0;}#define AC97_SURROUND_JACK_MODE_CTL \	{ \		.iface	= SNDRV_CTL_ELEM_IFACE_MIXER, \		.name	= "Surround Jack Mode", \		.info = ac97_surround_jack_mode_info, \		.get = ac97_surround_jack_mode_get, \		.put = ac97_surround_jack_mode_put, \	}#define AC97_CHANNEL_MODE_CTL \	{ \		.iface	= SNDRV_CTL_ELEM_IFACE_MIXER, \		.name	= "Channel Mode", \		.info = ac97_channel_mode_info, \		.get = ac97_channel_mode_get, \		.put = ac97_channel_mode_put, \	}#define AC97_CHANNEL_MODE_4CH_CTL \	{ \		.iface	= SNDRV_CTL_ELEM_IFACE_MIXER, \		.name	= "Channel Mode", \		.info = ac97_channel_mode_info, \		.get = ac97_channel_mode_get, \		.put = ac97_channel_mode_put, \		.private_value = 1, \	}static inline int is_surround_on(ac97_t *ac97){	return ac97->channel_mode >= 1;}static inline int is_clfe_on(ac97_t *ac97){	return ac97->channel_mode >= 2;}static inline int is_shared_linein(ac97_t *ac97){	return ! ac97->indep_surround && is_surround_on(ac97);}static inline int is_shared_micin(ac97_t *ac97){	return ! ac97->indep_surround && is_clfe_on(ac97);}/* 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. */static const snd_kcontrol_new_t wm97xx_snd_ac97_controls[] = {AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1),AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1),};static int patch_wolfson_wm9703_specific(ac97_t * ac97){	/* This is known to work for the ViewSonic ViewPad 1000	 * Randolph Bentson <bentson@holmsjoen.com>

⌨️ 快捷键说明

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