📄 patch_conexant.c
字号:
/* * HD audio interface patch for Conexant HDA audio codec * * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com> * Takashi Iwai <tiwai@suse.de> * Tobin Davis <tdavis@dsl-only.net> * * 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"#define CXT_PIN_DIR_IN 0x00#define CXT_PIN_DIR_OUT 0x01#define CXT_PIN_DIR_INOUT 0x02#define CXT_PIN_DIR_IN_NOMICBIAS 0x03#define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04#define CONEXANT_HP_EVENT 0x37#define CONEXANT_MIC_EVENT 0x38struct conexant_spec { struct snd_kcontrol_new *mixers[5]; int num_mixers; const struct hda_verb *init_verbs[5]; /* initialization verbs * don't forget NULL * termination! */ unsigned int num_init_verbs; /* playback */ struct hda_multi_out multiout; /* playback set-up * max_channels, dacs must be set * dig_out_nid and hp_nid are optional */ unsigned int cur_eapd; unsigned int hp_present; unsigned int need_dac_fix; /* 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; hda_nid_t *capsrc_nids; 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[2]; /* used in build_pcms() */ struct mutex amp_mutex; /* PCM volume/mute control mutex */ unsigned int spdif_route; /* 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[AUTO_CFG_MAX_OUTS];};static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo, struct hda_codec *codec, struct snd_pcm_substream *substream){ struct conexant_spec *spec = codec->spec; return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);}static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo, struct hda_codec *codec, unsigned int stream_tag, unsigned int format, struct snd_pcm_substream *substream){ struct conexant_spec *spec = codec->spec; return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);}static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, struct hda_codec *codec, struct snd_pcm_substream *substream){ struct conexant_spec *spec = codec->spec; return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);}/* * Digital out */static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, struct hda_codec *codec, struct snd_pcm_substream *substream){ struct conexant_spec *spec = codec->spec; return snd_hda_multi_out_dig_open(codec, &spec->multiout);}static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, struct hda_codec *codec, struct snd_pcm_substream *substream){ struct conexant_spec *spec = codec->spec; return snd_hda_multi_out_dig_close(codec, &spec->multiout);}static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, struct hda_codec *codec, unsigned int stream_tag, unsigned int format, struct snd_pcm_substream *substream){ struct conexant_spec *spec = codec->spec; return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag, format, substream);}/* * Analog capture */static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo, struct hda_codec *codec, unsigned int stream_tag, unsigned int format, struct snd_pcm_substream *substream){ struct conexant_spec *spec = codec->spec; snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], stream_tag, 0, format); return 0;}static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, struct hda_codec *codec, struct snd_pcm_substream *substream){ struct conexant_spec *spec = codec->spec; snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0); return 0;}static struct hda_pcm_stream conexant_pcm_analog_playback = { .substreams = 1, .channels_min = 2, .channels_max = 2, .nid = 0, /* fill later */ .ops = { .open = conexant_playback_pcm_open, .prepare = conexant_playback_pcm_prepare, .cleanup = conexant_playback_pcm_cleanup },};static struct hda_pcm_stream conexant_pcm_analog_capture = { .substreams = 1, .channels_min = 2, .channels_max = 2, .nid = 0, /* fill later */ .ops = { .prepare = conexant_capture_pcm_prepare, .cleanup = conexant_capture_pcm_cleanup },};static struct hda_pcm_stream conexant_pcm_digital_playback = { .substreams = 1, .channels_min = 2, .channels_max = 2, .nid = 0, /* fill later */ .ops = { .open = conexant_dig_playback_pcm_open, .close = conexant_dig_playback_pcm_close, .prepare = conexant_dig_playback_pcm_prepare },};static struct hda_pcm_stream conexant_pcm_digital_capture = { .substreams = 1, .channels_min = 2, .channels_max = 2, /* NID is set in alc_build_pcms */};static int conexant_build_pcms(struct hda_codec *codec){ struct conexant_spec *spec = codec->spec; struct hda_pcm *info = spec->pcm_rec; codec->num_pcms = 1; codec->pcm_info = info; info->name = "CONEXANT Analog"; info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback; info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels; info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0]; info->stream[SNDRV_PCM_STREAM_CAPTURE] = conexant_pcm_analog_capture; info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids; info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; if (spec->multiout.dig_out_nid) { info++; codec->num_pcms++; info->name = "Conexant Digital"; info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_digital_playback; info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; if (spec->dig_in_nid) { info->stream[SNDRV_PCM_STREAM_CAPTURE] = conexant_pcm_digital_capture; info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid; } } return 0;}static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo){ struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct conexant_spec *spec = codec->spec; return snd_hda_input_mux_info(spec->input_mux, uinfo);}static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct conexant_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 conexant_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct conexant_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->capsrc_nids[adc_idx], &spec->cur_mux[adc_idx]);}static int conexant_init(struct hda_codec *codec){ struct conexant_spec *spec = codec->spec; int i; for (i = 0; i < spec->num_init_verbs; i++) snd_hda_sequence_write(codec, spec->init_verbs[i]); return 0;}static void conexant_free(struct hda_codec *codec){ struct conexant_spec *spec = codec->spec; unsigned int i; if (spec->kctl_alloc) { for (i = 0; i < spec->num_kctl_used; i++) kfree(spec->kctl_alloc[i].name); kfree(spec->kctl_alloc); } kfree(codec->spec);}static int conexant_build_controls(struct hda_codec *codec){ struct conexant_spec *spec = codec->spec; unsigned int i; int err; for (i = 0; i < spec->num_mixers; i++) { err = snd_hda_add_new_ctls(codec, spec->mixers[i]); if (err < 0) return err; } if (spec->multiout.dig_out_nid) { err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid); if (err < 0) return err; } if (spec->dig_in_nid) { err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid); if (err < 0) return err; } return 0;}static struct hda_codec_ops conexant_patch_ops = { .build_controls = conexant_build_controls, .build_pcms = conexant_build_pcms, .init = conexant_init, .free = conexant_free,};/* * EAPD control * the private value = nid | (invert << 8) */#define cxt_eapd_info snd_ctl_boolean_mono_infostatic int cxt_eapd_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct conexant_spec *spec = codec->spec; int invert = (kcontrol->private_value >> 8) & 1; if (invert) ucontrol->value.integer.value[0] = !spec->cur_eapd; else ucontrol->value.integer.value[0] = spec->cur_eapd; return 0;}static int cxt_eapd_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct conexant_spec *spec = codec->spec; int invert = (kcontrol->private_value >> 8) & 1; hda_nid_t nid = kcontrol->private_value & 0xff; unsigned int eapd; eapd = ucontrol->value.integer.value[0]; if (invert) eapd = !eapd; if (eapd == spec->cur_eapd) return 0; spec->cur_eapd = eapd; snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE, eapd ? 0x02 : 0x00); return 1;}/* controls for test mode */#ifdef CONFIG_SND_DEBUG#define CXT_EAPD_SWITCH(xname, nid, mask) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ .info = cxt_eapd_info, \ .get = cxt_eapd_get, \ .put = cxt_eapd_put, \ .private_value = nid | (mask<<16) }static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo){ struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct conexant_spec *spec = codec->spec; return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode, spec->num_channel_mode);}static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct conexant_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 conexant_ch_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct conexant_spec *spec = codec->spec; int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode, spec->num_channel_mode, &spec->multiout.max_channels); if (err >= 0 && spec->need_dac_fix) spec->multiout.num_dacs = spec->multiout.max_channels / 2; return err;}#define CXT_PIN_MODE(xname, nid, dir) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ .info = conexant_ch_mode_info, \ .get = conexant_ch_mode_get, \ .put = conexant_ch_mode_put, \ .private_value = nid | (dir<<16) }#endif /* CONFIG_SND_DEBUG *//* Conexant 5045 specific */static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -