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

📄 patch_analog.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * HD audio interface patch for AD1981HD, AD1983, AD1986A * * Copyright (c) 2005 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"struct ad198x_spec {	snd_kcontrol_new_t *mixers[5];	int num_mixers;	const struct hda_verb *init_verbs[3];	/* 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					 */	/* 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() */	struct semaphore amp_mutex;	/* PCM volume/mute control mutex */	unsigned int spdif_route;};/* * input MUX handling (common part) */static int ad198x_mux_enum_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo){	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);	struct ad198x_spec *spec = codec->spec;	return snd_hda_input_mux_info(spec->input_mux, uinfo);}static int ad198x_mux_enum_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol){	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);	struct ad198x_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 ad198x_mux_enum_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol){	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);	struct ad198x_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]);}/* * initialization (common callbacks) */static int ad198x_init(struct hda_codec *codec){	struct ad198x_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 int ad198x_build_controls(struct hda_codec *codec){	struct ad198x_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;}/* * Analog playback callbacks */static int ad198x_playback_pcm_open(struct hda_pcm_stream *hinfo,				    struct hda_codec *codec,				    snd_pcm_substream_t *substream){	struct ad198x_spec *spec = codec->spec;	return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);}static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo,				       struct hda_codec *codec,				       unsigned int stream_tag,				       unsigned int format,				       snd_pcm_substream_t *substream){	struct ad198x_spec *spec = codec->spec;	return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,						format, substream);}static int ad198x_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,				       struct hda_codec *codec,				       snd_pcm_substream_t *substream){	struct ad198x_spec *spec = codec->spec;	return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);}/* * Digital out */static int ad198x_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,					struct hda_codec *codec,					snd_pcm_substream_t *substream){	struct ad198x_spec *spec = codec->spec;	return snd_hda_multi_out_dig_open(codec, &spec->multiout);}static int ad198x_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,					 struct hda_codec *codec,					 snd_pcm_substream_t *substream){	struct ad198x_spec *spec = codec->spec;	return snd_hda_multi_out_dig_close(codec, &spec->multiout);}/* * Analog capture */static int ad198x_capture_pcm_prepare(struct hda_pcm_stream *hinfo,				      struct hda_codec *codec,				      unsigned int stream_tag,				      unsigned int format,				      snd_pcm_substream_t *substream){	struct ad198x_spec *spec = codec->spec;	snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],				   stream_tag, 0, format);	return 0;}static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,				      struct hda_codec *codec,				      snd_pcm_substream_t *substream){	struct ad198x_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 ad198x_pcm_analog_playback = {	.substreams = 1,	.channels_min = 2,	.channels_max = 6, /* changed later */	.nid = 0, /* fill later */	.ops = {		.open = ad198x_playback_pcm_open,		.prepare = ad198x_playback_pcm_prepare,		.cleanup = ad198x_playback_pcm_cleanup	},};static struct hda_pcm_stream ad198x_pcm_analog_capture = {	.substreams = 1,	.channels_min = 2,	.channels_max = 2,	.nid = 0, /* fill later */	.ops = {		.prepare = ad198x_capture_pcm_prepare,		.cleanup = ad198x_capture_pcm_cleanup	},};static struct hda_pcm_stream ad198x_pcm_digital_playback = {	.substreams = 1,	.channels_min = 2,	.channels_max = 2,	.nid = 0, /* fill later */	.ops = {		.open = ad198x_dig_playback_pcm_open,		.close = ad198x_dig_playback_pcm_close	},};static struct hda_pcm_stream ad198x_pcm_digital_capture = {	.substreams = 1,	.channels_min = 2,	.channels_max = 2,	/* NID is set in alc_build_pcms */};static int ad198x_build_pcms(struct hda_codec *codec){	struct ad198x_spec *spec = codec->spec;	struct hda_pcm *info = spec->pcm_rec;	codec->num_pcms = 1;	codec->pcm_info = info;	info->name = "AD198x Analog";	info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_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] = ad198x_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 = "AD198x Digital";		info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_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] = ad198x_pcm_digital_capture;			info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;		}	}	return 0;}static void ad198x_free(struct hda_codec *codec){	kfree(codec->spec);}#ifdef CONFIG_PMstatic int ad198x_resume(struct hda_codec *codec){	struct ad198x_spec *spec = codec->spec;	int i;	ad198x_init(codec);	for (i = 0; i < spec->num_mixers; i++)		snd_hda_resume_ctls(codec, spec->mixers[i]);	if (spec->multiout.dig_out_nid)		snd_hda_resume_spdif_out(codec);	if (spec->dig_in_nid)		snd_hda_resume_spdif_in(codec);	return 0;}#endifstatic struct hda_codec_ops ad198x_patch_ops = {	.build_controls = ad198x_build_controls,	.build_pcms = ad198x_build_pcms,	.init = ad198x_init,	.free = ad198x_free,#ifdef CONFIG_PM	.resume = ad198x_resume,#endif};/* * AD1986A specific */#define AD1986A_SPDIF_OUT	0x02#define AD1986A_FRONT_DAC	0x03#define AD1986A_SURR_DAC	0x04#define AD1986A_CLFE_DAC	0x05#define AD1986A_ADC		0x06static hda_nid_t ad1986a_dac_nids[3] = {	AD1986A_FRONT_DAC, AD1986A_SURR_DAC, AD1986A_CLFE_DAC};static hda_nid_t ad1986a_adc_nids[1] = { AD1986A_ADC };static struct hda_input_mux ad1986a_capture_source = {	.num_items = 7,	.items = {		{ "Mic", 0x0 },		{ "CD", 0x1 },		{ "Aux", 0x3 },		{ "Line", 0x4 },		{ "Mix", 0x5 },		{ "Mono", 0x6 },		{ "Phone", 0x7 },	},};/* * PCM control * * bind volumes/mutes of 3 DACs as a single PCM control for simplicity */#define ad1986a_pcm_amp_vol_info	snd_hda_mixer_amp_volume_infostatic int ad1986a_pcm_amp_vol_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol){	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);	struct ad198x_spec *ad = codec->spec;	down(&ad->amp_mutex);	snd_hda_mixer_amp_volume_get(kcontrol, ucontrol);	up(&ad->amp_mutex);	return 0;}static int ad1986a_pcm_amp_vol_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol){	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);	struct ad198x_spec *ad = codec->spec;	int i, change = 0;	down(&ad->amp_mutex);	for (i = 0; i < ARRAY_SIZE(ad1986a_dac_nids); i++) {		kcontrol->private_value = HDA_COMPOSE_AMP_VAL(ad1986a_dac_nids[i], 3, 0, HDA_OUTPUT);		change |= snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);	}	kcontrol->private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT);	up(&ad->amp_mutex);	return change;}#define ad1986a_pcm_amp_sw_info		snd_hda_mixer_amp_switch_infostatic int ad1986a_pcm_amp_sw_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol){	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);	struct ad198x_spec *ad = codec->spec;	down(&ad->amp_mutex);	snd_hda_mixer_amp_switch_get(kcontrol, ucontrol);	up(&ad->amp_mutex);	return 0;}static int ad1986a_pcm_amp_sw_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol){	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);	struct ad198x_spec *ad = codec->spec;	int i, change = 0;	down(&ad->amp_mutex);	for (i = 0; i < ARRAY_SIZE(ad1986a_dac_nids); i++) {		kcontrol->private_value = HDA_COMPOSE_AMP_VAL(ad1986a_dac_nids[i], 3, 0, HDA_OUTPUT);		change |= snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);	}	kcontrol->private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT);	up(&ad->amp_mutex);	return change;}/* * mixers */static snd_kcontrol_new_t ad1986a_mixers[] = {	{		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,		.name = "PCM Playback Volume",		.info = ad1986a_pcm_amp_vol_info,		.get = ad1986a_pcm_amp_vol_get,		.put = ad1986a_pcm_amp_vol_put,		.private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT)	},	{		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,		.name = "PCM Playback Switch",		.info = ad1986a_pcm_amp_sw_info,		.get = ad1986a_pcm_amp_sw_get,		.put = ad1986a_pcm_amp_sw_put,		.private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT)	},	HDA_CODEC_VOLUME("Front Playback Volume", 0x1b, 0x0, HDA_OUTPUT),	HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),	HDA_CODEC_VOLUME("Surround Playback Volume", 0x1c, 0x0, HDA_OUTPUT),	HDA_CODEC_MUTE("Surround Playback Switch", 0x1c, 0x0, HDA_OUTPUT),	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x1d, 1, 0x0, HDA_OUTPUT),	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x1d, 2, 0x0, HDA_OUTPUT),	HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x1d, 1, 0x0, HDA_OUTPUT),	HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x1d, 2, 0x0, HDA_OUTPUT),

⌨️ 快捷键说明

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