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

📄 ca0106_mixer.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *  Copyright (c) 2004 James Courtier-Dutton <James@superbug.demon.co.uk> *  Driver CA0106 chips. e.g. Sound Blaster Audigy LS and Live 24bit *  Version: 0.0.18 * *  FEATURES currently supported: *    See ca0106_main.c for features. *  *  Changelog: *    Support interrupts per period. *    Removed noise from Center/LFE channel when in Analog mode. *    Rename and remove mixer controls. *  0.0.6 *    Use separate card based DMA buffer for periods table list. *  0.0.7 *    Change remove and rename ctrls into lists. *  0.0.8 *    Try to fix capture sources. *  0.0.9 *    Fix AC3 output. *    Enable S32_LE format support. *  0.0.10 *    Enable playback 48000 and 96000 rates. (Rates other that these do not work, even with "plug:front".) *  0.0.11 *    Add Model name recognition. *  0.0.12 *    Correct interrupt timing. interrupt at end of period, instead of in the middle of a playback period. *    Remove redundent "voice" handling. *  0.0.13 *    Single trigger call for multi channels. *  0.0.14 *    Set limits based on what the sound card hardware can do. *    playback periods_min=2, periods_max=8 *    capture hw constraints require period_size = n * 64 bytes. *    playback hw constraints require period_size = n * 64 bytes. *  0.0.15 *    Separated ca0106.c into separate functional .c files. *  0.0.16 *    Modified Copyright message. *  0.0.17 *    Implement Mic and Line in Capture. *  0.0.18 *    Add support for mute control on SB Live 24bit (cards w/ SPI DAC) * *  This code was initally based on code from ALSA's emu10k1x.c which is: *  Copyright (c) by Francisco Moraes <fmoraes@nc.rr.com> * *   This program 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 program 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/delay.h>#include <linux/init.h>#include <linux/interrupt.h>#include <linux/slab.h>#include <linux/moduleparam.h>#include <sound/core.h>#include <sound/initval.h>#include <sound/pcm.h>#include <sound/ac97_codec.h>#include <sound/info.h>#include <sound/tlv.h>#include <asm/io.h>#include "ca0106.h"static const DECLARE_TLV_DB_SCALE(snd_ca0106_db_scale1, -5175, 25, 1);static const DECLARE_TLV_DB_SCALE(snd_ca0106_db_scale2, -10350, 50, 1);#define snd_ca0106_shared_spdif_info	snd_ctl_boolean_mono_infostatic int snd_ca0106_shared_spdif_get(struct snd_kcontrol *kcontrol,					struct snd_ctl_elem_value *ucontrol){	struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);	ucontrol->value.integer.value[0] = emu->spdif_enable;	return 0;}static int snd_ca0106_shared_spdif_put(struct snd_kcontrol *kcontrol,					struct snd_ctl_elem_value *ucontrol){	struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);	unsigned int val;	int change = 0;	u32 mask;	val = !!ucontrol->value.integer.value[0];	change = (emu->spdif_enable != val);	if (change) {		emu->spdif_enable = val;		if (val) {			/* Digital */			snd_ca0106_ptr_write(emu, SPDIF_SELECT1, 0, 0xf);			snd_ca0106_ptr_write(emu, SPDIF_SELECT2, 0, 0x0b000000);			snd_ca0106_ptr_write(emu, CAPTURE_CONTROL, 0,				snd_ca0106_ptr_read(emu, CAPTURE_CONTROL, 0) & ~0x1000);			mask = inl(emu->port + GPIO) & ~0x101;			outl(mask, emu->port + GPIO);		} else {			/* Analog */			snd_ca0106_ptr_write(emu, SPDIF_SELECT1, 0, 0xf);			snd_ca0106_ptr_write(emu, SPDIF_SELECT2, 0, 0x000f0000);			snd_ca0106_ptr_write(emu, CAPTURE_CONTROL, 0,				snd_ca0106_ptr_read(emu, CAPTURE_CONTROL, 0) | 0x1000);			mask = inl(emu->port + GPIO) | 0x101;			outl(mask, emu->port + GPIO);		}	}        return change;}static int snd_ca0106_capture_source_info(struct snd_kcontrol *kcontrol,					  struct snd_ctl_elem_info *uinfo){	static char *texts[6] = {		"IEC958 out", "i2s mixer out", "IEC958 in", "i2s in", "AC97 in", "SRC out"	};	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;	uinfo->count = 1;	uinfo->value.enumerated.items = 6;	if (uinfo->value.enumerated.item > 5)                uinfo->value.enumerated.item = 5;	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);	return 0;}static int snd_ca0106_capture_source_get(struct snd_kcontrol *kcontrol,					struct snd_ctl_elem_value *ucontrol){	struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);	ucontrol->value.enumerated.item[0] = emu->capture_source;	return 0;}static int snd_ca0106_capture_source_put(struct snd_kcontrol *kcontrol,					struct snd_ctl_elem_value *ucontrol){	struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);	unsigned int val;	int change = 0;	u32 mask;	u32 source;	val = ucontrol->value.enumerated.item[0] ;	if (val >= 6)		return -EINVAL;	change = (emu->capture_source != val);	if (change) {		emu->capture_source = val;		source = (val << 28) | (val << 24) | (val << 20) | (val << 16);		mask = snd_ca0106_ptr_read(emu, CAPTURE_SOURCE, 0) & 0xffff;		snd_ca0106_ptr_write(emu, CAPTURE_SOURCE, 0, source | mask);	}        return change;}static int snd_ca0106_i2c_capture_source_info(struct snd_kcontrol *kcontrol,					  struct snd_ctl_elem_info *uinfo){	static char *texts[6] = {		"Phone", "Mic", "Line in", "Aux"	};	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;	uinfo->count = 1;	uinfo->value.enumerated.items = 4;	if (uinfo->value.enumerated.item > 3)                uinfo->value.enumerated.item = 3;	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);	return 0;}static int snd_ca0106_i2c_capture_source_get(struct snd_kcontrol *kcontrol,					struct snd_ctl_elem_value *ucontrol){	struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);	ucontrol->value.enumerated.item[0] = emu->i2c_capture_source;	return 0;}static int snd_ca0106_i2c_capture_source_put(struct snd_kcontrol *kcontrol,					struct snd_ctl_elem_value *ucontrol){	struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);	unsigned int source_id;	unsigned int ngain, ogain;	int change = 0;	u32 source;	/* If the capture source has changed,	 * update the capture volume from the cached value	 * for the particular source.	 */	source_id = ucontrol->value.enumerated.item[0] ;	if (source_id >= 4)		return -EINVAL;	change = (emu->i2c_capture_source != source_id);	if (change) {		snd_ca0106_i2c_write(emu, ADC_MUX, 0); /* Mute input */		ngain = emu->i2c_capture_volume[source_id][0]; /* Left */		ogain = emu->i2c_capture_volume[emu->i2c_capture_source][0]; /* Left */		if (ngain != ogain)			snd_ca0106_i2c_write(emu, ADC_ATTEN_ADCL, ((ngain) & 0xff));		ngain = emu->i2c_capture_volume[source_id][1]; /* Left */		ogain = emu->i2c_capture_volume[emu->i2c_capture_source][1]; /* Left */		if (ngain != ogain)			snd_ca0106_i2c_write(emu, ADC_ATTEN_ADCR, ((ngain) & 0xff));		source = 1 << source_id;		snd_ca0106_i2c_write(emu, ADC_MUX, source); /* Set source */		emu->i2c_capture_source = source_id;	}        return change;}static int snd_ca0106_capture_line_in_side_out_info(struct snd_kcontrol *kcontrol,					       struct snd_ctl_elem_info *uinfo){	static char *texts[2] = { "Side out", "Line in" };	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;	uinfo->count = 1;	uinfo->value.enumerated.items = 2;	if (uinfo->value.enumerated.item > 1)                uinfo->value.enumerated.item = 1;	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);	return 0;}static int snd_ca0106_capture_mic_line_in_info(struct snd_kcontrol *kcontrol,					       struct snd_ctl_elem_info *uinfo){	static char *texts[2] = { "Line in", "Mic in" };	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;	uinfo->count = 1;	uinfo->value.enumerated.items = 2;	if (uinfo->value.enumerated.item > 1)                uinfo->value.enumerated.item = 1;	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);	return 0;}static int snd_ca0106_capture_mic_line_in_get(struct snd_kcontrol *kcontrol,					struct snd_ctl_elem_value *ucontrol){	struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);	ucontrol->value.enumerated.item[0] = emu->capture_mic_line_in;	return 0;}static int snd_ca0106_capture_mic_line_in_put(struct snd_kcontrol *kcontrol,					struct snd_ctl_elem_value *ucontrol){	struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);	unsigned int val;	int change = 0;	u32 tmp;	val = ucontrol->value.enumerated.item[0] ;	if (val > 1)		return -EINVAL;	change = (emu->capture_mic_line_in != val);	if (change) {		emu->capture_mic_line_in = val;		if (val) {			//snd_ca0106_i2c_write(emu, ADC_MUX, 0); /* Mute input */			tmp = inl(emu->port+GPIO) & ~0x400;			tmp = tmp | 0x400;			outl(tmp, emu->port+GPIO);			//snd_ca0106_i2c_write(emu, ADC_MUX, ADC_MUX_MIC);		} else {			//snd_ca0106_i2c_write(emu, ADC_MUX, 0); /* Mute input */			tmp = inl(emu->port+GPIO) & ~0x400;			outl(tmp, emu->port+GPIO);			//snd_ca0106_i2c_write(emu, ADC_MUX, ADC_MUX_LINEIN);		}	}        return change;}static struct snd_kcontrol_new snd_ca0106_capture_mic_line_in __devinitdata ={	.iface =	SNDRV_CTL_ELEM_IFACE_MIXER,	.name =		"Shared Mic/Line in Capture Switch",	.info =		snd_ca0106_capture_mic_line_in_info,	.get =		snd_ca0106_capture_mic_line_in_get,	.put =		snd_ca0106_capture_mic_line_in_put};static struct snd_kcontrol_new snd_ca0106_capture_line_in_side_out __devinitdata ={	.iface =	SNDRV_CTL_ELEM_IFACE_MIXER,	.name =		"Shared Line in/Side out Capture Switch",	.info =		snd_ca0106_capture_line_in_side_out_info,	.get =		snd_ca0106_capture_mic_line_in_get,	.put =		snd_ca0106_capture_mic_line_in_put};static int snd_ca0106_spdif_info(struct snd_kcontrol *kcontrol,				 struct snd_ctl_elem_info *uinfo){	uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;	uinfo->count = 1;	return 0;}static int snd_ca0106_spdif_get(struct snd_kcontrol *kcontrol,                                 struct snd_ctl_elem_value *ucontrol){	struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);	unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);	ucontrol->value.iec958.status[0] = (emu->spdif_bits[idx] >> 0) & 0xff;	ucontrol->value.iec958.status[1] = (emu->spdif_bits[idx] >> 8) & 0xff;	ucontrol->value.iec958.status[2] = (emu->spdif_bits[idx] >> 16) & 0xff;	ucontrol->value.iec958.status[3] = (emu->spdif_bits[idx] >> 24) & 0xff;        return 0;}static int snd_ca0106_spdif_get_mask(struct snd_kcontrol *kcontrol,				      struct snd_ctl_elem_value *ucontrol){	ucontrol->value.iec958.status[0] = 0xff;	ucontrol->value.iec958.status[1] = 0xff;	ucontrol->value.iec958.status[2] = 0xff;	ucontrol->value.iec958.status[3] = 0xff;        return 0;}static int snd_ca0106_spdif_put(struct snd_kcontrol *kcontrol,                                 struct snd_ctl_elem_value *ucontrol){	struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);	unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);	int change;	unsigned int val;	val = (ucontrol->value.iec958.status[0] << 0) |	      (ucontrol->value.iec958.status[1] << 8) |	      (ucontrol->value.iec958.status[2] << 16) |	      (ucontrol->value.iec958.status[3] << 24);	change = val != emu->spdif_bits[idx];	if (change) {		snd_ca0106_ptr_write(emu, SPCS0 + idx, 0, val);

⌨️ 快捷键说明

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