^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (c) 2004 James Courtier-Dutton <James@superbug.demon.co.uk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Driver CA0106 chips. e.g. Sound Blaster Audigy LS and Live 24bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Version: 0.0.18
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * FEATURES currently supported:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * See ca0106_main.c for features.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Changelog:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Support interrupts per period.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Removed noise from Center/LFE channel when in Analog mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * Rename and remove mixer controls.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * 0.0.6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * Use separate card based DMA buffer for periods table list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * 0.0.7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * Change remove and rename ctrls into lists.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * 0.0.8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * Try to fix capture sources.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * 0.0.9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * Fix AC3 output.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * Enable S32_LE format support.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * 0.0.10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * Enable playback 48000 and 96000 rates. (Rates other that these do not work, even with "plug:front".)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * 0.0.11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * Add Model name recognition.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * 0.0.12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * Correct interrupt timing. interrupt at end of period, instead of in the middle of a playback period.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * Remove redundent "voice" handling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * 0.0.13
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * Single trigger call for multi channels.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * 0.0.14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * Set limits based on what the sound card hardware can do.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * playback periods_min=2, periods_max=8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * capture hw constraints require period_size = n * 64 bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * playback hw constraints require period_size = n * 64 bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * 0.0.15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * Separated ca0106.c into separate functional .c files.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * 0.0.16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * Modified Copyright message.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * 0.0.17
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * Implement Mic and Line in Capture.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * 0.0.18
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * Add support for mute control on SB Live 24bit (cards w/ SPI DAC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * This code was initially based on code from ALSA's emu10k1x.c which is:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * Copyright (c) by Francisco Moraes <fmoraes@nc.rr.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #include <sound/initval.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #include <sound/pcm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #include <sound/ac97_codec.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #include <sound/info.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #include <sound/tlv.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #include "ca0106.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) static void ca0106_spdif_enable(struct snd_ca0106 *emu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) if (emu->spdif_enable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) /* Digital */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) snd_ca0106_ptr_write(emu, SPDIF_SELECT1, 0, 0xf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) snd_ca0106_ptr_write(emu, SPDIF_SELECT2, 0, 0x0b000000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) val = snd_ca0106_ptr_read(emu, CAPTURE_CONTROL, 0) & ~0x1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) snd_ca0106_ptr_write(emu, CAPTURE_CONTROL, 0, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) val = inl(emu->port + GPIO) & ~0x101;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) outl(val, emu->port + GPIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) /* Analog */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) snd_ca0106_ptr_write(emu, SPDIF_SELECT1, 0, 0xf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) snd_ca0106_ptr_write(emu, SPDIF_SELECT2, 0, 0x000f0000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) val = snd_ca0106_ptr_read(emu, CAPTURE_CONTROL, 0) | 0x1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) snd_ca0106_ptr_write(emu, CAPTURE_CONTROL, 0, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) val = inl(emu->port + GPIO) | 0x101;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) outl(val, emu->port + GPIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) static void ca0106_set_capture_source(struct snd_ca0106 *emu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) unsigned int val = emu->capture_source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) unsigned int source, mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) source = (val << 28) | (val << 24) | (val << 20) | (val << 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) mask = snd_ca0106_ptr_read(emu, CAPTURE_SOURCE, 0) & 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) snd_ca0106_ptr_write(emu, CAPTURE_SOURCE, 0, source | mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) static void ca0106_set_i2c_capture_source(struct snd_ca0106 *emu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) unsigned int val, int force)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) unsigned int ngain, ogain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) u32 source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) snd_ca0106_i2c_write(emu, ADC_MUX, 0); /* Mute input */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) ngain = emu->i2c_capture_volume[val][0]; /* Left */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) ogain = emu->i2c_capture_volume[emu->i2c_capture_source][0]; /* Left */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (force || ngain != ogain)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) snd_ca0106_i2c_write(emu, ADC_ATTEN_ADCL, ngain & 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) ngain = emu->i2c_capture_volume[val][1]; /* Right */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) ogain = emu->i2c_capture_volume[emu->i2c_capture_source][1]; /* Right */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) if (force || ngain != ogain)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) snd_ca0106_i2c_write(emu, ADC_ATTEN_ADCR, ngain & 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) source = 1 << val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) snd_ca0106_i2c_write(emu, ADC_MUX, source); /* Set source */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) emu->i2c_capture_source = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static void ca0106_set_capture_mic_line_in(struct snd_ca0106 *emu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) u32 tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) if (emu->capture_mic_line_in) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) /* snd_ca0106_i2c_write(emu, ADC_MUX, 0); */ /* Mute input */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) tmp = inl(emu->port+GPIO) & ~0x400;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) tmp = tmp | 0x400;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) outl(tmp, emu->port+GPIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) /* snd_ca0106_i2c_write(emu, ADC_MUX, ADC_MUX_MIC); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /* snd_ca0106_i2c_write(emu, ADC_MUX, 0); */ /* Mute input */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) tmp = inl(emu->port+GPIO) & ~0x400;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) outl(tmp, emu->port+GPIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) /* snd_ca0106_i2c_write(emu, ADC_MUX, ADC_MUX_LINEIN); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static void ca0106_set_spdif_bits(struct snd_ca0106 *emu, int idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) snd_ca0106_ptr_write(emu, SPCS0 + idx, 0, emu->spdif_str_bits[idx]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static const DECLARE_TLV_DB_SCALE(snd_ca0106_db_scale1, -5175, 25, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static const DECLARE_TLV_DB_SCALE(snd_ca0106_db_scale2, -10350, 50, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) #define snd_ca0106_shared_spdif_info snd_ctl_boolean_mono_info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) static int snd_ca0106_shared_spdif_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) ucontrol->value.integer.value[0] = emu->spdif_enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) static int snd_ca0106_shared_spdif_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) int change = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) val = !!ucontrol->value.integer.value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) change = (emu->spdif_enable != val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) if (change) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) emu->spdif_enable = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) ca0106_spdif_enable(emu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) return change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) static int snd_ca0106_capture_source_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) static const char * const texts[6] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) "IEC958 out", "i2s mixer out", "IEC958 in", "i2s in", "AC97 in", "SRC out"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) return snd_ctl_enum_info(uinfo, 1, 6, texts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) static int snd_ca0106_capture_source_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) ucontrol->value.enumerated.item[0] = emu->capture_source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static int snd_ca0106_capture_source_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) int change = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) val = ucontrol->value.enumerated.item[0] ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) if (val >= 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) change = (emu->capture_source != val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) if (change) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) emu->capture_source = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) ca0106_set_capture_source(emu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) return change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static int snd_ca0106_i2c_capture_source_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) static const char * const texts[4] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) "Phone", "Mic", "Line in", "Aux"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) return snd_ctl_enum_info(uinfo, 1, 4, texts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) static int snd_ca0106_i2c_capture_source_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) ucontrol->value.enumerated.item[0] = emu->i2c_capture_source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) static int snd_ca0106_i2c_capture_source_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) unsigned int source_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) int change = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) /* If the capture source has changed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * update the capture volume from the cached value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * for the particular source.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) source_id = ucontrol->value.enumerated.item[0] ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) if (source_id >= 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) change = (emu->i2c_capture_source != source_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) if (change) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) ca0106_set_i2c_capture_source(emu, source_id, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) return change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) static int snd_ca0106_capture_line_in_side_out_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) static const char * const texts[2] = { "Side out", "Line in" };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) return snd_ctl_enum_info(uinfo, 1, 2, texts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) static int snd_ca0106_capture_mic_line_in_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) static const char * const texts[2] = { "Line in", "Mic in" };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) return snd_ctl_enum_info(uinfo, 1, 2, texts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) static int snd_ca0106_capture_mic_line_in_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) ucontrol->value.enumerated.item[0] = emu->capture_mic_line_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) static int snd_ca0106_capture_mic_line_in_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) int change = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) val = ucontrol->value.enumerated.item[0] ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) if (val > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) change = (emu->capture_mic_line_in != val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) if (change) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) emu->capture_mic_line_in = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) ca0106_set_capture_mic_line_in(emu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) return change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) static const struct snd_kcontrol_new snd_ca0106_capture_mic_line_in =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) .name = "Shared Mic/Line in Capture Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) .info = snd_ca0106_capture_mic_line_in_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) .get = snd_ca0106_capture_mic_line_in_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) .put = snd_ca0106_capture_mic_line_in_put
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) static const struct snd_kcontrol_new snd_ca0106_capture_line_in_side_out =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) .name = "Shared Line in/Side out Capture Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) .info = snd_ca0106_capture_line_in_side_out_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) .get = snd_ca0106_capture_mic_line_in_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) .put = snd_ca0106_capture_mic_line_in_put
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) static int snd_ca0106_spdif_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) uinfo->count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) static void decode_spdif_bits(unsigned char *status, unsigned int bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) status[0] = (bits >> 0) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) status[1] = (bits >> 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) status[2] = (bits >> 16) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) status[3] = (bits >> 24) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) static int snd_ca0106_spdif_get_default(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) decode_spdif_bits(ucontrol->value.iec958.status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) emu->spdif_bits[idx]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) static int snd_ca0106_spdif_get_stream(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) decode_spdif_bits(ucontrol->value.iec958.status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) emu->spdif_str_bits[idx]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) static int snd_ca0106_spdif_get_mask(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) ucontrol->value.iec958.status[0] = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) ucontrol->value.iec958.status[1] = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) ucontrol->value.iec958.status[2] = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) ucontrol->value.iec958.status[3] = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) static unsigned int encode_spdif_bits(unsigned char *status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) return ((unsigned int)status[0] << 0) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) ((unsigned int)status[1] << 8) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) ((unsigned int)status[2] << 16) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) ((unsigned int)status[3] << 24);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) static int snd_ca0106_spdif_put_default(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) val = encode_spdif_bits(ucontrol->value.iec958.status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) if (val != emu->spdif_bits[idx]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) emu->spdif_bits[idx] = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) /* FIXME: this isn't safe, but needed to keep the compatibility
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) * with older alsa-lib config
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) emu->spdif_str_bits[idx] = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) ca0106_set_spdif_bits(emu, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) static int snd_ca0106_spdif_put_stream(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) val = encode_spdif_bits(ucontrol->value.iec958.status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) if (val != emu->spdif_str_bits[idx]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) emu->spdif_str_bits[idx] = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) ca0106_set_spdif_bits(emu, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) static int snd_ca0106_volume_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) uinfo->count = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) uinfo->value.integer.min = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) uinfo->value.integer.max = 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) static int snd_ca0106_volume_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) unsigned int value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) int channel_id, reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) channel_id = (kcontrol->private_value >> 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) reg = kcontrol->private_value & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) value = snd_ca0106_ptr_read(emu, reg, channel_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) ucontrol->value.integer.value[0] = 0xff - ((value >> 24) & 0xff); /* Left */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) ucontrol->value.integer.value[1] = 0xff - ((value >> 16) & 0xff); /* Right */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) static int snd_ca0106_volume_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) unsigned int oval, nval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) int channel_id, reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) channel_id = (kcontrol->private_value >> 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) reg = kcontrol->private_value & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) oval = snd_ca0106_ptr_read(emu, reg, channel_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) nval = ((0xff - ucontrol->value.integer.value[0]) << 24) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) ((0xff - ucontrol->value.integer.value[1]) << 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) nval |= ((0xff - ucontrol->value.integer.value[0]) << 8) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) ((0xff - ucontrol->value.integer.value[1]) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) if (oval == nval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) snd_ca0106_ptr_write(emu, reg, channel_id, nval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) static int snd_ca0106_i2c_volume_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) uinfo->count = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) uinfo->value.integer.min = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) uinfo->value.integer.max = 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) static int snd_ca0106_i2c_volume_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) int source_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) source_id = kcontrol->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) ucontrol->value.integer.value[0] = emu->i2c_capture_volume[source_id][0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) ucontrol->value.integer.value[1] = emu->i2c_capture_volume[source_id][1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) static int snd_ca0106_i2c_volume_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) unsigned int ogain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) unsigned int ngain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) int source_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) int change = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) source_id = kcontrol->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) ogain = emu->i2c_capture_volume[source_id][0]; /* Left */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) ngain = ucontrol->value.integer.value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) if (ngain > 0xff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) if (ogain != ngain) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) if (emu->i2c_capture_source == source_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) snd_ca0106_i2c_write(emu, ADC_ATTEN_ADCL, ((ngain) & 0xff) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) emu->i2c_capture_volume[source_id][0] = ucontrol->value.integer.value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) change = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) ogain = emu->i2c_capture_volume[source_id][1]; /* Right */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) ngain = ucontrol->value.integer.value[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) if (ngain > 0xff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) if (ogain != ngain) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) if (emu->i2c_capture_source == source_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) snd_ca0106_i2c_write(emu, ADC_ATTEN_ADCR, ((ngain) & 0xff));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) emu->i2c_capture_volume[source_id][1] = ucontrol->value.integer.value[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) change = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) return change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) #define spi_mute_info snd_ctl_boolean_mono_info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) static int spi_mute_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) unsigned int reg = kcontrol->private_value >> SPI_REG_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) unsigned int bit = kcontrol->private_value & SPI_REG_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) ucontrol->value.integer.value[0] = !(emu->spi_dac_reg[reg] & bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) static int spi_mute_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) unsigned int reg = kcontrol->private_value >> SPI_REG_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) unsigned int bit = kcontrol->private_value & SPI_REG_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) ret = emu->spi_dac_reg[reg] & bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) if (ucontrol->value.integer.value[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) if (!ret) /* bit already cleared, do nothing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) emu->spi_dac_reg[reg] &= ~bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) if (ret) /* bit already set, do nothing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) emu->spi_dac_reg[reg] |= bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) ret = snd_ca0106_spi_write(emu, emu->spi_dac_reg[reg]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) return ret ? -EINVAL : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) #define CA_VOLUME(xname,chid,reg) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) .info = snd_ca0106_volume_info, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) .get = snd_ca0106_volume_get, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) .put = snd_ca0106_volume_put, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) .tlv = { .p = snd_ca0106_db_scale1 }, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) .private_value = ((chid) << 8) | (reg) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) static const struct snd_kcontrol_new snd_ca0106_volume_ctls[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) CA_VOLUME("Analog Front Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) CONTROL_FRONT_CHANNEL, PLAYBACK_VOLUME2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) CA_VOLUME("Analog Rear Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) CONTROL_REAR_CHANNEL, PLAYBACK_VOLUME2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) CA_VOLUME("Analog Center/LFE Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) CONTROL_CENTER_LFE_CHANNEL, PLAYBACK_VOLUME2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) CA_VOLUME("Analog Side Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) CONTROL_UNKNOWN_CHANNEL, PLAYBACK_VOLUME2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) CA_VOLUME("IEC958 Front Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) CONTROL_FRONT_CHANNEL, PLAYBACK_VOLUME1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) CA_VOLUME("IEC958 Rear Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) CONTROL_REAR_CHANNEL, PLAYBACK_VOLUME1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) CA_VOLUME("IEC958 Center/LFE Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) CONTROL_CENTER_LFE_CHANNEL, PLAYBACK_VOLUME1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) CA_VOLUME("IEC958 Unknown Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) CONTROL_UNKNOWN_CHANNEL, PLAYBACK_VOLUME1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) CA_VOLUME("CAPTURE feedback Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 1, CAPTURE_CONTROL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) .access = SNDRV_CTL_ELEM_ACCESS_READ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) .iface = SNDRV_CTL_ELEM_IFACE_PCM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) .count = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) .info = snd_ca0106_spdif_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) .get = snd_ca0106_spdif_get_mask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) .name = "IEC958 Playback Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) .info = snd_ca0106_shared_spdif_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) .get = snd_ca0106_shared_spdif_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) .put = snd_ca0106_shared_spdif_put
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) .name = "Digital Source Capture Enum",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) .info = snd_ca0106_capture_source_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) .get = snd_ca0106_capture_source_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) .put = snd_ca0106_capture_source_put
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) .name = "Analog Source Capture Enum",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) .info = snd_ca0106_i2c_capture_source_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) .get = snd_ca0106_i2c_capture_source_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) .put = snd_ca0106_i2c_capture_source_put
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) .iface = SNDRV_CTL_ELEM_IFACE_PCM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) .count = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) .info = snd_ca0106_spdif_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) .get = snd_ca0106_spdif_get_default,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) .put = snd_ca0106_spdif_put_default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) .iface = SNDRV_CTL_ELEM_IFACE_PCM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) .count = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) .info = snd_ca0106_spdif_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) .get = snd_ca0106_spdif_get_stream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) .put = snd_ca0106_spdif_put_stream
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) #define I2C_VOLUME(xname,chid) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) .info = snd_ca0106_i2c_volume_info, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) .get = snd_ca0106_i2c_volume_get, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) .put = snd_ca0106_i2c_volume_put, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) .tlv = { .p = snd_ca0106_db_scale2 }, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) .private_value = chid \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) static const struct snd_kcontrol_new snd_ca0106_volume_i2c_adc_ctls[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) I2C_VOLUME("Phone Capture Volume", 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) I2C_VOLUME("Mic Capture Volume", 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) I2C_VOLUME("Line in Capture Volume", 2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) I2C_VOLUME("Aux Capture Volume", 3),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) static const int spi_dmute_reg[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) SPI_DMUTE0_REG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) SPI_DMUTE1_REG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) SPI_DMUTE2_REG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) SPI_DMUTE4_REG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) static const int spi_dmute_bit[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) SPI_DMUTE0_BIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) SPI_DMUTE1_BIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) SPI_DMUTE2_BIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) SPI_DMUTE4_BIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) static struct snd_kcontrol_new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) snd_ca0106_volume_spi_dac_ctl(const struct snd_ca0106_details *details,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) int channel_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) struct snd_kcontrol_new spi_switch = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) int reg, bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) int dac_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) spi_switch.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) spi_switch.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) spi_switch.info = spi_mute_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) spi_switch.get = spi_mute_get;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) spi_switch.put = spi_mute_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) switch (channel_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) case PCM_FRONT_CHANNEL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) spi_switch.name = "Analog Front Playback Switch";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) dac_id = (details->spi_dac & 0xf000) >> (4 * 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) case PCM_REAR_CHANNEL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) spi_switch.name = "Analog Rear Playback Switch";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) dac_id = (details->spi_dac & 0x0f00) >> (4 * 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) case PCM_CENTER_LFE_CHANNEL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) spi_switch.name = "Analog Center/LFE Playback Switch";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) dac_id = (details->spi_dac & 0x00f0) >> (4 * 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) case PCM_UNKNOWN_CHANNEL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) spi_switch.name = "Analog Side Playback Switch";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) dac_id = (details->spi_dac & 0x000f) >> (4 * 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) /* Unused channel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) spi_switch.name = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) dac_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) reg = spi_dmute_reg[dac_id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) bit = spi_dmute_bit[dac_id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) spi_switch.private_value = (reg << SPI_REG_SHIFT) | bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) return spi_switch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) static int remove_ctl(struct snd_card *card, const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) struct snd_ctl_elem_id id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) memset(&id, 0, sizeof(id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) strcpy(id.name, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) return snd_ctl_remove_id(card, &id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) static struct snd_kcontrol *ctl_find(struct snd_card *card, const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) struct snd_ctl_elem_id sid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) memset(&sid, 0, sizeof(sid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) /* FIXME: strcpy is bad. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) strcpy(sid.name, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) return snd_ctl_find_id(card, &sid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) static int rename_ctl(struct snd_card *card, const char *src, const char *dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) struct snd_kcontrol *kctl = ctl_find(card, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) if (kctl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) strcpy(kctl->id.name, dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) #define ADD_CTLS(emu, ctls) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) int i, _err; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) for (i = 0; i < ARRAY_SIZE(ctls); i++) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) _err = snd_ctl_add(card, snd_ctl_new1(&ctls[i], emu)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) if (_err < 0) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) return _err; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) DECLARE_TLV_DB_SCALE(snd_ca0106_master_db_scale, -6375, 25, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) static const char * const follower_vols[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) "Analog Front Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) "Analog Rear Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) "Analog Center/LFE Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) "Analog Side Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) "IEC958 Front Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) "IEC958 Rear Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) "IEC958 Center/LFE Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) "IEC958 Unknown Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) "CAPTURE feedback Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) static const char * const follower_sws[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) "Analog Front Playback Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) "Analog Rear Playback Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) "Analog Center/LFE Playback Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) "Analog Side Playback Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) "IEC958 Playback Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) static void add_followers(struct snd_card *card,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) struct snd_kcontrol *master, const char * const *list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) for (; *list; list++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) struct snd_kcontrol *follower = ctl_find(card, *list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) if (follower)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) snd_ctl_add_follower(master, follower);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) int snd_ca0106_mixer(struct snd_ca0106 *emu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) struct snd_card *card = emu->card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) const char * const *c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) struct snd_kcontrol *vmaster;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) static const char * const ca0106_remove_ctls[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) "Master Mono Playback Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) "Master Mono Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) "3D Control - Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) "3D Control Sigmatel - Depth",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) "PCM Playback Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) "PCM Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) "CD Playback Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) "CD Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) "Phone Playback Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) "Phone Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) "Video Playback Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) "Video Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) "Beep Playback Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) "Beep Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) "Mono Output Select",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) "Capture Source",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) "Capture Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) "Capture Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) "External Amplifier",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) "Sigmatel 4-Speaker Stereo Playback Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) "Surround Phase Inversion Playback Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) static const char * const ca0106_rename_ctls[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) "Master Playback Switch", "Capture Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) "Master Playback Volume", "Capture Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) "Line Playback Switch", "AC97 Line Capture Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) "Line Playback Volume", "AC97 Line Capture Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) "Aux Playback Switch", "AC97 Aux Capture Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) "Aux Playback Volume", "AC97 Aux Capture Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) "Mic Playback Switch", "AC97 Mic Capture Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) "Mic Playback Volume", "AC97 Mic Capture Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) "Mic Select", "AC97 Mic Select",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) "Mic Boost (+20dB)", "AC97 Mic Boost (+20dB)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) #if 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) for (c = ca0106_remove_ctls; *c; c++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) remove_ctl(card, *c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) for (c = ca0106_rename_ctls; *c; c += 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) rename_ctl(card, c[0], c[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) ADD_CTLS(emu, snd_ca0106_volume_ctls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) if (emu->details->i2c_adc == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) ADD_CTLS(emu, snd_ca0106_volume_i2c_adc_ctls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) if (emu->details->gpio_type == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) err = snd_ctl_add(card, snd_ctl_new1(&snd_ca0106_capture_mic_line_in, emu));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) else /* gpio_type == 2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) err = snd_ctl_add(card, snd_ctl_new1(&snd_ca0106_capture_line_in_side_out, emu));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) if (emu->details->spi_dac) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) for (i = 0;; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) struct snd_kcontrol_new ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) ctl = snd_ca0106_volume_spi_dac_ctl(emu->details, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) if (!ctl.name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) err = snd_ctl_add(card, snd_ctl_new1(&ctl, emu));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) /* Create virtual master controls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) vmaster = snd_ctl_make_virtual_master("Master Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) snd_ca0106_master_db_scale);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) if (!vmaster)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) err = snd_ctl_add(card, vmaster);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) add_followers(card, vmaster, follower_vols);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) if (emu->details->spi_dac) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) vmaster = snd_ctl_make_virtual_master("Master Playback Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) if (!vmaster)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) err = snd_ctl_add(card, vmaster);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) add_followers(card, vmaster, follower_sws);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) strcpy(card->mixername, "CA0106");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) struct ca0106_vol_tbl {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) unsigned int channel_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) unsigned int reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) static const struct ca0106_vol_tbl saved_volumes[NUM_SAVED_VOLUMES] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) { CONTROL_FRONT_CHANNEL, PLAYBACK_VOLUME2 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) { CONTROL_REAR_CHANNEL, PLAYBACK_VOLUME2 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) { CONTROL_CENTER_LFE_CHANNEL, PLAYBACK_VOLUME2 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) { CONTROL_UNKNOWN_CHANNEL, PLAYBACK_VOLUME2 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) { CONTROL_FRONT_CHANNEL, PLAYBACK_VOLUME1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) { CONTROL_REAR_CHANNEL, PLAYBACK_VOLUME1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) { CONTROL_CENTER_LFE_CHANNEL, PLAYBACK_VOLUME1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) { CONTROL_UNKNOWN_CHANNEL, PLAYBACK_VOLUME1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) { 1, CAPTURE_CONTROL },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) void snd_ca0106_mixer_suspend(struct snd_ca0106 *chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) /* save volumes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) for (i = 0; i < NUM_SAVED_VOLUMES; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) chip->saved_vol[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) snd_ca0106_ptr_read(chip, saved_volumes[i].reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) saved_volumes[i].channel_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) void snd_ca0106_mixer_resume(struct snd_ca0106 *chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) for (i = 0; i < NUM_SAVED_VOLUMES; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) snd_ca0106_ptr_write(chip, saved_volumes[i].reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) saved_volumes[i].channel_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) chip->saved_vol[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) ca0106_spdif_enable(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) ca0106_set_capture_source(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) ca0106_set_i2c_capture_source(chip, chip->i2c_capture_source, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) for (i = 0; i < 4; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) ca0106_set_spdif_bits(chip, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) if (chip->details->i2c_adc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) ca0106_set_capture_mic_line_in(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) #endif /* CONFIG_PM_SLEEP */