1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-or-later */ 2*4882a593Smuzhiyun /* 3*4882a593Smuzhiyun * Copyright (c) by Jaroslav Kysela <perex@perex.cz> 4*4882a593Smuzhiyun * Universal interface for Audio Codec '97 5*4882a593Smuzhiyun * 6*4882a593Smuzhiyun * For more details look to AC '97 component specification revision 2.2 7*4882a593Smuzhiyun * by Intel Corporation (http://developer.intel.com). 8*4882a593Smuzhiyun */ 9*4882a593Smuzhiyun 10*4882a593Smuzhiyun #define AC97_SINGLE_VALUE(reg,shift,mask,invert) \ 11*4882a593Smuzhiyun ((reg) | ((shift) << 8) | ((shift) << 12) | ((mask) << 16) | \ 12*4882a593Smuzhiyun ((invert) << 24)) 13*4882a593Smuzhiyun #define AC97_PAGE_SINGLE_VALUE(reg,shift,mask,invert,page) \ 14*4882a593Smuzhiyun (AC97_SINGLE_VALUE(reg,shift,mask,invert) | (1<<25) | ((page) << 26)) 15*4882a593Smuzhiyun #define AC97_SINGLE(xname, reg, shift, mask, invert) \ 16*4882a593Smuzhiyun { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 17*4882a593Smuzhiyun .info = snd_ac97_info_volsw, \ 18*4882a593Smuzhiyun .get = snd_ac97_get_volsw, .put = snd_ac97_put_volsw, \ 19*4882a593Smuzhiyun .private_value = AC97_SINGLE_VALUE(reg, shift, mask, invert) } 20*4882a593Smuzhiyun #define AC97_PAGE_SINGLE(xname, reg, shift, mask, invert, page) \ 21*4882a593Smuzhiyun { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 22*4882a593Smuzhiyun .info = snd_ac97_info_volsw, \ 23*4882a593Smuzhiyun .get = snd_ac97_get_volsw, .put = snd_ac97_put_volsw, \ 24*4882a593Smuzhiyun .private_value = AC97_PAGE_SINGLE_VALUE(reg, shift, mask, invert, page) } 25*4882a593Smuzhiyun #define AC97_DOUBLE(xname, reg, shift_left, shift_right, mask, invert) \ 26*4882a593Smuzhiyun { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \ 27*4882a593Smuzhiyun .info = snd_ac97_info_volsw, \ 28*4882a593Smuzhiyun .get = snd_ac97_get_volsw, .put = snd_ac97_put_volsw, \ 29*4882a593Smuzhiyun .private_value = (reg) | ((shift_left) << 8) | ((shift_right) << 12) | ((mask) << 16) | ((invert) << 24) } 30*4882a593Smuzhiyun 31*4882a593Smuzhiyun /* enum control */ 32*4882a593Smuzhiyun struct ac97_enum { 33*4882a593Smuzhiyun unsigned char reg; 34*4882a593Smuzhiyun unsigned char shift_l; 35*4882a593Smuzhiyun unsigned char shift_r; 36*4882a593Smuzhiyun unsigned short mask; 37*4882a593Smuzhiyun const char * const *texts; 38*4882a593Smuzhiyun }; 39*4882a593Smuzhiyun 40*4882a593Smuzhiyun #define AC97_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, xtexts) \ 41*4882a593Smuzhiyun { .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \ 42*4882a593Smuzhiyun .mask = xmask, .texts = xtexts } 43*4882a593Smuzhiyun #define AC97_ENUM_SINGLE(xreg, xshift, xmask, xtexts) \ 44*4882a593Smuzhiyun AC97_ENUM_DOUBLE(xreg, xshift, xshift, xmask, xtexts) 45*4882a593Smuzhiyun #define AC97_ENUM(xname, xenum) \ 46*4882a593Smuzhiyun { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 47*4882a593Smuzhiyun .info = snd_ac97_info_enum_double, \ 48*4882a593Smuzhiyun .get = snd_ac97_get_enum_double, .put = snd_ac97_put_enum_double, \ 49*4882a593Smuzhiyun .private_value = (unsigned long)&xenum } 50*4882a593Smuzhiyun 51*4882a593Smuzhiyun /* ac97_codec.c */ 52*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_controls_3d[]; 53*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_controls_spdif[]; 54*4882a593Smuzhiyun static struct snd_kcontrol *snd_ac97_cnew(const struct snd_kcontrol_new *_template, 55*4882a593Smuzhiyun struct snd_ac97 * ac97); 56*4882a593Smuzhiyun static int snd_ac97_info_volsw(struct snd_kcontrol *kcontrol, 57*4882a593Smuzhiyun struct snd_ctl_elem_info *uinfo); 58*4882a593Smuzhiyun static int snd_ac97_get_volsw(struct snd_kcontrol *kcontrol, 59*4882a593Smuzhiyun struct snd_ctl_elem_value *ucontrol); 60*4882a593Smuzhiyun static int snd_ac97_put_volsw(struct snd_kcontrol *kcontrol, 61*4882a593Smuzhiyun struct snd_ctl_elem_value *ucontrol); 62*4882a593Smuzhiyun static int snd_ac97_try_bit(struct snd_ac97 * ac97, int reg, int bit); 63*4882a593Smuzhiyun static int snd_ac97_remove_ctl(struct snd_ac97 *ac97, const char *name, 64*4882a593Smuzhiyun const char *suffix); 65*4882a593Smuzhiyun static int snd_ac97_rename_ctl(struct snd_ac97 *ac97, const char *src, 66*4882a593Smuzhiyun const char *dst, const char *suffix); 67*4882a593Smuzhiyun static int snd_ac97_swap_ctl(struct snd_ac97 *ac97, const char *s1, 68*4882a593Smuzhiyun const char *s2, const char *suffix); 69*4882a593Smuzhiyun static void snd_ac97_rename_vol_ctl(struct snd_ac97 *ac97, const char *src, 70*4882a593Smuzhiyun const char *dst); 71*4882a593Smuzhiyun #ifdef CONFIG_PM 72*4882a593Smuzhiyun static void snd_ac97_restore_status(struct snd_ac97 *ac97); 73*4882a593Smuzhiyun static void snd_ac97_restore_iec958(struct snd_ac97 *ac97); 74*4882a593Smuzhiyun #endif 75*4882a593Smuzhiyun static int snd_ac97_info_enum_double(struct snd_kcontrol *kcontrol, 76*4882a593Smuzhiyun struct snd_ctl_elem_info *uinfo); 77*4882a593Smuzhiyun static int snd_ac97_get_enum_double(struct snd_kcontrol *kcontrol, 78*4882a593Smuzhiyun struct snd_ctl_elem_value *ucontrol); 79*4882a593Smuzhiyun static int snd_ac97_put_enum_double(struct snd_kcontrol *kcontrol, 80*4882a593Smuzhiyun struct snd_ctl_elem_value *ucontrol); 81