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

📄 patch_sigmatel.c

📁 linux2.6.16版本
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * Universal Interface for Intel High Definition Audio Codec * * HD audio interface patch for SigmaTel STAC92xx * * Copyright (c) 2005 Embedded Alley Solutions, Inc. * Matt Porter <mporter@embeddedalley.com> * * Based on patch_cmedia.c and patch_realtek.c * Copyright (c) 2004 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 <sound/asoundef.h>#include "hda_codec.h"#include "hda_local.h"#define NUM_CONTROL_ALLOC	32#define STAC_HP_EVENT		0x37#define STAC_UNSOL_ENABLE 	(AC_USRSP_EN | STAC_HP_EVENT)#define STAC_REF		0#define STAC_D945GTP3		1#define STAC_D945GTP5		2struct sigmatel_spec {	struct snd_kcontrol_new *mixers[4];	unsigned int num_mixers;	int board_config;	unsigned int surr_switch: 1;	unsigned int line_switch: 1;	unsigned int mic_switch: 1;	unsigned int alt_switch: 1;	/* playback */	struct hda_multi_out multiout;	hda_nid_t dac_nids[5];	/* capture */	hda_nid_t *adc_nids;	unsigned int num_adcs;	hda_nid_t *mux_nids;	unsigned int num_muxes;	hda_nid_t dig_in_nid;	/* pin widgets */	hda_nid_t *pin_nids;	unsigned int num_pins;	unsigned int *pin_configs;	/* codec specific stuff */	struct hda_verb *init;	struct snd_kcontrol_new *mixer;	/* capture source */	struct hda_input_mux *input_mux;	unsigned int cur_mux[3];	/* i/o switches */	unsigned int io_switch[2];	struct hda_pcm pcm_rec[2];	/* PCM information */	/* dynamic controls 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;};static hda_nid_t stac9200_adc_nids[1] = {        0x03,};static hda_nid_t stac9200_mux_nids[1] = {        0x0c,};static hda_nid_t stac9200_dac_nids[1] = {        0x02,};static hda_nid_t stac922x_adc_nids[2] = {        0x06, 0x07,};static hda_nid_t stac922x_mux_nids[2] = {        0x12, 0x13,};static hda_nid_t stac927x_adc_nids[3] = {        0x07, 0x08, 0x09};static hda_nid_t stac927x_mux_nids[3] = {        0x15, 0x16, 0x17};static hda_nid_t stac9200_pin_nids[8] = {	0x08, 0x09, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12,};static hda_nid_t stac922x_pin_nids[10] = {	0x0a, 0x0b, 0x0c, 0x0d, 0x0e,	0x0f, 0x10, 0x11, 0x15, 0x1b,};static hda_nid_t stac927x_pin_nids[14] = {	0x0a, 0x0b, 0x0c, 0x0d, 0x0e,	0x0f, 0x10, 0x11, 0x12, 0x13,	0x14, 0x21, 0x22, 0x23,};static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo){	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);	struct sigmatel_spec *spec = codec->spec;	return snd_hda_input_mux_info(spec->input_mux, uinfo);}static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);	struct sigmatel_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 stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);	struct sigmatel_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->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);}static struct hda_verb stac9200_core_init[] = {	/* set dac0mux for dac converter */	{ 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},	{}};static struct hda_verb stac922x_core_init[] = {	/* set master volume and direct control */		{ 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},	{}};static struct hda_verb stac927x_core_init[] = {	/* set master volume and direct control */		{ 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},	{}};static struct snd_kcontrol_new stac9200_mixer[] = {	HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),	HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),	{		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,		.name = "Input Source",		.count = 1,		.info = stac92xx_mux_enum_info,		.get = stac92xx_mux_enum_get,		.put = stac92xx_mux_enum_put,	},	HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),	HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),	HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),	{ } /* end */};/* This needs to be generated dynamically based on sequence */static struct snd_kcontrol_new stac922x_mixer[] = {	{		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,		.name = "Input Source",		.count = 1,		.info = stac92xx_mux_enum_info,		.get = stac92xx_mux_enum_get,		.put = stac92xx_mux_enum_put,	},	HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),	HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),	HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),	{ } /* end */};static snd_kcontrol_new_t stac927x_mixer[] = {	{		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,		.name = "Input Source",		.count = 1,		.info = stac92xx_mux_enum_info,		.get = stac92xx_mux_enum_get,		.put = stac92xx_mux_enum_put,	},	HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT),	HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT),	HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT),	{ } /* end */};static int stac92xx_build_controls(struct hda_codec *codec){	struct sigmatel_spec *spec = codec->spec;	int err;	int i;	err = snd_hda_add_new_ctls(codec, spec->mixer);	if (err < 0)		return 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 unsigned int ref9200_pin_configs[8] = {	0x01c47010, 0x01447010, 0x0221401f, 0x01114010,	0x02a19020, 0x01a19021, 0x90100140, 0x01813122,};static unsigned int *stac9200_brd_tbl[] = {	ref9200_pin_configs,};static struct hda_board_config stac9200_cfg_tbl[] = {	{ .modelname = "ref",	  .pci_subvendor = PCI_VENDOR_ID_INTEL,	  .pci_subdevice = 0x2668,	/* DFI LanParty */	  .config = STAC_REF },	{} /* terminator */};static unsigned int ref922x_pin_configs[10] = {	0x01014010, 0x01016011, 0x01012012, 0x0221401f,	0x01813122, 0x01011014, 0x01441030, 0x01c41030,	0x40000100, 0x40000100,};static unsigned int d945gtp3_pin_configs[10] = {	0x0221401f, 0x01a19022, 0x01813021, 0x01014010,	0x40000100, 0x40000100, 0x40000100, 0x40000100,	0x02a19120, 0x40000100,};static unsigned int d945gtp5_pin_configs[10] = {	0x0221401f, 0x01011012, 0x01813024, 0x01014010,	0x01a19021, 0x01016011, 0x01452130, 0x40000100,	0x02a19320, 0x40000100,};static unsigned int *stac922x_brd_tbl[] = {	ref922x_pin_configs,	d945gtp3_pin_configs,	d945gtp5_pin_configs,};static struct hda_board_config stac922x_cfg_tbl[] = {	{ .modelname = "ref",	  .pci_subvendor = PCI_VENDOR_ID_INTEL,	  .pci_subdevice = 0x2668,	/* DFI LanParty */	  .config = STAC_REF },		/* SigmaTel reference board */	{ .pci_subvendor = PCI_VENDOR_ID_INTEL,	  .pci_subdevice = 0x0101,	  .config = STAC_D945GTP3 },	/* Intel D945GTP - 3 Stack */	{ .pci_subvendor = PCI_VENDOR_ID_INTEL,	  .pci_subdevice = 0x0404,	  .config = STAC_D945GTP5 },	/* Intel D945GTP - 5 Stack */	{ .pci_subvendor = PCI_VENDOR_ID_INTEL,	  .pci_subdevice = 0x0303,	  .config = STAC_D945GTP5 },	/* Intel D945GNT - 5 Stack */	{ .pci_subvendor = PCI_VENDOR_ID_INTEL,	  .pci_subdevice = 0x0013,	  .config = STAC_D945GTP5 },	/* Intel D955XBK - 5 Stack */	{ .pci_subvendor = PCI_VENDOR_ID_INTEL,	  .pci_subdevice = 0x0417,	  .config = STAC_D945GTP5 },	/* Intel D975XBK - 5 Stack */	{} /* terminator */};static unsigned int ref927x_pin_configs[14] = {	0x01813122, 0x01a19021, 0x01014010, 0x01016011,	0x01012012, 0x01011014, 0x40000100, 0x40000100, 	0x40000100, 0x40000100, 0x40000100, 0x01441030,	0x01c41030, 0x40000100,};static unsigned int *stac927x_brd_tbl[] = {	ref927x_pin_configs,};static struct hda_board_config stac927x_cfg_tbl[] = {	{ .modelname = "ref",	  .pci_subvendor = PCI_VENDOR_ID_INTEL,	  .pci_subdevice = 0x2668,	/* DFI LanParty */	  .config = STAC_REF },		/* SigmaTel reference board */	{} /* terminator */};static void stac92xx_set_config_regs(struct hda_codec *codec){	int i;	struct sigmatel_spec *spec = codec->spec;	unsigned int pin_cfg;	for (i=0; i < spec->num_pins; i++) {		snd_hda_codec_write(codec, spec->pin_nids[i], 0,				    AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,				    spec->pin_configs[i] & 0x000000ff);		snd_hda_codec_write(codec, spec->pin_nids[i], 0,				    AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,				    (spec->pin_configs[i] & 0x0000ff00) >> 8);		snd_hda_codec_write(codec, spec->pin_nids[i], 0,				    AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,				    (spec->pin_configs[i] & 0x00ff0000) >> 16);		snd_hda_codec_write(codec, spec->pin_nids[i], 0,				    AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,				    spec->pin_configs[i] >> 24);		pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,					     AC_VERB_GET_CONFIG_DEFAULT,					     0x00);			snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n", spec->pin_nids[i], pin_cfg);	}}/* * Analog playback callbacks */static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,				      struct hda_codec *codec,				      struct snd_pcm_substream *substream){	struct sigmatel_spec *spec = codec->spec;	return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);}static int stac92xx_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 sigmatel_spec *spec = codec->spec;	return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);}static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,					struct hda_codec *codec,					struct snd_pcm_substream *substream){

⌨️ 快捷键说明

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