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

📄 patch_sigmatel.c

📁 LINUX 2.6.17.4的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
	.channels_min = 2,	.channels_max = 2,	/* NID is set in stac92xx_build_pcms */};static struct hda_pcm_stream stac92xx_pcm_analog_playback = {	.substreams = 1,	.channels_min = 2,	.channels_max = 8,	.nid = 0x02, /* NID to query formats and rates */	.ops = {		.open = stac92xx_playback_pcm_open,		.prepare = stac92xx_playback_pcm_prepare,		.cleanup = stac92xx_playback_pcm_cleanup	},};static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {	.substreams = 1,	.channels_min = 2,	.channels_max = 2,	.nid = 0x06, /* NID to query formats and rates */	.ops = {		.open = stac92xx_playback_pcm_open,		.prepare = stac92xx_playback_pcm_prepare,		.cleanup = stac92xx_playback_pcm_cleanup	},};static struct hda_pcm_stream stac92xx_pcm_analog_capture = {	.substreams = 2,	.channels_min = 2,	.channels_max = 2,	/* NID is set in stac92xx_build_pcms */	.ops = {		.prepare = stac92xx_capture_pcm_prepare,		.cleanup = stac92xx_capture_pcm_cleanup	},};static int stac92xx_build_pcms(struct hda_codec *codec){	struct sigmatel_spec *spec = codec->spec;	struct hda_pcm *info = spec->pcm_rec;	codec->num_pcms = 1;	codec->pcm_info = info;	info->name = "STAC92xx Analog";	info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;	info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;	info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];	if (spec->alt_switch) {		codec->num_pcms++;		info++;		info->name = "STAC92xx Analog Alt";		info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;	}	if (spec->multiout.dig_out_nid || spec->dig_in_nid) {		codec->num_pcms++;		info++;		info->name = "STAC92xx Digital";		if (spec->multiout.dig_out_nid) {			info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_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] = stac92xx_pcm_digital_capture;			info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;		}	}	return 0;}static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid){	unsigned int pincap = snd_hda_param_read(codec, nid,						 AC_PAR_PIN_CAP);	pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;	if (pincap & AC_PINCAP_VREF_100)		return AC_PINCTL_VREF_100;	if (pincap & AC_PINCAP_VREF_80)		return AC_PINCTL_VREF_80;	if (pincap & AC_PINCAP_VREF_50)		return AC_PINCTL_VREF_50;	if (pincap & AC_PINCAP_VREF_GRD)		return AC_PINCTL_VREF_GRD;	return 0;}static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type){	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);}static int stac92xx_io_switch_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 stac92xx_io_switch_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;	int io_idx = kcontrol-> private_value & 0xff;	ucontrol->value.integer.value[0] = spec->io_switch[io_idx];	return 0;}static int stac92xx_io_switch_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;        hda_nid_t nid = kcontrol->private_value >> 8;	int io_idx = kcontrol-> private_value & 0xff;        unsigned short val = ucontrol->value.integer.value[0];	spec->io_switch[io_idx] = val;	if (val)		stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);	else {		unsigned int pinctl = AC_PINCTL_IN_EN;		if (io_idx) /* set VREF for mic */			pinctl |= stac92xx_get_vref(codec, nid);		stac92xx_auto_set_pinctl(codec, nid, pinctl);	}        return 1;}#define STAC_CODEC_IO_SWITCH(xname, xpval) \	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \	  .name = xname, \	  .index = 0, \          .info = stac92xx_io_switch_info, \          .get = stac92xx_io_switch_get, \          .put = stac92xx_io_switch_put, \          .private_value = xpval, \	}enum {	STAC_CTL_WIDGET_VOL,	STAC_CTL_WIDGET_MUTE,	STAC_CTL_WIDGET_IO_SWITCH,};static struct snd_kcontrol_new stac92xx_control_templates[] = {	HDA_CODEC_VOLUME(NULL, 0, 0, 0),	HDA_CODEC_MUTE(NULL, 0, 0, 0),	STAC_CODEC_IO_SWITCH(NULL, 0),};/* add dynamic controls */static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val){	struct snd_kcontrol_new *knew;	if (spec->num_kctl_used >= spec->num_kctl_alloc) {		int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;		knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */		if (! knew)			return -ENOMEM;		if (spec->kctl_alloc) {			memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);			kfree(spec->kctl_alloc);		}		spec->kctl_alloc = knew;		spec->num_kctl_alloc = num;	}	knew = &spec->kctl_alloc[spec->num_kctl_used];	*knew = stac92xx_control_templates[type];	knew->name = kstrdup(name, GFP_KERNEL);	if (! knew->name)		return -ENOMEM;	knew->private_value = val;	spec->num_kctl_used++;	return 0;}/* flag inputs as additional dynamic lineouts */static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg){	struct sigmatel_spec *spec = codec->spec;	switch (cfg->line_outs) {	case 3:		/* add line-in as side */		if (cfg->input_pins[AUTO_PIN_LINE]) {			cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];			spec->line_switch = 1;			cfg->line_outs++;		}		break;	case 2:		/* add line-in as clfe and mic as side */		if (cfg->input_pins[AUTO_PIN_LINE]) {			cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];			spec->line_switch = 1;			cfg->line_outs++;		}		if (cfg->input_pins[AUTO_PIN_MIC]) {			cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];			spec->mic_switch = 1;			cfg->line_outs++;		}		break;	case 1:		/* add line-in as surr and mic as clfe */		if (cfg->input_pins[AUTO_PIN_LINE]) {			cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];			spec->line_switch = 1;			cfg->line_outs++;		}		if (cfg->input_pins[AUTO_PIN_MIC]) {			cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];			spec->mic_switch = 1;			cfg->line_outs++;		}		break;	}	return 0;}/* * XXX The line_out pin widget connection list may not be set to the * desired DAC nid. This is the case on 927x where ports A and B can * be routed to several DACs. * * This requires an analysis of the line-out/hp pin configuration * to provide a best fit for pin/DAC configurations that are routable. * For now, 927x DAC4 is not supported and 927x DAC1 output to ports * A and B is not supported. *//* fill in the dac_nids table from the parsed pin configuration */static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec, const struct auto_pin_cfg *cfg){	struct sigmatel_spec *spec = codec->spec;	hda_nid_t nid;	int i;	/* check the pins hardwired to audio widget */	for (i = 0; i < cfg->line_outs; i++) {		nid = cfg->line_out_pins[i];		spec->multiout.dac_nids[i] = snd_hda_codec_read(codec, nid, 0,					AC_VERB_GET_CONNECT_LIST, 0) & 0xff;	}	spec->multiout.num_dacs = cfg->line_outs;	return 0;}/* add playback controls from the parsed DAC table */static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec, const struct auto_pin_cfg *cfg){	char name[32];	static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };	hda_nid_t nid;	int i, err;	for (i = 0; i < cfg->line_outs; i++) {		if (!spec->multiout.dac_nids[i])			continue;		nid = spec->multiout.dac_nids[i];		if (i == 2) {			/* Center/LFE */			if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Center Playback Volume",					       HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)				return err;			if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "LFE Playback Volume",					       HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)				return err;			if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Center Playback Switch",					       HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)				return err;			if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "LFE Playback Switch",					       HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)				return err;		} else {			sprintf(name, "%s Playback Volume", chname[i]);			if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,					       HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)				return err;			sprintf(name, "%s Playback Switch", chname[i]);			if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,					       HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)				return err;		}	}	if (spec->line_switch)		if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)			return err;	if (spec->mic_switch)		if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)			return err;	return 0;}/* add playback controls for HP output */static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec, struct auto_pin_cfg *cfg){	struct sigmatel_spec *spec = codec->spec;	hda_nid_t pin = cfg->hp_pin;	hda_nid_t nid;	int i, err;	unsigned int wid_caps;	if (! pin)		return 0;	wid_caps = get_wcaps(codec, pin);	if (wid_caps & AC_WCAP_UNSOL_CAP)		spec->hp_detect = 1;	nid = snd_hda_codec_read(codec, pin, 0, AC_VERB_GET_CONNECT_LIST, 0) & 0xff;	for (i = 0; i < cfg->line_outs; i++) {		if (! spec->multiout.dac_nids[i])			continue;		if (spec->multiout.dac_nids[i] == nid)			return 0;	}	spec->multiout.hp_nid = nid;	/* control HP volume/switch on the output mixer amp */	if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Headphone Playback Volume",					HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)		return err;	if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Headphone Playback Switch",					HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)		return err;	return 0;}/* create playback/capture controls for input pins */static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg){	struct sigmatel_spec *spec = codec->spec;	struct hda_input_mux *imux = &spec->private_imux;	hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];	int i, j, k;	for (i = 0; i < AUTO_PIN_LAST; i++) {		int index = -1;		if (cfg->input_pins[i]) {			imux->items[imux->num_items].label = auto_pin_cfg_labels[i];			for (j=0; j<spec->num_muxes; j++) {				int num_cons = snd_hda_get_connections(codec, spec->mux_nids[j], con_lst, HDA_MAX_NUM_INPUTS);				for (k=0; k<num_cons; k++)					if (con_lst[k] == cfg->input_pins[i]) {						index = k;					 	break;					}				if (index >= 0)					break;			}			imux->items[imux->num_items].index = index;			imux->num_items++;		}	}	return 0;}static void stac92xx_auto_init_multi_out(struct hda_codec *codec){	struct sigmatel_spec *spec = codec->spec;	int i;	for (i = 0; i < spec->autocfg.line_outs; i++) {		hda_nid_t nid = spec->autocfg.line_out_pins[i];		stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);	}}static void stac92xx_auto_init_hp_out(struct hda_codec *codec){	struct sigmatel_spec *spec = codec->spec;	hda_nid_t pin;	pin = spec->autocfg.hp_pin;	if (pin) /* connect to front */		stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);}static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in){	struct sigmatel_spec *spec = codec->spec;	int err;	if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)		return err;	if (! spec->autocfg.line_outs)		return 0; /* can't find valid pin config */	if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)		return err;	if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)		return err;	if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||	    (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||	    (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)		return err;	spec->multiout.max_channels = spec->multiout.num_dacs * 2;	if (spec->multiout.max_channels > 2)		spec->surr_switch = 1;	if (spec->autocfg.dig_out_pin)		spec->multiout.dig_out_nid = dig_out;	if (spec->autocfg.dig_in_pin)		spec->dig_in_nid = dig_in;	if (spec->kctl_alloc)		spec->mixers[spec->num_mixers++] = spec->kctl_alloc;	spec->input_mux = &spec->private_imux;	return 1;}/* add playback controls for HP output */static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,					struct auto_pin_cfg *cfg){	struct sigmatel_spec *spec = codec->spec;	hda_nid_t pin = cfg->hp_pin;	unsigned int wid_caps;	if (! pin)		return 0;	wid_caps = get_wcaps(codec, pin);	if (wid_caps & AC_WCAP_UNSOL_CAP)		spec->hp_detect = 1;	return 0;}static int stac9200_parse_auto_config(struct hda_codec *codec){	struct sigmatel_spec *spec = codec->spec;

⌨️ 快捷键说明

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