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

source code of linux/sound/pci/ac97/ac97_patch.h