^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2008, Creative Technology Ltd. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * @File ctmixer.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * @Brief
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * This file contains the implementation of alsa mixer device functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * @Author Liu Chun
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * @Date May 28 2008
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "ctmixer.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "ctamixer.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <sound/control.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <sound/asoundef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <sound/pcm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <sound/tlv.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) enum CT_SUM_CTL {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) SUM_IN_F,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) SUM_IN_R,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) SUM_IN_C,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) SUM_IN_S,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) SUM_IN_F_C,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) NUM_CT_SUMS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) enum CT_AMIXER_CTL {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /* volume control mixers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) AMIXER_MASTER_F,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) AMIXER_MASTER_R,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) AMIXER_MASTER_C,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) AMIXER_MASTER_S,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) AMIXER_PCM_F,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) AMIXER_PCM_R,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) AMIXER_PCM_C,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) AMIXER_PCM_S,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) AMIXER_SPDIFI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) AMIXER_LINEIN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) AMIXER_MIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) AMIXER_SPDIFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) AMIXER_WAVE_F,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) AMIXER_WAVE_R,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) AMIXER_WAVE_C,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) AMIXER_WAVE_S,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) AMIXER_MASTER_F_C,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) AMIXER_PCM_F_C,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) AMIXER_SPDIFI_C,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) AMIXER_LINEIN_C,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) AMIXER_MIC_C,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) /* this should always be the last one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) NUM_CT_AMIXERS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) enum CTALSA_MIXER_CTL {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /* volume control mixers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) MIXER_MASTER_P,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) MIXER_PCM_P,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) MIXER_LINEIN_P,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) MIXER_MIC_P,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) MIXER_SPDIFI_P,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) MIXER_SPDIFO_P,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) MIXER_WAVEF_P,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) MIXER_WAVER_P,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) MIXER_WAVEC_P,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) MIXER_WAVES_P,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) MIXER_MASTER_C,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) MIXER_PCM_C,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) MIXER_LINEIN_C,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) MIXER_MIC_C,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) MIXER_SPDIFI_C,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) /* switch control mixers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) MIXER_PCM_C_S,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) MIXER_LINEIN_C_S,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) MIXER_MIC_C_S,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) MIXER_SPDIFI_C_S,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) MIXER_SPDIFO_P_S,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) MIXER_WAVEF_P_S,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) MIXER_WAVER_P_S,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) MIXER_WAVEC_P_S,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) MIXER_WAVES_P_S,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) MIXER_DIGITAL_IO_S,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) MIXER_IEC958_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) MIXER_IEC958_DEFAULT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) MIXER_IEC958_STREAM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) /* this should always be the last one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) NUM_CTALSA_MIXERS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) #define VOL_MIXER_START MIXER_MASTER_P
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #define VOL_MIXER_END MIXER_SPDIFI_C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #define VOL_MIXER_NUM (VOL_MIXER_END - VOL_MIXER_START + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #define SWH_MIXER_START MIXER_PCM_C_S
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #define SWH_MIXER_END MIXER_DIGITAL_IO_S
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #define SWH_CAPTURE_START MIXER_PCM_C_S
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) #define SWH_CAPTURE_END MIXER_SPDIFI_C_S
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #define CHN_NUM 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct ct_kcontrol_init {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) unsigned char ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static struct ct_kcontrol_init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) ct_kcontrol_init_table[NUM_CTALSA_MIXERS] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) [MIXER_MASTER_P] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) .ctl = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) .name = "Master Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) [MIXER_MASTER_C] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) .ctl = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) .name = "Master Capture Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) [MIXER_PCM_P] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) .ctl = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) .name = "PCM Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) [MIXER_PCM_C] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) .ctl = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) .name = "PCM Capture Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) [MIXER_LINEIN_P] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) .ctl = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) .name = "Line Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) [MIXER_LINEIN_C] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) .ctl = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) .name = "Line Capture Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) [MIXER_MIC_P] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) .ctl = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) .name = "Mic Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) [MIXER_MIC_C] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) .ctl = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) .name = "Mic Capture Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) [MIXER_SPDIFI_P] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) .ctl = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) .name = "IEC958 Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) [MIXER_SPDIFI_C] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) .ctl = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) .name = "IEC958 Capture Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) [MIXER_SPDIFO_P] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) .ctl = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) .name = "Digital Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) [MIXER_WAVEF_P] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) .ctl = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) .name = "Front Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) [MIXER_WAVES_P] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) .ctl = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) .name = "Side Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) [MIXER_WAVEC_P] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) .ctl = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) .name = "Center/LFE Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) [MIXER_WAVER_P] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) .ctl = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) .name = "Surround Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) [MIXER_PCM_C_S] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) .ctl = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) .name = "PCM Capture Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) [MIXER_LINEIN_C_S] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) .ctl = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) .name = "Line Capture Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) [MIXER_MIC_C_S] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) .ctl = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) .name = "Mic Capture Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) [MIXER_SPDIFI_C_S] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) .ctl = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) .name = "IEC958 Capture Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) [MIXER_SPDIFO_P_S] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) .ctl = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) .name = "Digital Playback Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) [MIXER_WAVEF_P_S] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) .ctl = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) .name = "Front Playback Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) [MIXER_WAVES_P_S] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) .ctl = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) .name = "Side Playback Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) [MIXER_WAVEC_P_S] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) .ctl = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) .name = "Center/LFE Playback Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) [MIXER_WAVER_P_S] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) .ctl = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) .name = "Surround Playback Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) [MIXER_DIGITAL_IO_S] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) .ctl = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) .name = "Digit-IO Playback Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) },
^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 void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) ct_mixer_recording_select(struct ct_mixer *mixer, enum CT_AMIXER_CTL type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) ct_mixer_recording_unselect(struct ct_mixer *mixer, enum CT_AMIXER_CTL type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) /* FIXME: this static looks like it would fail if more than one card was */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) /* installed. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) static struct snd_kcontrol *kctls[2] = {NULL};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) static enum CT_AMIXER_CTL get_amixer_index(enum CTALSA_MIXER_CTL alsa_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) switch (alsa_index) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) case MIXER_MASTER_P: return AMIXER_MASTER_F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) case MIXER_MASTER_C: return AMIXER_MASTER_F_C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) case MIXER_PCM_P: return AMIXER_PCM_F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) case MIXER_PCM_C:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) case MIXER_PCM_C_S: return AMIXER_PCM_F_C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) case MIXER_LINEIN_P: return AMIXER_LINEIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) case MIXER_LINEIN_C:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) case MIXER_LINEIN_C_S: return AMIXER_LINEIN_C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) case MIXER_MIC_P: return AMIXER_MIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) case MIXER_MIC_C:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) case MIXER_MIC_C_S: return AMIXER_MIC_C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) case MIXER_SPDIFI_P: return AMIXER_SPDIFI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) case MIXER_SPDIFI_C:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) case MIXER_SPDIFI_C_S: return AMIXER_SPDIFI_C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) case MIXER_SPDIFO_P: return AMIXER_SPDIFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) case MIXER_WAVEF_P: return AMIXER_WAVE_F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) case MIXER_WAVES_P: return AMIXER_WAVE_S;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) case MIXER_WAVEC_P: return AMIXER_WAVE_C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) case MIXER_WAVER_P: return AMIXER_WAVE_R;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) default: return NUM_CT_AMIXERS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static enum CT_AMIXER_CTL get_recording_amixer(enum CT_AMIXER_CTL index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) switch (index) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) case AMIXER_MASTER_F: return AMIXER_MASTER_F_C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) case AMIXER_PCM_F: return AMIXER_PCM_F_C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) case AMIXER_SPDIFI: return AMIXER_SPDIFI_C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) case AMIXER_LINEIN: return AMIXER_LINEIN_C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) case AMIXER_MIC: return AMIXER_MIC_C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) default: return NUM_CT_AMIXERS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) static unsigned char
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) get_switch_state(struct ct_mixer *mixer, enum CTALSA_MIXER_CTL type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) return (mixer->switch_state & (0x1 << (type - SWH_MIXER_START)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) set_switch_state(struct ct_mixer *mixer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) enum CTALSA_MIXER_CTL type, unsigned char state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) if (state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) mixer->switch_state |= (0x1 << (type - SWH_MIXER_START));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) mixer->switch_state &= ~(0x1 << (type - SWH_MIXER_START));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) #if 0 /* not used */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) /* Map integer value ranging from 0 to 65535 to 14-bit float value ranging
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) * from 2^-6 to (1+1023/1024) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) static unsigned int uint16_to_float14(unsigned int x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) if (x < 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) x *= 2031;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) x /= 65535;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) x += 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) /* i <= 6 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) for (i = 0; !(x & 0x400); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) x <<= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) x = (((7 - i) & 0x7) << 10) | (x & 0x3ff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) return x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) static unsigned int float14_to_uint16(unsigned int x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) unsigned int e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) if (!x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) return x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) e = (x >> 10) & 0x7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) x &= 0x3ff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) x += 1024;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) x >>= (7 - e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) x -= 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) x *= 65535;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) x /= 2031;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) return x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) #endif /* not used */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) #define VOL_SCALE 0x1c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) #define VOL_MAX 0x100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) static const DECLARE_TLV_DB_SCALE(ct_vol_db_scale, -6400, 25, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) static int ct_alsa_mix_volume_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) uinfo->count = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) uinfo->value.integer.min = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) uinfo->value.integer.max = VOL_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) static int ct_alsa_mix_volume_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) struct ct_atc *atc = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) enum CT_AMIXER_CTL type = get_amixer_index(kcontrol->private_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) struct amixer *amixer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) int i, val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) for (i = 0; i < 2; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) amixer = ((struct ct_mixer *)atc->mixer)->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) amixers[type*CHN_NUM+i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) val = amixer->ops->get_scale(amixer) / VOL_SCALE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) if (val < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) else if (val > VOL_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) val = VOL_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) ucontrol->value.integer.value[i] = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) static int ct_alsa_mix_volume_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) struct ct_atc *atc = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) struct ct_mixer *mixer = atc->mixer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) enum CT_AMIXER_CTL type = get_amixer_index(kcontrol->private_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) struct amixer *amixer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) int i, j, val, oval, change = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) for (i = 0; i < 2; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) val = ucontrol->value.integer.value[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) if (val < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) else if (val > VOL_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) val = VOL_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) val *= VOL_SCALE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) amixer = mixer->amixers[type*CHN_NUM+i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) oval = amixer->ops->get_scale(amixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) if (val != oval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) amixer->ops->set_scale(amixer, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) amixer->ops->commit_write(amixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) change = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) /* Synchronize Master/PCM playback AMIXERs. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) if (AMIXER_MASTER_F == type || AMIXER_PCM_F == type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) for (j = 1; j < 4; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) amixer = mixer->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) amixers[(type+j)*CHN_NUM+i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) amixer->ops->set_scale(amixer, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) amixer->ops->commit_write(amixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) return change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) static struct snd_kcontrol_new vol_ctl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) SNDRV_CTL_ELEM_ACCESS_TLV_READ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) .info = ct_alsa_mix_volume_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) .get = ct_alsa_mix_volume_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) .put = ct_alsa_mix_volume_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) .tlv = { .p = ct_vol_db_scale },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) static int output_switch_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) struct snd_ctl_elem_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) static const char *const names[3] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) "FP Headphones", "Headphones", "Speakers"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) return snd_ctl_enum_info(info, 1, 3, names);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) static int output_switch_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) struct ct_atc *atc = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) ucontrol->value.enumerated.item[0] = atc->output_switch_get(atc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) static int output_switch_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) struct ct_atc *atc = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) if (ucontrol->value.enumerated.item[0] > 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) return atc->output_switch_put(atc, ucontrol->value.enumerated.item[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) static struct snd_kcontrol_new output_ctl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) .name = "Analog Output Playback Enum",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) .info = output_switch_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) .get = output_switch_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) .put = output_switch_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) static int mic_source_switch_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) struct snd_ctl_elem_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) static const char *const names[3] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) "Mic", "FP Mic", "Aux"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) return snd_ctl_enum_info(info, 1, 3, names);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) static int mic_source_switch_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) struct ct_atc *atc = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) ucontrol->value.enumerated.item[0] = atc->mic_source_switch_get(atc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) static int mic_source_switch_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) struct ct_atc *atc = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) if (ucontrol->value.enumerated.item[0] > 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) return atc->mic_source_switch_put(atc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) ucontrol->value.enumerated.item[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) static struct snd_kcontrol_new mic_source_ctl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) .name = "Mic Source Capture Enum",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) .info = mic_source_switch_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) .get = mic_source_switch_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) .put = mic_source_switch_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) do_line_mic_switch(struct ct_atc *atc, enum CTALSA_MIXER_CTL type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) if (MIXER_LINEIN_C_S == type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) atc->select_line_in(atc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) set_switch_state(atc->mixer, MIXER_MIC_C_S, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) snd_ctl_notify(atc->card, SNDRV_CTL_EVENT_MASK_VALUE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) &kctls[1]->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) } else if (MIXER_MIC_C_S == type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) atc->select_mic_in(atc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) set_switch_state(atc->mixer, MIXER_LINEIN_C_S, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) snd_ctl_notify(atc->card, SNDRV_CTL_EVENT_MASK_VALUE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) &kctls[0]->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) do_digit_io_switch(struct ct_atc *atc, int state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) struct ct_mixer *mixer = atc->mixer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) if (state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) atc->select_digit_io(atc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) atc->spdif_out_unmute(atc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) get_switch_state(mixer, MIXER_SPDIFO_P_S));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) atc->spdif_in_unmute(atc, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) atc->line_in_unmute(atc, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) if (get_switch_state(mixer, MIXER_LINEIN_C_S))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) atc->select_line_in(atc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) else if (get_switch_state(mixer, MIXER_MIC_C_S))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) atc->select_mic_in(atc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) atc->spdif_out_unmute(atc, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) atc->spdif_in_unmute(atc, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) atc->line_in_unmute(atc, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) static void do_switch(struct ct_atc *atc, enum CTALSA_MIXER_CTL type, int state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) struct ct_mixer *mixer = atc->mixer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) struct capabilities cap = atc->capabilities(atc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) /* Do changes in mixer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) if ((SWH_CAPTURE_START <= type) && (SWH_CAPTURE_END >= type)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) if (state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) ct_mixer_recording_select(mixer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) get_amixer_index(type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) ct_mixer_recording_unselect(mixer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) get_amixer_index(type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) /* Do changes out of mixer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) if (!cap.dedicated_mic &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) (MIXER_LINEIN_C_S == type || MIXER_MIC_C_S == type)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) if (state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) do_line_mic_switch(atc, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) atc->line_in_unmute(atc, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) } else if (cap.dedicated_mic && (MIXER_LINEIN_C_S == type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) atc->line_in_unmute(atc, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) else if (cap.dedicated_mic && (MIXER_MIC_C_S == type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) atc->mic_unmute(atc, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) else if (MIXER_SPDIFI_C_S == type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) atc->spdif_in_unmute(atc, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) else if (MIXER_WAVEF_P_S == type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) atc->line_front_unmute(atc, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) else if (MIXER_WAVES_P_S == type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) atc->line_surround_unmute(atc, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) else if (MIXER_WAVEC_P_S == type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) atc->line_clfe_unmute(atc, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) else if (MIXER_WAVER_P_S == type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) atc->line_rear_unmute(atc, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) else if (MIXER_SPDIFO_P_S == type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) atc->spdif_out_unmute(atc, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) else if (MIXER_DIGITAL_IO_S == type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) do_digit_io_switch(atc, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) static int ct_alsa_mix_switch_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) uinfo->count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) uinfo->value.integer.min = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) uinfo->value.integer.max = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) uinfo->value.integer.step = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) static int ct_alsa_mix_switch_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) struct ct_mixer *mixer =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) ((struct ct_atc *)snd_kcontrol_chip(kcontrol))->mixer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) enum CTALSA_MIXER_CTL type = kcontrol->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) ucontrol->value.integer.value[0] = get_switch_state(mixer, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) static int ct_alsa_mix_switch_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) struct ct_atc *atc = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) struct ct_mixer *mixer = atc->mixer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) enum CTALSA_MIXER_CTL type = kcontrol->private_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) int state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) state = ucontrol->value.integer.value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) if (get_switch_state(mixer, type) == state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) set_switch_state(mixer, type, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) do_switch(atc, type, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) static struct snd_kcontrol_new swh_ctl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) .info = ct_alsa_mix_switch_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) .get = ct_alsa_mix_switch_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) .put = ct_alsa_mix_switch_put
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) static int ct_spdif_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) uinfo->count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) static int ct_spdif_get_mask(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) ucontrol->value.iec958.status[0] = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) ucontrol->value.iec958.status[1] = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) ucontrol->value.iec958.status[2] = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) ucontrol->value.iec958.status[3] = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) static int ct_spdif_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) struct ct_atc *atc = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) unsigned int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) atc->spdif_out_get_status(atc, &status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) if (status == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) status = SNDRV_PCM_DEFAULT_CON_SPDIF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) ucontrol->value.iec958.status[0] = (status >> 0) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) ucontrol->value.iec958.status[1] = (status >> 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) ucontrol->value.iec958.status[2] = (status >> 16) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) ucontrol->value.iec958.status[3] = (status >> 24) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) static int ct_spdif_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) struct ct_atc *atc = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) int change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) unsigned int status, old_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) status = (ucontrol->value.iec958.status[0] << 0) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) (ucontrol->value.iec958.status[1] << 8) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) (ucontrol->value.iec958.status[2] << 16) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) (ucontrol->value.iec958.status[3] << 24);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) atc->spdif_out_get_status(atc, &old_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) change = (old_status != status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) if (change)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) atc->spdif_out_set_status(atc, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) return change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) static struct snd_kcontrol_new iec958_mask_ctl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) .access = SNDRV_CTL_ELEM_ACCESS_READ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) .iface = SNDRV_CTL_ELEM_IFACE_PCM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, MASK),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) .count = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) .info = ct_spdif_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) .get = ct_spdif_get_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) .private_value = MIXER_IEC958_MASK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) static struct snd_kcontrol_new iec958_default_ctl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) .iface = SNDRV_CTL_ELEM_IFACE_PCM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) .count = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) .info = ct_spdif_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) .get = ct_spdif_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) .put = ct_spdif_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) .private_value = MIXER_IEC958_DEFAULT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) static struct snd_kcontrol_new iec958_ctl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) .iface = SNDRV_CTL_ELEM_IFACE_PCM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) .count = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) .info = ct_spdif_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) .get = ct_spdif_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) .put = ct_spdif_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) .private_value = MIXER_IEC958_STREAM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) #define NUM_IEC958_CTL 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) ct_mixer_kcontrol_new(struct ct_mixer *mixer, struct snd_kcontrol_new *new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) struct snd_kcontrol *kctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) kctl = snd_ctl_new1(new, mixer->atc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) if (!kctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) if (SNDRV_CTL_ELEM_IFACE_PCM == kctl->id.iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) kctl->id.device = IEC958;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) err = snd_ctl_add(mixer->atc->card, kctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) switch (new->private_value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) case MIXER_LINEIN_C_S:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) kctls[0] = kctl; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) case MIXER_MIC_C_S:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) kctls[1] = kctl; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) static int ct_mixer_kcontrols_create(struct ct_mixer *mixer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) enum CTALSA_MIXER_CTL type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) struct ct_atc *atc = mixer->atc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) struct capabilities cap = atc->capabilities(atc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) /* Create snd kcontrol instances on demand */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) for (type = VOL_MIXER_START; type <= VOL_MIXER_END; type++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) if (ct_kcontrol_init_table[type].ctl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) vol_ctl.name = ct_kcontrol_init_table[type].name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) vol_ctl.private_value = (unsigned long)type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) err = ct_mixer_kcontrol_new(mixer, &vol_ctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) ct_kcontrol_init_table[MIXER_DIGITAL_IO_S].ctl = cap.digit_io_switch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) for (type = SWH_MIXER_START; type <= SWH_MIXER_END; type++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) if (ct_kcontrol_init_table[type].ctl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) swh_ctl.name = ct_kcontrol_init_table[type].name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) swh_ctl.private_value = (unsigned long)type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) err = ct_mixer_kcontrol_new(mixer, &swh_ctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) }
^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) err = ct_mixer_kcontrol_new(mixer, &iec958_mask_ctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) err = ct_mixer_kcontrol_new(mixer, &iec958_default_ctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) err = ct_mixer_kcontrol_new(mixer, &iec958_ctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) if (cap.output_switch) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) err = ct_mixer_kcontrol_new(mixer, &output_ctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) if (cap.mic_source_switch) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) err = ct_mixer_kcontrol_new(mixer, &mic_source_ctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) atc->line_front_unmute(atc, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) set_switch_state(mixer, MIXER_WAVEF_P_S, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) atc->line_surround_unmute(atc, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) set_switch_state(mixer, MIXER_WAVES_P_S, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) atc->line_clfe_unmute(atc, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) set_switch_state(mixer, MIXER_WAVEC_P_S, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) atc->line_rear_unmute(atc, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) set_switch_state(mixer, MIXER_WAVER_P_S, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) atc->spdif_out_unmute(atc, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) set_switch_state(mixer, MIXER_SPDIFO_P_S, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) atc->line_in_unmute(atc, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) if (cap.dedicated_mic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) atc->mic_unmute(atc, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) atc->spdif_in_unmute(atc, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) set_switch_state(mixer, MIXER_PCM_C_S, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) set_switch_state(mixer, MIXER_LINEIN_C_S, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) set_switch_state(mixer, MIXER_SPDIFI_C_S, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) ct_mixer_recording_select(struct ct_mixer *mixer, enum CT_AMIXER_CTL type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) struct amixer *amix_d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) struct sum *sum_c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) for (i = 0; i < 2; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) amix_d = mixer->amixers[type*CHN_NUM+i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) sum_c = mixer->sums[SUM_IN_F_C*CHN_NUM+i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) amix_d->ops->set_sum(amix_d, sum_c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) amix_d->ops->commit_write(amix_d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) ct_mixer_recording_unselect(struct ct_mixer *mixer, enum CT_AMIXER_CTL type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) struct amixer *amix_d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) for (i = 0; i < 2; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) amix_d = mixer->amixers[type*CHN_NUM+i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) amix_d->ops->set_sum(amix_d, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) amix_d->ops->commit_write(amix_d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) static int ct_mixer_get_resources(struct ct_mixer *mixer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) struct sum_mgr *sum_mgr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) struct sum *sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) struct sum_desc sum_desc = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) struct amixer_mgr *amixer_mgr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) struct amixer *amixer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) struct amixer_desc am_desc = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) /* Allocate sum resources for mixer obj */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) sum_mgr = (struct sum_mgr *)mixer->atc->rsc_mgrs[SUM];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) sum_desc.msr = mixer->atc->msr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) for (i = 0; i < (NUM_CT_SUMS * CHN_NUM); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) err = sum_mgr->get_sum(sum_mgr, &sum_desc, &sum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) dev_err(mixer->atc->card->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) "Failed to get sum resources for front output!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) mixer->sums[i] = sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) goto error1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) /* Allocate amixer resources for mixer obj */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) amixer_mgr = (struct amixer_mgr *)mixer->atc->rsc_mgrs[AMIXER];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) am_desc.msr = mixer->atc->msr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) for (i = 0; i < (NUM_CT_AMIXERS * CHN_NUM); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) err = amixer_mgr->get_amixer(amixer_mgr, &am_desc, &amixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) dev_err(mixer->atc->card->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) "Failed to get amixer resources for mixer obj!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) mixer->amixers[i] = amixer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) goto error2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) error2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) for (i = 0; i < (NUM_CT_AMIXERS * CHN_NUM); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) if (NULL != mixer->amixers[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) amixer = mixer->amixers[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) amixer_mgr->put_amixer(amixer_mgr, amixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) mixer->amixers[i] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) error1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) for (i = 0; i < (NUM_CT_SUMS * CHN_NUM); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) if (NULL != mixer->sums[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) sum_mgr->put_sum(sum_mgr, (struct sum *)mixer->sums[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) mixer->sums[i] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) static int ct_mixer_get_mem(struct ct_mixer **rmixer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) struct ct_mixer *mixer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) *rmixer = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) /* Allocate mem for mixer obj */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) mixer = kzalloc(sizeof(*mixer), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) if (!mixer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) mixer->amixers = kcalloc(NUM_CT_AMIXERS * CHN_NUM, sizeof(void *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) if (!mixer->amixers) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) goto error1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) mixer->sums = kcalloc(NUM_CT_SUMS * CHN_NUM, sizeof(void *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) if (!mixer->sums) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) goto error2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) *rmixer = mixer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) error2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) kfree(mixer->amixers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) error1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) kfree(mixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) static int ct_mixer_topology_build(struct ct_mixer *mixer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) struct sum *sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) struct amixer *amix_d, *amix_s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) enum CT_AMIXER_CTL i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) enum CT_SUM_CTL k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) /* Build topology from destination to source */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) /* Set up Master mixer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) for (i = AMIXER_MASTER_F, k = SUM_IN_F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) i <= AMIXER_MASTER_S; i++, k++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) amix_d = mixer->amixers[i*CHN_NUM];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) sum = mixer->sums[k*CHN_NUM];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) amix_d->ops->setup(amix_d, &sum->rsc, INIT_VOL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) amix_d = mixer->amixers[i*CHN_NUM+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) sum = mixer->sums[k*CHN_NUM+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) amix_d->ops->setup(amix_d, &sum->rsc, INIT_VOL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) /* Set up Wave-out mixer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) for (i = AMIXER_WAVE_F, j = AMIXER_MASTER_F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) i <= AMIXER_WAVE_S; i++, j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) amix_d = mixer->amixers[i*CHN_NUM];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) amix_s = mixer->amixers[j*CHN_NUM];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) amix_d->ops->setup(amix_d, &amix_s->rsc, INIT_VOL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) amix_d = mixer->amixers[i*CHN_NUM+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) amix_s = mixer->amixers[j*CHN_NUM+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) amix_d->ops->setup(amix_d, &amix_s->rsc, INIT_VOL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) /* Set up S/PDIF-out mixer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) amix_d = mixer->amixers[AMIXER_SPDIFO*CHN_NUM];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) amix_s = mixer->amixers[AMIXER_MASTER_F*CHN_NUM];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) amix_d->ops->setup(amix_d, &amix_s->rsc, INIT_VOL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) amix_d = mixer->amixers[AMIXER_SPDIFO*CHN_NUM+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) amix_s = mixer->amixers[AMIXER_MASTER_F*CHN_NUM+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) amix_d->ops->setup(amix_d, &amix_s->rsc, INIT_VOL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) /* Set up PCM-in mixer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) for (i = AMIXER_PCM_F, k = SUM_IN_F; i <= AMIXER_PCM_S; i++, k++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) amix_d = mixer->amixers[i*CHN_NUM];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) sum = mixer->sums[k*CHN_NUM];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) amix_d->ops->setup(amix_d, NULL, INIT_VOL, sum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) amix_d = mixer->amixers[i*CHN_NUM+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) sum = mixer->sums[k*CHN_NUM+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) amix_d->ops->setup(amix_d, NULL, INIT_VOL, sum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) /* Set up Line-in mixer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) amix_d = mixer->amixers[AMIXER_LINEIN*CHN_NUM];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) sum = mixer->sums[SUM_IN_F*CHN_NUM];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) amix_d->ops->setup(amix_d, NULL, INIT_VOL, sum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) amix_d = mixer->amixers[AMIXER_LINEIN*CHN_NUM+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) sum = mixer->sums[SUM_IN_F*CHN_NUM+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) amix_d->ops->setup(amix_d, NULL, INIT_VOL, sum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) /* Set up Mic-in mixer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) amix_d = mixer->amixers[AMIXER_MIC*CHN_NUM];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) sum = mixer->sums[SUM_IN_F*CHN_NUM];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) amix_d->ops->setup(amix_d, NULL, INIT_VOL, sum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) amix_d = mixer->amixers[AMIXER_MIC*CHN_NUM+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) sum = mixer->sums[SUM_IN_F*CHN_NUM+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) amix_d->ops->setup(amix_d, NULL, INIT_VOL, sum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) /* Set up S/PDIF-in mixer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) amix_d = mixer->amixers[AMIXER_SPDIFI*CHN_NUM];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) sum = mixer->sums[SUM_IN_F*CHN_NUM];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) amix_d->ops->setup(amix_d, NULL, INIT_VOL, sum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) amix_d = mixer->amixers[AMIXER_SPDIFI*CHN_NUM+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) sum = mixer->sums[SUM_IN_F*CHN_NUM+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) amix_d->ops->setup(amix_d, NULL, INIT_VOL, sum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) /* Set up Master recording mixer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) amix_d = mixer->amixers[AMIXER_MASTER_F_C*CHN_NUM];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) sum = mixer->sums[SUM_IN_F_C*CHN_NUM];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) amix_d->ops->setup(amix_d, &sum->rsc, INIT_VOL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) amix_d = mixer->amixers[AMIXER_MASTER_F_C*CHN_NUM+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) sum = mixer->sums[SUM_IN_F_C*CHN_NUM+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) amix_d->ops->setup(amix_d, &sum->rsc, INIT_VOL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) /* Set up PCM-in recording mixer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) amix_d = mixer->amixers[AMIXER_PCM_F_C*CHN_NUM];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) sum = mixer->sums[SUM_IN_F_C*CHN_NUM];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) amix_d->ops->setup(amix_d, NULL, INIT_VOL, sum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) amix_d = mixer->amixers[AMIXER_PCM_F_C*CHN_NUM+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) sum = mixer->sums[SUM_IN_F_C*CHN_NUM+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) amix_d->ops->setup(amix_d, NULL, INIT_VOL, sum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) /* Set up Line-in recording mixer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) amix_d = mixer->amixers[AMIXER_LINEIN_C*CHN_NUM];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) sum = mixer->sums[SUM_IN_F_C*CHN_NUM];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) amix_d->ops->setup(amix_d, NULL, INIT_VOL, sum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) amix_d = mixer->amixers[AMIXER_LINEIN_C*CHN_NUM+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) sum = mixer->sums[SUM_IN_F_C*CHN_NUM+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) amix_d->ops->setup(amix_d, NULL, INIT_VOL, sum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) /* Set up Mic-in recording mixer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) amix_d = mixer->amixers[AMIXER_MIC_C*CHN_NUM];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) sum = mixer->sums[SUM_IN_F_C*CHN_NUM];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) amix_d->ops->setup(amix_d, NULL, INIT_VOL, sum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) amix_d = mixer->amixers[AMIXER_MIC_C*CHN_NUM+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) sum = mixer->sums[SUM_IN_F_C*CHN_NUM+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) amix_d->ops->setup(amix_d, NULL, INIT_VOL, sum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) /* Set up S/PDIF-in recording mixer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) amix_d = mixer->amixers[AMIXER_SPDIFI_C*CHN_NUM];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) sum = mixer->sums[SUM_IN_F_C*CHN_NUM];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) amix_d->ops->setup(amix_d, NULL, INIT_VOL, sum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) amix_d = mixer->amixers[AMIXER_SPDIFI_C*CHN_NUM+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) sum = mixer->sums[SUM_IN_F_C*CHN_NUM+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) amix_d->ops->setup(amix_d, NULL, INIT_VOL, sum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) static int mixer_set_input_port(struct amixer *amixer, struct rsc *rsc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) amixer->ops->set_input(amixer, rsc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) amixer->ops->commit_write(amixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) static enum CT_AMIXER_CTL port_to_amixer(enum MIXER_PORT_T type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) case MIX_WAVE_FRONT: return AMIXER_WAVE_F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) case MIX_WAVE_SURROUND: return AMIXER_WAVE_S;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) case MIX_WAVE_CENTLFE: return AMIXER_WAVE_C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) case MIX_WAVE_REAR: return AMIXER_WAVE_R;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) case MIX_PCMO_FRONT: return AMIXER_MASTER_F_C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) case MIX_SPDIF_OUT: return AMIXER_SPDIFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) case MIX_LINE_IN: return AMIXER_LINEIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) case MIX_MIC_IN: return AMIXER_MIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) case MIX_SPDIF_IN: return AMIXER_SPDIFI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) case MIX_PCMI_FRONT: return AMIXER_PCM_F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) case MIX_PCMI_SURROUND: return AMIXER_PCM_S;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) case MIX_PCMI_CENTLFE: return AMIXER_PCM_C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) case MIX_PCMI_REAR: return AMIXER_PCM_R;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) default: return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) static int mixer_get_output_ports(struct ct_mixer *mixer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) enum MIXER_PORT_T type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) struct rsc **rleft, struct rsc **rright)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) enum CT_AMIXER_CTL amix = port_to_amixer(type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) if (NULL != rleft)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) *rleft = &((struct amixer *)mixer->amixers[amix*CHN_NUM])->rsc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) if (NULL != rright)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) *rright =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) &((struct amixer *)mixer->amixers[amix*CHN_NUM+1])->rsc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) static int mixer_set_input_left(struct ct_mixer *mixer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) enum MIXER_PORT_T type, struct rsc *rsc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) enum CT_AMIXER_CTL amix = port_to_amixer(type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) mixer_set_input_port(mixer->amixers[amix*CHN_NUM], rsc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) amix = get_recording_amixer(amix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) if (amix < NUM_CT_AMIXERS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) mixer_set_input_port(mixer->amixers[amix*CHN_NUM], rsc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) mixer_set_input_right(struct ct_mixer *mixer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) enum MIXER_PORT_T type, struct rsc *rsc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) enum CT_AMIXER_CTL amix = port_to_amixer(type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) mixer_set_input_port(mixer->amixers[amix*CHN_NUM+1], rsc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) amix = get_recording_amixer(amix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) if (amix < NUM_CT_AMIXERS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) mixer_set_input_port(mixer->amixers[amix*CHN_NUM+1], rsc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) static int mixer_resume(struct ct_mixer *mixer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) int i, state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) struct amixer *amixer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) /* resume topology and volume gain. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) for (i = 0; i < NUM_CT_AMIXERS*CHN_NUM; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) amixer = mixer->amixers[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) amixer->ops->commit_write(amixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) /* resume switch state. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) for (i = SWH_MIXER_START; i <= SWH_MIXER_END; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) state = get_switch_state(mixer, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) do_switch(mixer->atc, i, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) int ct_mixer_destroy(struct ct_mixer *mixer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) struct sum_mgr *sum_mgr = (struct sum_mgr *)mixer->atc->rsc_mgrs[SUM];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) struct amixer_mgr *amixer_mgr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) (struct amixer_mgr *)mixer->atc->rsc_mgrs[AMIXER];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) struct amixer *amixer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) /* Release amixer resources */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) for (i = 0; i < (NUM_CT_AMIXERS * CHN_NUM); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) if (NULL != mixer->amixers[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) amixer = mixer->amixers[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) amixer_mgr->put_amixer(amixer_mgr, amixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) /* Release sum resources */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) for (i = 0; i < (NUM_CT_SUMS * CHN_NUM); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) if (NULL != mixer->sums[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) sum_mgr->put_sum(sum_mgr, (struct sum *)mixer->sums[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) /* Release mem assigned to mixer object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) kfree(mixer->sums);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) kfree(mixer->amixers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) kfree(mixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) int ct_mixer_create(struct ct_atc *atc, struct ct_mixer **rmixer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) struct ct_mixer *mixer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) *rmixer = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) /* Allocate mem for mixer obj */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) err = ct_mixer_get_mem(&mixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) mixer->switch_state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) mixer->atc = atc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) /* Set operations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) mixer->get_output_ports = mixer_get_output_ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) mixer->set_input_left = mixer_set_input_left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) mixer->set_input_right = mixer_set_input_right;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) mixer->resume = mixer_resume;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) /* Allocate chip resources for mixer obj */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) err = ct_mixer_get_resources(mixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) /* Build internal mixer topology */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) ct_mixer_topology_build(mixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) *rmixer = mixer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) ct_mixer_destroy(mixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) int ct_alsa_mix_create(struct ct_atc *atc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) enum CTALSADEVS device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) const char *device_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) /* Create snd kcontrol instances on demand */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) /* vol_ctl.device = swh_ctl.device = device; */ /* better w/ device 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) err = ct_mixer_kcontrols_create((struct ct_mixer *)atc->mixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) strcpy(atc->card->mixername, device_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) }