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

📄 patch_realtek.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 5 页
字号:
/* * Universal Interface for Intel High Definition Audio Codec * * HD audio interface patch for ALC 260/880/882 codecs * * Copyright (c) 2004 PeiSen Hou <pshou@realtek.com.tw> *                    Takashi Iwai <tiwai@suse.de> * *  This driver 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 driver 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/init.h>#include <linux/delay.h>#include <linux/slab.h>#include <linux/pci.h>#include <sound/core.h>#include "hda_codec.h"#include "hda_local.h"/* ALC880 board config type */enum {	ALC880_3ST,	ALC880_3ST_DIG,	ALC880_5ST,	ALC880_5ST_DIG,	ALC880_W810,	ALC880_Z71V,	ALC880_AUTO,	ALC880_6ST,	ALC880_6ST_DIG,	ALC880_F1734,	ALC880_ASUS,	ALC880_ASUS_DIG,	ALC880_ASUS_W1V,	ALC880_UNIWILL_DIG,#ifdef CONFIG_SND_DEBUG	ALC880_TEST,#endif	ALC880_MODEL_LAST /* last tag */};/* ALC260 models */enum {	ALC260_BASIC,	ALC260_HP,	ALC260_FUJITSU_S702x,	ALC260_MODEL_LAST /* last tag */};/* amp values */#define AMP_IN_MUTE(idx)	(0x7080 | ((idx)<<8))#define AMP_IN_UNMUTE(idx)	(0x7000 | ((idx)<<8))#define AMP_OUT_MUTE	0xb080#define AMP_OUT_UNMUTE	0xb000#define AMP_OUT_ZERO	0xb000/* pinctl values */#define PIN_IN		0x20#define PIN_VREF80	0x24#define PIN_VREF50	0x21#define PIN_OUT		0x40#define PIN_HP		0xc0#define PIN_HP_AMP	0x80struct alc_spec {	/* codec parameterization */	snd_kcontrol_new_t *mixers[3];	/* mixer arrays */	unsigned int num_mixers;	const struct hda_verb *init_verbs[3];	/* initialization verbs						 * don't forget NULL termination!						 */	unsigned int num_init_verbs;	char *stream_name_analog;	/* analog PCM stream */	struct hda_pcm_stream *stream_analog_playback;	struct hda_pcm_stream *stream_analog_capture;	char *stream_name_digital;	/* digital PCM stream */ 	struct hda_pcm_stream *stream_digital_playback;	struct hda_pcm_stream *stream_digital_capture;	/* playback */	struct hda_multi_out multiout;	/* playback set-up					 * max_channels, dacs must be set					 * dig_out_nid and hp_nid are optional					 */	/* capture */	unsigned int num_adc_nids;	hda_nid_t *adc_nids;	hda_nid_t dig_in_nid;		/* digital-in NID; optional */	/* capture source */	const struct hda_input_mux *input_mux;	unsigned int cur_mux[3];	/* channel model */	const struct alc_channel_mode *channel_mode;	int num_channel_mode;	/* PCM information */	struct hda_pcm pcm_rec[2];	/* used in alc_build_pcms() */	/* dynamic controls, init_verbs and input_mux */	struct auto_pin_cfg autocfg;	unsigned int num_kctl_alloc, num_kctl_used;	snd_kcontrol_new_t *kctl_alloc;	struct hda_input_mux private_imux;	hda_nid_t private_dac_nids[4];};/* * input MUX handling */static int alc_mux_enum_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo){	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);	struct alc_spec *spec = codec->spec;	return snd_hda_input_mux_info(spec->input_mux, uinfo);}static int alc_mux_enum_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol){	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);	struct alc_spec *spec = codec->spec;	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);	ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];	return 0;}static int alc_mux_enum_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol){	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);	struct alc_spec *spec = codec->spec;	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);	return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,				     spec->adc_nids[adc_idx], &spec->cur_mux[adc_idx]);}/* * channel mode setting */struct alc_channel_mode {	int channels;	const struct hda_verb *sequence;};static int alc880_ch_mode_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo){	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);	struct alc_spec *spec = codec->spec;	int items = kcontrol->private_value ? (int)kcontrol->private_value : 2;	snd_assert(spec->channel_mode, return -ENXIO);	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;	uinfo->count = 1;	uinfo->value.enumerated.items = items;	if (uinfo->value.enumerated.item >= items)		uinfo->value.enumerated.item = items - 1;	sprintf(uinfo->value.enumerated.name, "%dch",		spec->channel_mode[uinfo->value.enumerated.item].channels);	return 0;}static int alc880_ch_mode_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol){	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);	struct alc_spec *spec = codec->spec;	int items = kcontrol->private_value ? (int)kcontrol->private_value : 2;	int i;	snd_assert(spec->channel_mode, return -ENXIO);	for (i = 0; i < items; i++) {		if (spec->multiout.max_channels == spec->channel_mode[i].channels) {			ucontrol->value.enumerated.item[0] = i;			break;		}	}	return 0;}static int alc880_ch_mode_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol){	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);	struct alc_spec *spec = codec->spec;	int mode;	snd_assert(spec->channel_mode, return -ENXIO);	mode = ucontrol->value.enumerated.item[0] ? 1 : 0;	if (spec->multiout.max_channels == spec->channel_mode[mode].channels &&	    ! codec->in_resume)		return 0;	/* change the current channel setting */	spec->multiout.max_channels = spec->channel_mode[mode].channels;	if (spec->channel_mode[mode].sequence)		snd_hda_sequence_write(codec, spec->channel_mode[mode].sequence);	return 1;}/* * Control of pin widget settings via the mixer.  Only boolean settings are * supported, so VrefEn can't be controlled using these functions as they * stand. */static int alc_pinctl_switch_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *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 alc_pinctl_switch_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol){	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);	hda_nid_t nid = kcontrol->private_value & 0xffff;	long mask = (kcontrol->private_value >> 16) & 0xff;	long *valp = ucontrol->value.integer.value;	*valp = 0;	if (snd_hda_codec_read(codec,nid,0,AC_VERB_GET_PIN_WIDGET_CONTROL,0x00) & mask)		*valp = 1;	return 0;}static int alc_pinctl_switch_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol){	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);	hda_nid_t nid = kcontrol->private_value & 0xffff;	long mask = (kcontrol->private_value >> 16) & 0xff;	long *valp = ucontrol->value.integer.value;	unsigned int pinctl = snd_hda_codec_read(codec,nid,0,AC_VERB_GET_PIN_WIDGET_CONTROL,0x00);	int change = ((pinctl & mask)!=0) != *valp;	if (change)		snd_hda_codec_write(codec,nid,0,AC_VERB_SET_PIN_WIDGET_CONTROL,			*valp?(pinctl|mask):(pinctl&~mask));	return change;}#define ALC_PINCTL_SWITCH(xname, nid, mask) \	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \	  .info = alc_pinctl_switch_info, \	  .get = alc_pinctl_switch_get, \	  .put = alc_pinctl_switch_put, \	  .private_value = (nid) | (mask<<16) }/* * ALC880 3-stack model * * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e) * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18, F-Mic = 0x1b *                 HP = 0x19 */static hda_nid_t alc880_dac_nids[4] = {	/* front, rear, clfe, rear_surr */	0x02, 0x05, 0x04, 0x03};static hda_nid_t alc880_adc_nids[3] = {	/* ADC0-2 */	0x07, 0x08, 0x09,};/* The datasheet says the node 0x07 is connected from inputs, * but it shows zero connection in the real implementation on some devices. */static hda_nid_t alc880_adc_nids_alt[2] = {	/* ADC1-2 */	0x08, 0x09,};#define ALC880_DIGOUT_NID	0x06#define ALC880_DIGIN_NID	0x0astatic struct hda_input_mux alc880_capture_source = {	.num_items = 4,	.items = {		{ "Mic", 0x0 },		{ "Front Mic", 0x3 },		{ "Line", 0x2 },		{ "CD", 0x4 },	},};/* channel source setting (2/6 channel selection for 3-stack) *//* 2ch mode */static struct hda_verb alc880_threestack_ch2_init[] = {	/* set line-in to input, mute it */	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },	/* set mic-in to input vref 80%, mute it */	{ 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },	{ 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },	{ } /* end */};/* 6ch mode */static struct hda_verb alc880_threestack_ch6_init[] = {	/* set line-in to output, unmute it */	{ 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },	{ 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },	/* set mic-in to output, unmute it */	{ 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },	{ 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },	{ } /* end */};static struct alc_channel_mode alc880_threestack_modes[2] = {	{ 2, alc880_threestack_ch2_init },	{ 6, alc880_threestack_ch6_init },};static snd_kcontrol_new_t alc880_three_stack_mixer[] = {	HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),	HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),	HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),	HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),	HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),	HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),	HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),	HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),	HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),	HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),	HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),	HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),	{		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,		.name = "Channel Mode",		.info = alc880_ch_mode_info,		.get = alc880_ch_mode_get,		.put = alc880_ch_mode_put,	},	{ } /* end */};/* capture mixer elements */static snd_kcontrol_new_t alc880_capture_mixer[] = {	HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),	HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),	HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),	HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),	{		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,		/* The multiple "Capture Source" controls confuse alsamixer		 * So call somewhat different..		 * FIXME: the controls appear in the "playback" view!		 */		/* .name = "Capture Source", */		.name = "Input Source",		.count = 3,		.info = alc_mux_enum_info,		.get = alc_mux_enum_get,

⌨️ 快捷键说明

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