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