📄 ak4xxx-adda.c
字号:
"44.1kHz", "Off", "48kHz", "32kHz", }; uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; uinfo->count = 1; uinfo->value.enumerated.items = 4; if (uinfo->value.enumerated.item >= 4) uinfo->value.enumerated.item = 3; strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); return 0;}static int snd_akm4xxx_deemphasis_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol); int chip = AK_GET_CHIP(kcontrol->private_value); int addr = AK_GET_ADDR(kcontrol->private_value); int shift = AK_GET_SHIFT(kcontrol->private_value); ucontrol->value.enumerated.item[0] = (snd_akm4xxx_get(ak, chip, addr) >> shift) & 3; return 0;}static int snd_akm4xxx_deemphasis_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol); int chip = AK_GET_CHIP(kcontrol->private_value); int addr = AK_GET_ADDR(kcontrol->private_value); int shift = AK_GET_SHIFT(kcontrol->private_value); unsigned char nval = ucontrol->value.enumerated.item[0] & 3; int change; nval = (nval << shift) | (snd_akm4xxx_get(ak, chip, addr) & ~(3 << shift)); change = snd_akm4xxx_get(ak, chip, addr) != nval; if (change) snd_akm4xxx_write(ak, chip, addr, nval); return change;}#define ak4xxx_switch_info snd_ctl_boolean_mono_infostatic int ak4xxx_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol); int chip = AK_GET_CHIP(kcontrol->private_value); int addr = AK_GET_ADDR(kcontrol->private_value); int shift = AK_GET_SHIFT(kcontrol->private_value); int invert = AK_GET_INVERT(kcontrol->private_value); /* we observe the (1<<shift) bit only */ unsigned char val = snd_akm4xxx_get(ak, chip, addr) & (1<<shift); if (invert) val = ! val; ucontrol->value.integer.value[0] = (val & (1<<shift)) != 0; return 0;}static int ak4xxx_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol); int chip = AK_GET_CHIP(kcontrol->private_value); int addr = AK_GET_ADDR(kcontrol->private_value); int shift = AK_GET_SHIFT(kcontrol->private_value); int invert = AK_GET_INVERT(kcontrol->private_value); long flag = ucontrol->value.integer.value[0]; unsigned char val, oval; int change; if (invert) flag = ! flag; oval = snd_akm4xxx_get(ak, chip, addr); if (flag) val = oval | (1<<shift); else val = oval & ~(1<<shift); change = (oval != val); if (change) snd_akm4xxx_write(ak, chip, addr, val); return change;}#define AK5365_NUM_INPUTS 5static int ak4xxx_capture_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo){ struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol); int mixer_ch = AK_GET_SHIFT(kcontrol->private_value); const char **input_names; int num_names, idx; input_names = ak->adc_info[mixer_ch].input_names; num_names = 0; while (num_names < AK5365_NUM_INPUTS && input_names[num_names]) ++num_names; uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; uinfo->count = 1; uinfo->value.enumerated.items = num_names; idx = uinfo->value.enumerated.item; if (idx >= num_names) return -EINVAL; strncpy(uinfo->value.enumerated.name, input_names[idx], sizeof(uinfo->value.enumerated.name)); return 0;}static int ak4xxx_capture_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol); int chip = AK_GET_CHIP(kcontrol->private_value); int addr = AK_GET_ADDR(kcontrol->private_value); int mask = AK_GET_MASK(kcontrol->private_value); unsigned char val; val = snd_akm4xxx_get(ak, chip, addr) & mask; ucontrol->value.enumerated.item[0] = val; return 0;}static int ak4xxx_capture_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol); int chip = AK_GET_CHIP(kcontrol->private_value); int addr = AK_GET_ADDR(kcontrol->private_value); int mask = AK_GET_MASK(kcontrol->private_value); unsigned char oval, val; oval = snd_akm4xxx_get(ak, chip, addr); val = oval & ~mask; val |= ucontrol->value.enumerated.item[0] & mask; if (val != oval) { snd_akm4xxx_write(ak, chip, addr, val); return 1; } return 0;}/* * build AK4xxx controls */static int build_dac_controls(struct snd_akm4xxx *ak){ int idx, err, mixer_ch, num_stereo; struct snd_kcontrol_new knew; mixer_ch = 0; for (idx = 0; idx < ak->num_dacs; ) { /* mute control for Revolution 7.1 - AK4381 */ if (ak->type == SND_AK4381 && ak->dac_info[mixer_ch].switch_name) { memset(&knew, 0, sizeof(knew)); knew.iface = SNDRV_CTL_ELEM_IFACE_MIXER; knew.count = 1; knew.access = SNDRV_CTL_ELEM_ACCESS_READWRITE; knew.name = ak->dac_info[mixer_ch].switch_name; knew.info = ak4xxx_switch_info; knew.get = ak4xxx_switch_get; knew.put = ak4xxx_switch_put; knew.access = 0; /* register 1, bit 0 (SMUTE): 0 = normal operation, 1 = mute */ knew.private_value = AK_COMPOSE(idx/2, 1, 0, 0) | AK_INVERT; err = snd_ctl_add(ak->card, snd_ctl_new1(&knew, ak)); if (err < 0) return err; } memset(&knew, 0, sizeof(knew)); if (! ak->dac_info || ! ak->dac_info[mixer_ch].name) { knew.name = "DAC Volume"; knew.index = mixer_ch + ak->idx_offset * 2; num_stereo = 1; } else { knew.name = ak->dac_info[mixer_ch].name; num_stereo = ak->dac_info[mixer_ch].num_channels; } knew.iface = SNDRV_CTL_ELEM_IFACE_MIXER; knew.count = 1; knew.access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ; if (num_stereo == 2) { knew.info = snd_akm4xxx_stereo_volume_info; knew.get = snd_akm4xxx_stereo_volume_get; knew.put = snd_akm4xxx_stereo_volume_put; } else { knew.info = snd_akm4xxx_volume_info; knew.get = snd_akm4xxx_volume_get; knew.put = snd_akm4xxx_volume_put; } switch (ak->type) { case SND_AK4524: /* register 6 & 7 */ knew.private_value = AK_COMPOSE(idx/2, (idx%2) + 6, 0, 127) | AK_VOL_CVT; knew.tlv.p = db_scale_vol_datt; break; case SND_AK4528: /* register 4 & 5 */ knew.private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0, 127) | AK_VOL_CVT; knew.tlv.p = db_scale_vol_datt; break; case SND_AK4529: { /* registers 2-7 and b,c */ int val = idx < 6 ? idx + 2 : (idx - 6) + 0xb; knew.private_value = AK_COMPOSE(0, val, 0, 255) | AK_INVERT; knew.tlv.p = db_scale_8bit; break; } case SND_AK4355: /* register 4-9, chip #0 only */ knew.private_value = AK_COMPOSE(0, idx + 4, 0, 255); knew.tlv.p = db_scale_8bit; break; case SND_AK4358: { /* register 4-9 and 11-12, chip #0 only */ int addr = idx < 6 ? idx + 4 : idx + 5; knew.private_value = AK_COMPOSE(0, addr, 0, 127) | AK_NEEDSMSB; knew.tlv.p = db_scale_7bit; break; } case SND_AK4381: /* register 3 & 4 */ knew.private_value = AK_COMPOSE(idx/2, (idx%2) + 3, 0, 255); knew.tlv.p = db_scale_linear; break; default: return -EINVAL; } err = snd_ctl_add(ak->card, snd_ctl_new1(&knew, ak)); if (err < 0) return err; idx += num_stereo; mixer_ch++; } return 0;}static int build_adc_controls(struct snd_akm4xxx *ak){ int idx, err, mixer_ch, num_stereo; struct snd_kcontrol_new knew; mixer_ch = 0; for (idx = 0; idx < ak->num_adcs;) { memset(&knew, 0, sizeof(knew)); if (! ak->adc_info || ! ak->adc_info[mixer_ch].name) { knew.name = "ADC Volume"; knew.index = mixer_ch + ak->idx_offset * 2; num_stereo = 1; } else { knew.name = ak->adc_info[mixer_ch].name; num_stereo = ak->adc_info[mixer_ch].num_channels; } knew.iface = SNDRV_CTL_ELEM_IFACE_MIXER; knew.count = 1; knew.access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ; if (num_stereo == 2) { knew.info = snd_akm4xxx_stereo_volume_info; knew.get = snd_akm4xxx_stereo_volume_get; knew.put = snd_akm4xxx_stereo_volume_put; } else { knew.info = snd_akm4xxx_volume_info; knew.get = snd_akm4xxx_volume_get; knew.put = snd_akm4xxx_volume_put; } /* register 4 & 5 */ if (ak->type == SND_AK5365) knew.private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0, 151) | AK_VOL_CVT | AK_IPGA; else knew.private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0, 163) | AK_VOL_CVT | AK_IPGA; knew.tlv.p = db_scale_vol_datt; err = snd_ctl_add(ak->card, snd_ctl_new1(&knew, ak)); if (err < 0) return err; if (ak->type == SND_AK5365 && (idx % 2) == 0) { if (! ak->adc_info || ! ak->adc_info[mixer_ch].switch_name) { knew.name = "Capture Switch"; knew.index = mixer_ch + ak->idx_offset * 2; } else knew.name = ak->adc_info[mixer_ch].switch_name; knew.info = ak4xxx_switch_info; knew.get = ak4xxx_switch_get; knew.put = ak4xxx_switch_put; knew.access = 0; /* register 2, bit 0 (SMUTE): 0 = normal operation, 1 = mute */ knew.private_value = AK_COMPOSE(idx/2, 2, 0, 0) | AK_INVERT; err = snd_ctl_add(ak->card, snd_ctl_new1(&knew, ak)); if (err < 0) return err; memset(&knew, 0, sizeof(knew)); knew.name = ak->adc_info[mixer_ch].selector_name; if (!knew.name) { knew.name = "Capture Channel"; knew.index = mixer_ch + ak->idx_offset * 2; } knew.iface = SNDRV_CTL_ELEM_IFACE_MIXER; knew.info = ak4xxx_capture_source_info; knew.get = ak4xxx_capture_source_get; knew.put = ak4xxx_capture_source_put; knew.access = 0; /* input selector control: reg. 1, bits 0-2. * mis-use 'shift' to pass mixer_ch */ knew.private_value = AK_COMPOSE(idx/2, 1, mixer_ch, 0x07); err = snd_ctl_add(ak->card, snd_ctl_new1(&knew, ak)); if (err < 0) return err; } idx += num_stereo; mixer_ch++; } return 0;}static int build_deemphasis(struct snd_akm4xxx *ak, int num_emphs){ int idx, err; struct snd_kcontrol_new knew; for (idx = 0; idx < num_emphs; idx++) { memset(&knew, 0, sizeof(knew)); knew.name = "Deemphasis"; knew.index = idx + ak->idx_offset; knew.iface = SNDRV_CTL_ELEM_IFACE_MIXER; knew.count = 1; knew.info = snd_akm4xxx_deemphasis_info; knew.get = snd_akm4xxx_deemphasis_get; knew.put = snd_akm4xxx_deemphasis_put; switch (ak->type) { case SND_AK4524: case SND_AK4528: /* register 3 */ knew.private_value = AK_COMPOSE(idx, 3, 0, 0); break; case SND_AK4529: { int shift = idx == 3 ? 6 : (2 - idx) * 2; /* register 8 with shift */ knew.private_value = AK_COMPOSE(0, 8, shift, 0); break; } case SND_AK4355: case SND_AK4358: knew.private_value = AK_COMPOSE(idx, 3, 0, 0); break; case SND_AK4381: knew.private_value = AK_COMPOSE(idx, 1, 1, 0); break; default: return -EINVAL; } err = snd_ctl_add(ak->card, snd_ctl_new1(&knew, ak)); if (err < 0) return err; } return 0;}int snd_akm4xxx_build_controls(struct snd_akm4xxx *ak){ int err, num_emphs; err = build_dac_controls(ak); if (err < 0) return err; err = build_adc_controls(ak); if (err < 0) return err; if (ak->type == SND_AK4355 || ak->type == SND_AK4358) num_emphs = 1; else num_emphs = ak->num_dacs / 2; err = build_deemphasis(ak, num_emphs); if (err < 0) return err; return 0;} EXPORT_SYMBOL(snd_akm4xxx_build_controls);static int __init alsa_akm4xxx_module_init(void){ return 0;} static void __exit alsa_akm4xxx_module_exit(void){} module_init(alsa_akm4xxx_module_init)module_exit(alsa_akm4xxx_module_exit)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -