📄 patch_realtek.c
字号:
/* * Universal Interface for Intel High Definition Audio Codec * * HD audio interface patch for ALC 260/880/882 codecs * * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw> * PeiSen Hou <pshou@realtek.com.tw> * Takashi Iwai <tiwai@suse.de> * Jonathan Woithe <jwoithe@physics.adelaide.edu.au> * * 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_6ST, ALC880_6ST_DIG, ALC880_F1734, ALC880_ASUS, ALC880_ASUS_DIG, ALC880_ASUS_W1V, ALC880_ASUS_DIG2, ALC880_UNIWILL_DIG, ALC880_CLEVO, ALC880_TCL_S700, ALC880_LG, ALC880_LG_LW,#ifdef CONFIG_SND_DEBUG ALC880_TEST,#endif ALC880_AUTO, ALC880_MODEL_LAST /* last tag */};/* ALC260 models */enum { ALC260_BASIC, ALC260_HP, ALC260_HP_3013, ALC260_FUJITSU_S702X, ALC260_ACER,#ifdef CONFIG_SND_DEBUG ALC260_TEST,#endif ALC260_AUTO, ALC260_MODEL_LAST /* last tag */};/* ALC262 models */enum { ALC262_BASIC, ALC262_FUJITSU, ALC262_AUTO, ALC262_MODEL_LAST /* last tag */};/* ALC861 models */enum { ALC861_3ST, ALC861_3ST_DIG, ALC861_6ST_DIG, ALC861_AUTO, ALC861_MODEL_LAST,};/* ALC882 models */enum { ALC882_3ST_DIG, ALC882_6ST_DIG, ALC882_AUTO, ALC882_MODEL_LAST,};/* for GPIO Poll */#define GPIO_MASK 0x03struct alc_spec { /* codec parameterization */ struct snd_kcontrol_new *mixers[5]; /* mixer arrays */ unsigned int num_mixers; const struct hda_verb *init_verbs[5]; /* 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 */ unsigned int num_mux_defs; const struct hda_input_mux *input_mux; unsigned int cur_mux[3]; /* channel model */ const struct hda_channel_mode *channel_mode; int num_channel_mode; /* PCM information */ struct hda_pcm pcm_rec[3]; /* 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; struct snd_kcontrol_new *kctl_alloc; struct hda_input_mux private_imux; hda_nid_t private_dac_nids[5]; /* hooks */ void (*init_hook)(struct hda_codec *codec); void (*unsol_event)(struct hda_codec *codec, unsigned int res); /* for pin sensing */ unsigned int sense_updated: 1; unsigned int jack_present: 1;};/* * configuration template - to be copied to the spec instance */struct alc_config_preset { struct snd_kcontrol_new *mixers[5]; /* should be identical size with spec */ const struct hda_verb *init_verbs[5]; unsigned int num_dacs; hda_nid_t *dac_nids; hda_nid_t dig_out_nid; /* optional */ hda_nid_t hp_nid; /* optional */ unsigned int num_adc_nids; hda_nid_t *adc_nids; hda_nid_t dig_in_nid; unsigned int num_channel_mode; const struct hda_channel_mode *channel_mode; unsigned int num_mux_defs; const struct hda_input_mux *input_mux; void (*unsol_event)(struct hda_codec *, unsigned int); void (*init_hook)(struct hda_codec *);};/* * input MUX handling */static int alc_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo){ struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct alc_spec *spec = codec->spec; unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id); if (mux_idx >= spec->num_mux_defs) mux_idx = 0; return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);}static int alc_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *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(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *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); unsigned int mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx; return snd_hda_input_mux_put(codec, &spec->input_mux[mux_idx], ucontrol, spec->adc_nids[adc_idx], &spec->cur_mux[adc_idx]);}/* * channel mode setting */static int alc_ch_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo){ struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct alc_spec *spec = codec->spec; return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode, spec->num_channel_mode);}static int alc_ch_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct alc_spec *spec = codec->spec; return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode, spec->num_channel_mode, spec->multiout.max_channels);}static int alc_ch_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct alc_spec *spec = codec->spec; return snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode, spec->num_channel_mode, &spec->multiout.max_channels);}/* * Control the mode of pin widget settings via the mixer. "pc" is used * instead of "%" to avoid consequences of accidently treating the % as * being part of a format specifier. Maximum allowed length of a value is * 63 characters plus NULL terminator. * * Note: some retasking pin complexes seem to ignore requests for input * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these * are requested. Therefore order this list so that this behaviour will not * cause problems when mixer clients move through the enum sequentially. * NIDs 0x0f and 0x10 have been observed to have this behaviour as of * March 2006. */static char *alc_pin_mode_names[] = { "Mic 50pc bias", "Mic 80pc bias", "Line in", "Line out", "Headphone out",};static unsigned char alc_pin_mode_values[] = { PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,};/* The control can present all 5 options, or it can limit the options based * in the pin being assumed to be exclusively an input or an output pin. In * addition, "input" pins may or may not process the mic bias option * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to * accept requests for bias as of chip versions up to March 2006) and/or * wiring in the computer. */#define ALC_PIN_DIR_IN 0x00#define ALC_PIN_DIR_OUT 0x01#define ALC_PIN_DIR_INOUT 0x02#define ALC_PIN_DIR_IN_NOMICBIAS 0x03#define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04/* Info about the pin modes supported by the different pin direction modes. * For each direction the minimum and maximum values are given. */static signed char alc_pin_mode_dir_info[5][2] = { { 0, 2 }, /* ALC_PIN_DIR_IN */ { 3, 4 }, /* ALC_PIN_DIR_OUT */ { 0, 4 }, /* ALC_PIN_DIR_INOUT */ { 2, 2 }, /* ALC_PIN_DIR_IN_NOMICBIAS */ { 2, 4 }, /* ALC_PIN_DIR_INOUT_NOMICBIAS */};#define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])#define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])#define alc_pin_mode_n_items(_dir) \ (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)static int alc_pin_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo){ unsigned int item_num = uinfo->value.enumerated.item; unsigned char dir = (kcontrol->private_value >> 16) & 0xff; uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; uinfo->count = 1; uinfo->value.enumerated.items = alc_pin_mode_n_items(dir); if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir)) item_num = alc_pin_mode_min(dir); strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]); return 0;}static int alc_pin_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ unsigned int i; struct hda_codec *codec = snd_kcontrol_chip(kcontrol); hda_nid_t nid = kcontrol->private_value & 0xffff; unsigned char dir = (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); /* Find enumerated value for current pinctl setting */ i = alc_pin_mode_min(dir); while (alc_pin_mode_values[i]!=pinctl && i<=alc_pin_mode_max(dir)) i++; *valp = i<=alc_pin_mode_max(dir)?i:alc_pin_mode_min(dir); return 0;}static int alc_pin_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ signed int change; struct hda_codec *codec = snd_kcontrol_chip(kcontrol); hda_nid_t nid = kcontrol->private_value & 0xffff; unsigned char dir = (kcontrol->private_value >> 16) & 0xff; long val = *ucontrol->value.integer.value; unsigned int pinctl = snd_hda_codec_read(codec,nid,0,AC_VERB_GET_PIN_WIDGET_CONTROL,0x00); if (val<alc_pin_mode_min(dir) || val>alc_pin_mode_max(dir)) val = alc_pin_mode_min(dir); change = pinctl != alc_pin_mode_values[val]; if (change) { /* Set pin mode to that requested */ snd_hda_codec_write(codec,nid,0,AC_VERB_SET_PIN_WIDGET_CONTROL, alc_pin_mode_values[val]); /* Also enable the retasking pin's input/output as required * for the requested pin mode. Enum values of 2 or less are * input modes. * * Dynamically switching the input/output buffers probably * reduces noise slightly (particularly on input) so we'll * do it. However, having both input and output buffers * enabled simultaneously doesn't seem to be problematic if * this turns out to be necessary in the future. */ if (val <= 2) { snd_hda_codec_write(codec,nid,0,AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE); snd_hda_codec_write(codec,nid,0,AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)); } else { snd_hda_codec_write(codec,nid,0,AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)); snd_hda_codec_write(codec,nid,0,AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE); } } return change;}#define ALC_PIN_MODE(xname, nid, dir) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ .info = alc_pin_mode_info, \ .get = alc_pin_mode_get, \ .put = alc_pin_mode_put, \ .private_value = nid | (dir<<16) }/* A switch control for ALC260 GPIO pins. Multiple GPIOs can be ganged * together using a mask with more than one bit set. This control is * currently used only by the ALC260 test model. At this stage they are not * needed for any "production" models. */#ifdef CONFIG_SND_DEBUGstatic int alc_gpio_data_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 alc_gpio_data_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct hda_codec *codec = snd_kcontrol_chip(kcontrol); hda_nid_t nid = kcontrol->private_value & 0xffff; unsigned char mask = (kcontrol->private_value >> 16) & 0xff; long *valp = ucontrol->value.integer.value; unsigned int val = snd_hda_codec_read(codec,nid,0,AC_VERB_GET_GPIO_DATA,0x00); *valp = (val & mask) != 0; return 0;}static int alc_gpio_data_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ signed int change; struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -