📄 ak4531_codec.c
字号:
val2 |= (ucontrol->value.integer.value[1] & 1) << left_shift; val1 |= (ucontrol->value.integer.value[2] & 1) << right_shift; val2 |= (ucontrol->value.integer.value[3] & 1) << right_shift; change = val1 != ak4531->regs[reg1] || val2 != ak4531->regs[reg2]; ak4531->write(ak4531, reg1, ak4531->regs[reg1] = val1); ak4531->write(ak4531, reg2, ak4531->regs[reg2] = val2); up(&ak4531->reg_mutex); return change;}static struct snd_kcontrol_new snd_ak4531_controls[] = {AK4531_DOUBLE("Master Playback Switch", 0, AK4531_LMASTER, AK4531_RMASTER, 7, 7, 1, 1),AK4531_DOUBLE("Master Playback Volume", 0, AK4531_LMASTER, AK4531_RMASTER, 0, 0, 0x1f, 1),AK4531_SINGLE("Master Mono Playback Switch", 0, AK4531_MONO_OUT, 7, 1, 1),AK4531_SINGLE("Master Mono Playback Volume", 0, AK4531_MONO_OUT, 0, 0x07, 1),AK4531_DOUBLE("PCM Switch", 0, AK4531_LVOICE, AK4531_RVOICE, 7, 7, 1, 1),AK4531_DOUBLE("PCM Volume", 0, AK4531_LVOICE, AK4531_RVOICE, 0, 0, 0x1f, 1),AK4531_DOUBLE("PCM Playback Switch", 0, AK4531_OUT_SW2, AK4531_OUT_SW2, 3, 2, 1, 0),AK4531_DOUBLE("PCM Capture Switch", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 2, 2, 1, 0),AK4531_DOUBLE("PCM Switch", 1, AK4531_LFM, AK4531_RFM, 7, 7, 1, 1),AK4531_DOUBLE("PCM Volume", 1, AK4531_LFM, AK4531_RFM, 0, 0, 0x1f, 1),AK4531_DOUBLE("PCM Playback Switch", 1, AK4531_OUT_SW1, AK4531_OUT_SW1, 6, 5, 1, 0),AK4531_INPUT_SW("PCM Capture Route", 1, AK4531_LIN_SW1, AK4531_RIN_SW1, 6, 5),AK4531_DOUBLE("CD Switch", 0, AK4531_LCD, AK4531_RCD, 7, 7, 1, 1),AK4531_DOUBLE("CD Volume", 0, AK4531_LCD, AK4531_RCD, 0, 0, 0x1f, 1),AK4531_DOUBLE("CD Playback Switch", 0, AK4531_OUT_SW1, AK4531_OUT_SW1, 2, 1, 1, 0),AK4531_INPUT_SW("CD Capture Route", 0, AK4531_LIN_SW1, AK4531_RIN_SW1, 2, 1),AK4531_DOUBLE("Line Switch", 0, AK4531_LLINE, AK4531_RLINE, 7, 7, 1, 1),AK4531_DOUBLE("Line Volume", 0, AK4531_LLINE, AK4531_RLINE, 0, 0, 0x1f, 1),AK4531_DOUBLE("Line Playback Switch", 0, AK4531_OUT_SW1, AK4531_OUT_SW1, 4, 3, 1, 0),AK4531_INPUT_SW("Line Capture Route", 0, AK4531_LIN_SW1, AK4531_RIN_SW1, 4, 3),AK4531_DOUBLE("Aux Switch", 0, AK4531_LAUXA, AK4531_RAUXA, 7, 7, 1, 1),AK4531_DOUBLE("Aux Volume", 0, AK4531_LAUXA, AK4531_RAUXA, 0, 0, 0x1f, 1),AK4531_DOUBLE("Aux Playback Switch", 0, AK4531_OUT_SW2, AK4531_OUT_SW2, 5, 4, 1, 0),AK4531_INPUT_SW("Aux Capture Route", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 4, 3),AK4531_SINGLE("Mono Switch", 0, AK4531_MONO1, 7, 1, 1),AK4531_SINGLE("Mono Volume", 0, AK4531_MONO1, 0, 0x1f, 1),AK4531_SINGLE("Mono Playback Switch", 0, AK4531_OUT_SW2, 0, 1, 0),AK4531_DOUBLE("Mono Capture Switch", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 0, 0, 1, 0),AK4531_SINGLE("Mono Switch", 1, AK4531_MONO2, 7, 1, 1),AK4531_SINGLE("Mono Volume", 1, AK4531_MONO2, 0, 0x1f, 1),AK4531_SINGLE("Mono Playback Switch", 1, AK4531_OUT_SW2, 1, 1, 0),AK4531_DOUBLE("Mono Capture Switch", 1, AK4531_LIN_SW2, AK4531_RIN_SW2, 1, 1, 1, 0),AK4531_SINGLE("Mic Volume", 0, AK4531_MIC, 0, 0x1f, 1),AK4531_SINGLE("Mic Switch", 0, AK4531_MIC, 7, 1, 1),AK4531_SINGLE("Mic Playback Switch", 0, AK4531_OUT_SW1, 0, 1, 0),AK4531_DOUBLE("Mic Capture Switch", 0, AK4531_LIN_SW1, AK4531_RIN_SW1, 0, 0, 1, 0),AK4531_DOUBLE("Mic Bypass Capture Switch", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 7, 7, 1, 0),AK4531_DOUBLE("Mono1 Bypass Capture Switch", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 6, 6, 1, 0),AK4531_DOUBLE("Mono2 Bypass Capture Switch", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 5, 5, 1, 0),AK4531_SINGLE("AD Input Select", 0, AK4531_AD_IN, 0, 1, 0),AK4531_SINGLE("Mic Boost (+30dB)", 0, AK4531_MIC_GAIN, 0, 1, 0)};static int snd_ak4531_free(struct snd_ak4531 *ak4531){ if (ak4531) { if (ak4531->private_free) ak4531->private_free(ak4531); kfree(ak4531); } return 0;}static int snd_ak4531_dev_free(struct snd_device *device){ struct snd_ak4531 *ak4531 = device->device_data; return snd_ak4531_free(ak4531);}static u8 snd_ak4531_initial_map[0x19 + 1] = { 0x9f, /* 00: Master Volume Lch */ 0x9f, /* 01: Master Volume Rch */ 0x9f, /* 02: Voice Volume Lch */ 0x9f, /* 03: Voice Volume Rch */ 0x9f, /* 04: FM Volume Lch */ 0x9f, /* 05: FM Volume Rch */ 0x9f, /* 06: CD Audio Volume Lch */ 0x9f, /* 07: CD Audio Volume Rch */ 0x9f, /* 08: Line Volume Lch */ 0x9f, /* 09: Line Volume Rch */ 0x9f, /* 0a: Aux Volume Lch */ 0x9f, /* 0b: Aux Volume Rch */ 0x9f, /* 0c: Mono1 Volume */ 0x9f, /* 0d: Mono2 Volume */ 0x9f, /* 0e: Mic Volume */ 0x87, /* 0f: Mono-out Volume */ 0x00, /* 10: Output Mixer SW1 */ 0x00, /* 11: Output Mixer SW2 */ 0x00, /* 12: Lch Input Mixer SW1 */ 0x00, /* 13: Rch Input Mixer SW1 */ 0x00, /* 14: Lch Input Mixer SW2 */ 0x00, /* 15: Rch Input Mixer SW2 */ 0x00, /* 16: Reset & Power Down */ 0x00, /* 17: Clock Select */ 0x00, /* 18: AD Input Select */ 0x01 /* 19: Mic Amp Setup */};int snd_ak4531_mixer(struct snd_card *card, struct snd_ak4531 *_ak4531, struct snd_ak4531 **rak4531){ unsigned int idx; int err; struct snd_ak4531 *ak4531; static struct snd_device_ops ops = { .dev_free = snd_ak4531_dev_free, }; snd_assert(rak4531 != NULL, return -EINVAL); *rak4531 = NULL; snd_assert(card != NULL && _ak4531 != NULL, return -EINVAL); ak4531 = kzalloc(sizeof(*ak4531), GFP_KERNEL); if (ak4531 == NULL) return -ENOMEM; *ak4531 = *_ak4531; init_MUTEX(&ak4531->reg_mutex); if ((err = snd_component_add(card, "AK4531")) < 0) { snd_ak4531_free(ak4531); return err; } strcpy(card->mixername, "Asahi Kasei AK4531"); ak4531->write(ak4531, AK4531_RESET, 0x03); /* no RST, PD */ udelay(100); ak4531->write(ak4531, AK4531_CLOCK, 0x00); /* CODEC ADC and CODEC DAC use {LR,B}CLK2 and run off LRCLK2 PLL */ for (idx = 0; idx <= 0x19; idx++) { if (idx == AK4531_RESET || idx == AK4531_CLOCK) continue; ak4531->write(ak4531, idx, ak4531->regs[idx] = snd_ak4531_initial_map[idx]); /* recording source is mixer */ } for (idx = 0; idx < ARRAY_SIZE(snd_ak4531_controls); idx++) { if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_ak4531_controls[idx], ak4531))) < 0) { snd_ak4531_free(ak4531); return err; } } snd_ak4531_proc_init(card, ak4531); if ((err = snd_device_new(card, SNDRV_DEV_CODEC, ak4531, &ops)) < 0) { snd_ak4531_free(ak4531); return err; }#if 0 snd_ak4531_dump(ak4531);#endif *rak4531 = ak4531; return 0;}/* * power management */#ifdef CONFIG_PMvoid snd_ak4531_suspend(struct snd_ak4531 *ak4531){ /* mute */ ak4531->write(ak4531, AK4531_LMASTER, 0x9f); ak4531->write(ak4531, AK4531_RMASTER, 0x9f); /* powerdown */ ak4531->write(ak4531, AK4531_RESET, 0x01);}void snd_ak4531_resume(struct snd_ak4531 *ak4531){ int idx; /* initialize */ ak4531->write(ak4531, AK4531_RESET, 0x03); udelay(100); ak4531->write(ak4531, AK4531_CLOCK, 0x00); /* restore mixer registers */ for (idx = 0; idx <= 0x19; idx++) { if (idx == AK4531_RESET || idx == AK4531_CLOCK) continue; ak4531->write(ak4531, idx, ak4531->regs[idx]); }}#endif#ifdef CONFIG_PROC_FS/* * /proc interface */static void snd_ak4531_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer){ struct snd_ak4531 *ak4531 = entry->private_data; snd_iprintf(buffer, "Asahi Kasei AK4531\n\n"); snd_iprintf(buffer, "Recording source : %s\n" "MIC gain : %s\n", ak4531->regs[AK4531_AD_IN] & 1 ? "external" : "mixer", ak4531->regs[AK4531_MIC_GAIN] & 1 ? "+30dB" : "+0dB");}static void snd_ak4531_proc_init(struct snd_card *card, struct snd_ak4531 *ak4531){ struct snd_info_entry *entry; if (! snd_card_proc_new(card, "ak4531", &entry)) snd_info_set_text_ops(entry, ak4531, 1024, snd_ak4531_proc_read);}#endifEXPORT_SYMBOL(snd_ak4531_mixer);#ifdef CONFIG_PMEXPORT_SYMBOL(snd_ak4531_suspend);EXPORT_SYMBOL(snd_ak4531_resume);#endif/* * INIT part */static int __init alsa_ak4531_init(void){ return 0;}static void __exit alsa_ak4531_exit(void){}module_init(alsa_ak4531_init)module_exit(alsa_ak4531_exit)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -