162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
462306a36Sopenharmony_ci *  Universal interface for Audio Codec '97
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci *  For more details look to AC '97 component specification revision 2.2
762306a36Sopenharmony_ci *  by Intel Corporation (http://developer.intel.com).
862306a36Sopenharmony_ci */
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#define AC97_SINGLE_VALUE(reg,shift,mask,invert) \
1162306a36Sopenharmony_ci	((reg) | ((shift) << 8) | ((shift) << 12) | ((mask) << 16) | \
1262306a36Sopenharmony_ci	 ((invert) << 24))
1362306a36Sopenharmony_ci#define AC97_PAGE_SINGLE_VALUE(reg,shift,mask,invert,page) \
1462306a36Sopenharmony_ci	(AC97_SINGLE_VALUE(reg,shift,mask,invert) | (1<<25) | ((page) << 26))
1562306a36Sopenharmony_ci#define AC97_SINGLE(xname, reg, shift, mask, invert) \
1662306a36Sopenharmony_ci{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1762306a36Sopenharmony_ci  .info = snd_ac97_info_volsw,		\
1862306a36Sopenharmony_ci  .get = snd_ac97_get_volsw, .put = snd_ac97_put_volsw, \
1962306a36Sopenharmony_ci  .private_value =  AC97_SINGLE_VALUE(reg, shift, mask, invert) }
2062306a36Sopenharmony_ci#define AC97_PAGE_SINGLE(xname, reg, shift, mask, invert, page)		\
2162306a36Sopenharmony_ci{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
2262306a36Sopenharmony_ci  .info = snd_ac97_info_volsw,		\
2362306a36Sopenharmony_ci  .get = snd_ac97_get_volsw, .put = snd_ac97_put_volsw, \
2462306a36Sopenharmony_ci  .private_value =  AC97_PAGE_SINGLE_VALUE(reg, shift, mask, invert, page) }
2562306a36Sopenharmony_ci#define AC97_DOUBLE(xname, reg, shift_left, shift_right, mask, invert) \
2662306a36Sopenharmony_ci{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
2762306a36Sopenharmony_ci  .info = snd_ac97_info_volsw,		\
2862306a36Sopenharmony_ci  .get = snd_ac97_get_volsw, .put = snd_ac97_put_volsw, \
2962306a36Sopenharmony_ci  .private_value = (reg) | ((shift_left) << 8) | ((shift_right) << 12) | ((mask) << 16) | ((invert) << 24) }
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci/* enum control */
3262306a36Sopenharmony_cistruct ac97_enum {
3362306a36Sopenharmony_ci	unsigned char reg;
3462306a36Sopenharmony_ci	unsigned char shift_l;
3562306a36Sopenharmony_ci	unsigned char shift_r;
3662306a36Sopenharmony_ci	unsigned short mask;
3762306a36Sopenharmony_ci	const char * const *texts;
3862306a36Sopenharmony_ci};
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ci#define AC97_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, xtexts) \
4162306a36Sopenharmony_ci{ .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
4262306a36Sopenharmony_ci  .mask = xmask, .texts = xtexts }
4362306a36Sopenharmony_ci#define AC97_ENUM_SINGLE(xreg, xshift, xmask, xtexts) \
4462306a36Sopenharmony_ci	AC97_ENUM_DOUBLE(xreg, xshift, xshift, xmask, xtexts)
4562306a36Sopenharmony_ci#define AC97_ENUM(xname, xenum) \
4662306a36Sopenharmony_ci{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
4762306a36Sopenharmony_ci  .info = snd_ac97_info_enum_double,		    \
4862306a36Sopenharmony_ci  .get = snd_ac97_get_enum_double, .put = snd_ac97_put_enum_double, \
4962306a36Sopenharmony_ci  .private_value = (unsigned long)&xenum }
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci/* ac97_codec.c */
5262306a36Sopenharmony_cistatic const struct snd_kcontrol_new snd_ac97_controls_3d[];
5362306a36Sopenharmony_cistatic const struct snd_kcontrol_new snd_ac97_controls_spdif[];
5462306a36Sopenharmony_cistatic struct snd_kcontrol *snd_ac97_cnew(const struct snd_kcontrol_new *_template,
5562306a36Sopenharmony_ci					  struct snd_ac97 * ac97);
5662306a36Sopenharmony_cistatic int snd_ac97_info_volsw(struct snd_kcontrol *kcontrol,
5762306a36Sopenharmony_ci			       struct snd_ctl_elem_info *uinfo);
5862306a36Sopenharmony_cistatic int snd_ac97_get_volsw(struct snd_kcontrol *kcontrol,
5962306a36Sopenharmony_ci			      struct snd_ctl_elem_value *ucontrol);
6062306a36Sopenharmony_cistatic int snd_ac97_put_volsw(struct snd_kcontrol *kcontrol,
6162306a36Sopenharmony_ci			      struct snd_ctl_elem_value *ucontrol);
6262306a36Sopenharmony_cistatic int snd_ac97_try_bit(struct snd_ac97 * ac97, int reg, int bit);
6362306a36Sopenharmony_cistatic int snd_ac97_remove_ctl(struct snd_ac97 *ac97, const char *name,
6462306a36Sopenharmony_ci			       const char *suffix);
6562306a36Sopenharmony_cistatic int snd_ac97_rename_ctl(struct snd_ac97 *ac97, const char *src,
6662306a36Sopenharmony_ci			       const char *dst, const char *suffix);
6762306a36Sopenharmony_cistatic int snd_ac97_swap_ctl(struct snd_ac97 *ac97, const char *s1,
6862306a36Sopenharmony_ci			     const char *s2, const char *suffix);
6962306a36Sopenharmony_cistatic void snd_ac97_rename_vol_ctl(struct snd_ac97 *ac97, const char *src,
7062306a36Sopenharmony_ci				    const char *dst);
7162306a36Sopenharmony_ci#ifdef CONFIG_PM
7262306a36Sopenharmony_cistatic void snd_ac97_restore_status(struct snd_ac97 *ac97);
7362306a36Sopenharmony_cistatic void snd_ac97_restore_iec958(struct snd_ac97 *ac97);
7462306a36Sopenharmony_ci#endif
7562306a36Sopenharmony_cistatic int snd_ac97_info_enum_double(struct snd_kcontrol *kcontrol,
7662306a36Sopenharmony_ci				     struct snd_ctl_elem_info *uinfo);
7762306a36Sopenharmony_cistatic int snd_ac97_get_enum_double(struct snd_kcontrol *kcontrol,
7862306a36Sopenharmony_ci				    struct snd_ctl_elem_value *ucontrol);
7962306a36Sopenharmony_cistatic int snd_ac97_put_enum_double(struct snd_kcontrol *kcontrol,
8062306a36Sopenharmony_ci				    struct snd_ctl_elem_value *ucontrol);
81