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

📄 ak4531_codec.c

📁 linux2.6.16版本
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *  Copyright (c) by Jaroslav Kysela <perex@suse.cz> *  Universal routines for AK4531 codec * * *   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/slab.h>#include <sound/core.h>#include <sound/ak4531_codec.h>MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");MODULE_DESCRIPTION("Universal routines for AK4531 codec");MODULE_LICENSE("GPL");#ifdef CONFIG_PROC_FSstatic void snd_ak4531_proc_init(struct snd_card *card, struct snd_ak4531 *ak4531);#else#define snd_ak4531_proc_init(card,ak)#endif/* * */ #if 0static void snd_ak4531_dump(struct snd_ak4531 *ak4531){	int idx;		for (idx = 0; idx < 0x19; idx++)		printk("ak4531 0x%x: 0x%x\n", idx, ak4531->regs[idx]);}#endif/* * */#define AK4531_SINGLE(xname, xindex, reg, shift, mask, invert) \{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \  .info = snd_ak4531_info_single, \  .get = snd_ak4531_get_single, .put = snd_ak4531_put_single, \  .private_value = reg | (shift << 16) | (mask << 24) | (invert << 22) }static int snd_ak4531_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo){	int mask = (kcontrol->private_value >> 24) & 0xff;	uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;	uinfo->count = 1;	uinfo->value.integer.min = 0;	uinfo->value.integer.max = mask;	return 0;} static int snd_ak4531_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){	struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol);	int reg = kcontrol->private_value & 0xff;	int shift = (kcontrol->private_value >> 16) & 0x07;	int mask = (kcontrol->private_value >> 24) & 0xff;	int invert = (kcontrol->private_value >> 22) & 1;	int val;	down(&ak4531->reg_mutex);	val = (ak4531->regs[reg] >> shift) & mask;	up(&ak4531->reg_mutex);	if (invert) {		val = mask - val;	}	ucontrol->value.integer.value[0] = val;	return 0;}static int snd_ak4531_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){	struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol);	int reg = kcontrol->private_value & 0xff;	int shift = (kcontrol->private_value >> 16) & 0x07;	int mask = (kcontrol->private_value >> 24) & 0xff;	int invert = (kcontrol->private_value >> 22) & 1;	int change;	int val;	val = ucontrol->value.integer.value[0] & mask;	if (invert) {		val = mask - val;	}	val <<= shift;	down(&ak4531->reg_mutex);	val = (ak4531->regs[reg] & ~(mask << shift)) | val;	change = val != ak4531->regs[reg];	ak4531->write(ak4531, reg, ak4531->regs[reg] = val);	up(&ak4531->reg_mutex);	return change;}#define AK4531_DOUBLE(xname, xindex, left_reg, right_reg, left_shift, right_shift, mask, invert) \{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \  .info = snd_ak4531_info_double, \  .get = snd_ak4531_get_double, .put = snd_ak4531_put_double, \  .private_value = left_reg | (right_reg << 8) | (left_shift << 16) | (right_shift << 19) | (mask << 24) | (invert << 22) }static int snd_ak4531_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo){	int mask = (kcontrol->private_value >> 24) & 0xff;	uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;	uinfo->count = 2;	uinfo->value.integer.min = 0;	uinfo->value.integer.max = mask;	return 0;} static int snd_ak4531_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){	struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol);	int left_reg = kcontrol->private_value & 0xff;	int right_reg = (kcontrol->private_value >> 8) & 0xff;	int left_shift = (kcontrol->private_value >> 16) & 0x07;	int right_shift = (kcontrol->private_value >> 19) & 0x07;	int mask = (kcontrol->private_value >> 24) & 0xff;	int invert = (kcontrol->private_value >> 22) & 1;	int left, right;	down(&ak4531->reg_mutex);	left = (ak4531->regs[left_reg] >> left_shift) & mask;	right = (ak4531->regs[right_reg] >> right_shift) & mask;	up(&ak4531->reg_mutex);	if (invert) {		left = mask - left;		right = mask - right;	}	ucontrol->value.integer.value[0] = left;	ucontrol->value.integer.value[1] = right;	return 0;}static int snd_ak4531_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){	struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol);	int left_reg = kcontrol->private_value & 0xff;	int right_reg = (kcontrol->private_value >> 8) & 0xff;	int left_shift = (kcontrol->private_value >> 16) & 0x07;	int right_shift = (kcontrol->private_value >> 19) & 0x07;	int mask = (kcontrol->private_value >> 24) & 0xff;	int invert = (kcontrol->private_value >> 22) & 1;	int change;	int left, right;	left = ucontrol->value.integer.value[0] & mask;	right = ucontrol->value.integer.value[1] & mask;	if (invert) {		left = mask - left;		right = mask - right;	}	left <<= left_shift;	right <<= right_shift;	down(&ak4531->reg_mutex);	if (left_reg == right_reg) {		left = (ak4531->regs[left_reg] & ~((mask << left_shift) | (mask << right_shift))) | left | right;		change = left != ak4531->regs[left_reg];		ak4531->write(ak4531, left_reg, ak4531->regs[left_reg] = left);	} else {		left = (ak4531->regs[left_reg] & ~(mask << left_shift)) | left;		right = (ak4531->regs[right_reg] & ~(mask << right_shift)) | right;		change = left != ak4531->regs[left_reg] || right != ak4531->regs[right_reg];		ak4531->write(ak4531, left_reg, ak4531->regs[left_reg] = left);		ak4531->write(ak4531, right_reg, ak4531->regs[right_reg] = right);	}	up(&ak4531->reg_mutex);	return change;}#define AK4531_INPUT_SW(xname, xindex, reg1, reg2, left_shift, right_shift) \{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \  .info = snd_ak4531_info_input_sw, \  .get = snd_ak4531_get_input_sw, .put = snd_ak4531_put_input_sw, \  .private_value = reg1 | (reg2 << 8) | (left_shift << 16) | (right_shift << 24) }static int snd_ak4531_info_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo){	uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;	uinfo->count = 4;	uinfo->value.integer.min = 0;	uinfo->value.integer.max = 1;	return 0;} static int snd_ak4531_get_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){	struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol);	int reg1 = kcontrol->private_value & 0xff;	int reg2 = (kcontrol->private_value >> 8) & 0xff;	int left_shift = (kcontrol->private_value >> 16) & 0x0f;	int right_shift = (kcontrol->private_value >> 24) & 0x0f;	down(&ak4531->reg_mutex);	ucontrol->value.integer.value[0] = (ak4531->regs[reg1] >> left_shift) & 1;	ucontrol->value.integer.value[1] = (ak4531->regs[reg2] >> left_shift) & 1;	ucontrol->value.integer.value[2] = (ak4531->regs[reg1] >> right_shift) & 1;	ucontrol->value.integer.value[3] = (ak4531->regs[reg2] >> right_shift) & 1;	up(&ak4531->reg_mutex);	return 0;}static int snd_ak4531_put_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){	struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol);	int reg1 = kcontrol->private_value & 0xff;	int reg2 = (kcontrol->private_value >> 8) & 0xff;	int left_shift = (kcontrol->private_value >> 16) & 0x0f;	int right_shift = (kcontrol->private_value >> 24) & 0x0f;	int change;	int val1, val2;	down(&ak4531->reg_mutex);	val1 = ak4531->regs[reg1] & ~((1 << left_shift) | (1 << right_shift));	val2 = ak4531->regs[reg2] & ~((1 << left_shift) | (1 << right_shift));	val1 |= (ucontrol->value.integer.value[0] & 1) << left_shift;

⌨️ 快捷键说明

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