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

📄 ca0106_mixer.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
		emu->spdif_bits[idx] = val;	}        return change;}static int snd_ca0106_volume_info(struct snd_kcontrol *kcontrol,				  struct snd_ctl_elem_info *uinfo){        uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;        uinfo->count = 2;        uinfo->value.integer.min = 0;        uinfo->value.integer.max = 255;        return 0;}static int snd_ca0106_volume_get(struct snd_kcontrol *kcontrol,				 struct snd_ctl_elem_value *ucontrol){        struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);        unsigned int value;	int channel_id, reg;	channel_id = (kcontrol->private_value >> 8) & 0xff;	reg = kcontrol->private_value & 0xff;        value = snd_ca0106_ptr_read(emu, reg, channel_id);        ucontrol->value.integer.value[0] = 0xff - ((value >> 24) & 0xff); /* Left */        ucontrol->value.integer.value[1] = 0xff - ((value >> 16) & 0xff); /* Right */        return 0;}static int snd_ca0106_volume_put(struct snd_kcontrol *kcontrol,				 struct snd_ctl_elem_value *ucontrol){        struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);        unsigned int oval, nval;	int channel_id, reg;	channel_id = (kcontrol->private_value >> 8) & 0xff;	reg = kcontrol->private_value & 0xff;	oval = snd_ca0106_ptr_read(emu, reg, channel_id);	nval = ((0xff - ucontrol->value.integer.value[0]) << 24) |		((0xff - ucontrol->value.integer.value[1]) << 16);        nval |= ((0xff - ucontrol->value.integer.value[0]) << 8) |		((0xff - ucontrol->value.integer.value[1]) );	if (oval == nval)		return 0;	snd_ca0106_ptr_write(emu, reg, channel_id, nval);	return 1;}static int snd_ca0106_i2c_volume_info(struct snd_kcontrol *kcontrol,				  struct snd_ctl_elem_info *uinfo){        uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;        uinfo->count = 2;        uinfo->value.integer.min = 0;        uinfo->value.integer.max = 255;        return 0;}static int snd_ca0106_i2c_volume_get(struct snd_kcontrol *kcontrol,				 struct snd_ctl_elem_value *ucontrol){        struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);	int source_id;	source_id = kcontrol->private_value;        ucontrol->value.integer.value[0] = emu->i2c_capture_volume[source_id][0];        ucontrol->value.integer.value[1] = emu->i2c_capture_volume[source_id][1];        return 0;}static int snd_ca0106_i2c_volume_put(struct snd_kcontrol *kcontrol,				 struct snd_ctl_elem_value *ucontrol){        struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);        unsigned int ogain;        unsigned int ngain;	int source_id;	int change = 0;	source_id = kcontrol->private_value;	ogain = emu->i2c_capture_volume[source_id][0]; /* Left */	ngain = ucontrol->value.integer.value[0];	if (ngain > 0xff)		return -EINVAL;	if (ogain != ngain) {		if (emu->i2c_capture_source == source_id)			snd_ca0106_i2c_write(emu, ADC_ATTEN_ADCL, ((ngain) & 0xff) );		emu->i2c_capture_volume[source_id][0] = ucontrol->value.integer.value[0];		change = 1;	}	ogain = emu->i2c_capture_volume[source_id][1]; /* Right */	ngain = ucontrol->value.integer.value[1];	if (ngain > 0xff)		return -EINVAL;	if (ogain != ngain) {		if (emu->i2c_capture_source == source_id)			snd_ca0106_i2c_write(emu, ADC_ATTEN_ADCR, ((ngain) & 0xff));		emu->i2c_capture_volume[source_id][1] = ucontrol->value.integer.value[1];		change = 1;	}	return change;}#define spi_mute_info	snd_ctl_boolean_mono_infostatic int spi_mute_get(struct snd_kcontrol *kcontrol,			struct snd_ctl_elem_value *ucontrol){	struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);	unsigned int reg = kcontrol->private_value >> SPI_REG_SHIFT;	unsigned int bit = kcontrol->private_value & SPI_REG_MASK;	ucontrol->value.integer.value[0] = !(emu->spi_dac_reg[reg] & bit);	return 0;}static int spi_mute_put(struct snd_kcontrol *kcontrol,			struct snd_ctl_elem_value *ucontrol){	struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);	unsigned int reg = kcontrol->private_value >> SPI_REG_SHIFT;	unsigned int bit = kcontrol->private_value & SPI_REG_MASK;	int ret;	ret = emu->spi_dac_reg[reg] & bit;	if (ucontrol->value.integer.value[0]) {		if (!ret)	/* bit already cleared, do nothing */			return 0;		emu->spi_dac_reg[reg] &= ~bit;	} else {		if (ret)	/* bit already set, do nothing */			return 0;		emu->spi_dac_reg[reg] |= bit;	}	ret = snd_ca0106_spi_write(emu, emu->spi_dac_reg[reg]);	return ret ? -EINVAL : 1;}#define CA_VOLUME(xname,chid,reg) \{								\	.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,	\	.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |		\	          SNDRV_CTL_ELEM_ACCESS_TLV_READ,		\	.info =	 snd_ca0106_volume_info,			\	.get =   snd_ca0106_volume_get,				\	.put =   snd_ca0106_volume_put,				\	.tlv = { .p = snd_ca0106_db_scale1 },			\	.private_value = ((chid) << 8) | (reg)			\}static struct snd_kcontrol_new snd_ca0106_volume_ctls[] __devinitdata = {	CA_VOLUME("Analog Front Playback Volume",		  CONTROL_FRONT_CHANNEL, PLAYBACK_VOLUME2),        CA_VOLUME("Analog Rear Playback Volume",		  CONTROL_REAR_CHANNEL, PLAYBACK_VOLUME2),	CA_VOLUME("Analog Center/LFE Playback Volume",		  CONTROL_CENTER_LFE_CHANNEL, PLAYBACK_VOLUME2),        CA_VOLUME("Analog Side Playback Volume",		  CONTROL_UNKNOWN_CHANNEL, PLAYBACK_VOLUME2),        CA_VOLUME("IEC958 Front Playback Volume",		  CONTROL_FRONT_CHANNEL, PLAYBACK_VOLUME1),	CA_VOLUME("IEC958 Rear Playback Volume",		  CONTROL_REAR_CHANNEL, PLAYBACK_VOLUME1),	CA_VOLUME("IEC958 Center/LFE Playback Volume",		  CONTROL_CENTER_LFE_CHANNEL, PLAYBACK_VOLUME1),	CA_VOLUME("IEC958 Unknown Playback Volume",		  CONTROL_UNKNOWN_CHANNEL, PLAYBACK_VOLUME1),        CA_VOLUME("CAPTURE feedback Playback Volume",		  1, CAPTURE_CONTROL),	{		.access =	SNDRV_CTL_ELEM_ACCESS_READ,		.iface =        SNDRV_CTL_ELEM_IFACE_PCM,		.name =         SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),		.count =	4,		.info =         snd_ca0106_spdif_info,		.get =          snd_ca0106_spdif_get_mask	},	{		.iface =	SNDRV_CTL_ELEM_IFACE_MIXER,		.name =		"IEC958 Playback Switch",		.info =		snd_ca0106_shared_spdif_info,		.get =		snd_ca0106_shared_spdif_get,		.put =		snd_ca0106_shared_spdif_put	},	{		.iface =	SNDRV_CTL_ELEM_IFACE_MIXER,		.name =		"Digital Source Capture Enum",		.info =		snd_ca0106_capture_source_info,		.get =		snd_ca0106_capture_source_get,		.put =		snd_ca0106_capture_source_put	},	{		.iface =	SNDRV_CTL_ELEM_IFACE_MIXER,		.name =		"Analog Source Capture Enum",		.info =		snd_ca0106_i2c_capture_source_info,		.get =		snd_ca0106_i2c_capture_source_get,		.put =		snd_ca0106_i2c_capture_source_put	},	{		.iface =	SNDRV_CTL_ELEM_IFACE_PCM,		.name =         SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),		.count =	4,		.info =         snd_ca0106_spdif_info,		.get =          snd_ca0106_spdif_get,		.put =          snd_ca0106_spdif_put	},};#define I2C_VOLUME(xname,chid) \{								\	.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,	\	.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |		\	          SNDRV_CTL_ELEM_ACCESS_TLV_READ,		\	.info =  snd_ca0106_i2c_volume_info,			\	.get =   snd_ca0106_i2c_volume_get,			\	.put =   snd_ca0106_i2c_volume_put,			\	.tlv = { .p = snd_ca0106_db_scale2 },			\	.private_value = chid					\}static struct snd_kcontrol_new snd_ca0106_volume_i2c_adc_ctls[] __devinitdata = {        I2C_VOLUME("Phone Capture Volume", 0),        I2C_VOLUME("Mic Capture Volume", 1),        I2C_VOLUME("Line in Capture Volume", 2),        I2C_VOLUME("Aux Capture Volume", 3),};#define SPI_SWITCH(xname,reg,bit) \{								\	.iface	= SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,	\	.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,		\	.info	= spi_mute_info,				\	.get	= spi_mute_get,					\	.put	= spi_mute_put,					\	.private_value = (reg<<SPI_REG_SHIFT) | (bit)		\}static struct snd_kcontrol_new snd_ca0106_volume_spi_dac_ctls[]__devinitdata = {	SPI_SWITCH("Analog Front Playback Switch",		   SPI_DMUTE4_REG, SPI_DMUTE4_BIT),	SPI_SWITCH("Analog Rear Playback Switch",		   SPI_DMUTE0_REG, SPI_DMUTE0_BIT),	SPI_SWITCH("Analog Center/LFE Playback Switch",		   SPI_DMUTE2_REG, SPI_DMUTE2_BIT),	SPI_SWITCH("Analog Side Playback Switch",		   SPI_DMUTE1_REG, SPI_DMUTE1_BIT),};static int __devinit remove_ctl(struct snd_card *card, const char *name){	struct snd_ctl_elem_id id;	memset(&id, 0, sizeof(id));	strcpy(id.name, name);	id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;	return snd_ctl_remove_id(card, &id);}static struct snd_kcontrol __devinit *ctl_find(struct snd_card *card, const char *name){	struct snd_ctl_elem_id sid;	memset(&sid, 0, sizeof(sid));	/* FIXME: strcpy is bad. */	strcpy(sid.name, name);	sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER;	return snd_ctl_find_id(card, &sid);}static int __devinit rename_ctl(struct snd_card *card, const char *src, const char *dst){	struct snd_kcontrol *kctl = ctl_find(card, src);	if (kctl) {		strcpy(kctl->id.name, dst);		return 0;	}	return -ENOENT;}#define ADD_CTLS(emu, ctls)						\	do {								\		int i, err;						\		for (i = 0; i < ARRAY_SIZE(ctls); i++) {		\			err = snd_ctl_add(card, snd_ctl_new1(&ctls[i], emu)); \			if (err < 0)					\				return err;				\		}							\	} while (0)int __devinit snd_ca0106_mixer(struct snd_ca0106 *emu){	int err;        struct snd_card *card = emu->card;	char **c;	static char *ca0106_remove_ctls[] = {		"Master Mono Playback Switch",		"Master Mono Playback Volume",		"3D Control - Switch",		"3D Control Sigmatel - Depth",		"PCM Playback Switch",		"PCM Playback Volume",		"CD Playback Switch",		"CD Playback Volume",		"Phone Playback Switch",		"Phone Playback Volume",		"Video Playback Switch",		"Video Playback Volume",		"PC Speaker Playback Switch",		"PC Speaker Playback Volume",		"Mono Output Select",		"Capture Source",		"Capture Switch",		"Capture Volume",		"External Amplifier",		"Sigmatel 4-Speaker Stereo Playback Switch",		"Sigmatel Surround Phase Inversion Playback ",		NULL	};	static char *ca0106_rename_ctls[] = {		"Master Playback Switch", "Capture Switch",		"Master Playback Volume", "Capture Volume",		"Line Playback Switch", "AC97 Line Capture Switch",		"Line Playback Volume", "AC97 Line Capture Volume",		"Aux Playback Switch", "AC97 Aux Capture Switch",		"Aux Playback Volume", "AC97 Aux Capture Volume",		"Mic Playback Switch", "AC97 Mic Capture Switch",		"Mic Playback Volume", "AC97 Mic Capture Volume",		"Mic Select", "AC97 Mic Select",		"Mic Boost (+20dB)", "AC97 Mic Boost (+20dB)",		NULL	};#if 1	for (c = ca0106_remove_ctls; *c; c++)		remove_ctl(card, *c);	for (c = ca0106_rename_ctls; *c; c += 2)		rename_ctl(card, c[0], c[1]);#endif	ADD_CTLS(emu, snd_ca0106_volume_ctls);	if (emu->details->i2c_adc == 1) {		ADD_CTLS(emu, snd_ca0106_volume_i2c_adc_ctls);		if (emu->details->gpio_type == 1)			err = snd_ctl_add(card, snd_ctl_new1(&snd_ca0106_capture_mic_line_in, emu));		else  /* gpio_type == 2 */			err = snd_ctl_add(card, snd_ctl_new1(&snd_ca0106_capture_line_in_side_out, emu));		if (err < 0)			return err;	}	if (emu->details->spi_dac == 1)		ADD_CTLS(emu, snd_ca0106_volume_spi_dac_ctls);        return 0;}

⌨️ 快捷键说明

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