📄 ak4531_codec.c
字号:
/* * 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");#define chip_t ak4531_tstatic void snd_ak4531_proc_init(snd_card_t * card, ak4531_t * ak4531);static void snd_ak4531_proc_done(ak4531_t * ak4531);/* * */ #if 0static void snd_ak4531_dump(ak4531_t *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(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t * 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(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){ ak4531_t *ak4531 = snd_kcontrol_chip(kcontrol); unsigned long flags; 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; spin_lock_irqsave(&ak4531->reg_lock, flags); val = (ak4531->regs[reg] >> shift) & mask; spin_unlock_irqrestore(&ak4531->reg_lock, flags); if (invert) { val = mask - val; } ucontrol->value.integer.value[0] = val; return 0;} static int snd_ak4531_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){ ak4531_t *ak4531 = snd_kcontrol_chip(kcontrol); unsigned long flags; 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; spin_lock_irqsave(&ak4531->reg_lock, flags); val = (ak4531->regs[reg] & ~(mask << shift)) | val; change = val != ak4531->regs[reg]; ak4531->write(ak4531, reg, ak4531->regs[reg] = val); spin_unlock_irqrestore(&ak4531->reg_lock, flags); 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(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t * 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(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){ ak4531_t *ak4531 = snd_kcontrol_chip(kcontrol); unsigned long flags; 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; spin_lock_irqsave(&ak4531->reg_lock, flags); left = (ak4531->regs[left_reg] >> left_shift) & mask; right = (ak4531->regs[right_reg] >> right_shift) & mask; spin_unlock_irqrestore(&ak4531->reg_lock, flags); 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(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){ ak4531_t *ak4531 = snd_kcontrol_chip(kcontrol); unsigned long flags; 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; spin_lock_irqsave(&ak4531->reg_lock, flags); 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); } spin_unlock_irqrestore(&ak4531->reg_lock, flags); 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(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t * 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(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){ ak4531_t *ak4531 = snd_kcontrol_chip(kcontrol); unsigned long flags; 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; spin_lock_irqsave(&ak4531->reg_lock, flags); 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; spin_unlock_irqrestore(&ak4531->reg_lock, flags); return 0;} static int snd_ak4531_put_input_sw(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){ ak4531_t *ak4531 = snd_kcontrol_chip(kcontrol); unsigned long flags;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -