11da177e4SLinus Torvalds /* 2*c1017a4cSJaroslav Kysela * Copyright (c) by Jaroslav Kysela <perex@perex.cz> 31da177e4SLinus Torvalds * Universal interface for Audio Codec '97 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * For more details look to AC '97 component specification revision 2.2 61da177e4SLinus Torvalds * by Intel Corporation (http://developer.intel.com). 71da177e4SLinus Torvalds * 81da177e4SLinus Torvalds * 91da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify 101da177e4SLinus Torvalds * it under the terms of the GNU General Public License as published by 111da177e4SLinus Torvalds * the Free Software Foundation; either version 2 of the License, or 121da177e4SLinus Torvalds * (at your option) any later version. 131da177e4SLinus Torvalds * 141da177e4SLinus Torvalds * This program is distributed in the hope that it will be useful, 151da177e4SLinus Torvalds * but WITHOUT ANY WARRANTY; without even the implied warranty of 161da177e4SLinus Torvalds * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 171da177e4SLinus Torvalds * GNU General Public License for more details. 181da177e4SLinus Torvalds * 191da177e4SLinus Torvalds * You should have received a copy of the GNU General Public License 201da177e4SLinus Torvalds * along with this program; if not, write to the Free Software 211da177e4SLinus Torvalds * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 221da177e4SLinus Torvalds * 231da177e4SLinus Torvalds */ 241da177e4SLinus Torvalds 25ac519028STakashi Iwai #define AC97_SINGLE_VALUE(reg,shift,mask,invert) \ 26ac519028STakashi Iwai ((reg) | ((shift) << 8) | ((shift) << 12) | ((mask) << 16) | \ 27ac519028STakashi Iwai ((invert) << 24)) 28ac519028STakashi Iwai #define AC97_PAGE_SINGLE_VALUE(reg,shift,mask,invert,page) \ 29ac519028STakashi Iwai (AC97_SINGLE_VALUE(reg,shift,mask,invert) | (1<<25) | ((page) << 26)) 30ac519028STakashi Iwai #define AC97_SINGLE(xname, reg, shift, mask, invert) \ 31ac519028STakashi Iwai { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 32ac519028STakashi Iwai .info = snd_ac97_info_volsw, \ 33ac519028STakashi Iwai .get = snd_ac97_get_volsw, .put = snd_ac97_put_volsw, \ 34ac519028STakashi Iwai .private_value = AC97_SINGLE_VALUE(reg, shift, mask, invert) } 35ac519028STakashi Iwai #define AC97_PAGE_SINGLE(xname, reg, shift, mask, invert, page) \ 36ac519028STakashi Iwai { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 37ac519028STakashi Iwai .info = snd_ac97_info_volsw, \ 38ac519028STakashi Iwai .get = snd_ac97_get_volsw, .put = snd_ac97_put_volsw, \ 39ac519028STakashi Iwai .private_value = AC97_PAGE_SINGLE_VALUE(reg, shift, mask, invert, page) } 40ac519028STakashi Iwai #define AC97_DOUBLE(xname, reg, shift_left, shift_right, mask, invert) \ 41ac519028STakashi Iwai { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \ 42ac519028STakashi Iwai .info = snd_ac97_info_volsw, \ 43ac519028STakashi Iwai .get = snd_ac97_get_volsw, .put = snd_ac97_put_volsw, \ 44ac519028STakashi Iwai .private_value = (reg) | ((shift_left) << 8) | ((shift_right) << 12) | ((mask) << 16) | ((invert) << 24) } 45ac519028STakashi Iwai 46ac519028STakashi Iwai /* enum control */ 47ac519028STakashi Iwai struct ac97_enum { 48ac519028STakashi Iwai unsigned char reg; 49ac519028STakashi Iwai unsigned char shift_l; 50ac519028STakashi Iwai unsigned char shift_r; 51ac519028STakashi Iwai unsigned short mask; 52ac519028STakashi Iwai const char **texts; 53ac519028STakashi Iwai }; 54ac519028STakashi Iwai 55ac519028STakashi Iwai #define AC97_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, xtexts) \ 56ac519028STakashi Iwai { .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \ 57ac519028STakashi Iwai .mask = xmask, .texts = xtexts } 58ac519028STakashi Iwai #define AC97_ENUM_SINGLE(xreg, xshift, xmask, xtexts) \ 59ac519028STakashi Iwai AC97_ENUM_DOUBLE(xreg, xshift, xshift, xmask, xtexts) 60ac519028STakashi Iwai #define AC97_ENUM(xname, xenum) \ 61ac519028STakashi Iwai { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 62ac519028STakashi Iwai .info = snd_ac97_info_enum_double, \ 63ac519028STakashi Iwai .get = snd_ac97_get_enum_double, .put = snd_ac97_put_enum_double, \ 64ac519028STakashi Iwai .private_value = (unsigned long)&xenum } 65ac519028STakashi Iwai 66ac519028STakashi Iwai /* ac97_codec.c */ 67ac519028STakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_3d[]; 68ac519028STakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_spdif[]; 69ac519028STakashi Iwai static struct snd_kcontrol *snd_ac97_cnew(const struct snd_kcontrol_new *_template, 70ac519028STakashi Iwai struct snd_ac97 * ac97); 71ac519028STakashi Iwai static int snd_ac97_info_volsw(struct snd_kcontrol *kcontrol, 72ac519028STakashi Iwai struct snd_ctl_elem_info *uinfo); 73ac519028STakashi Iwai static int snd_ac97_get_volsw(struct snd_kcontrol *kcontrol, 74ac519028STakashi Iwai struct snd_ctl_elem_value *ucontrol); 75ac519028STakashi Iwai static int snd_ac97_put_volsw(struct snd_kcontrol *kcontrol, 76ac519028STakashi Iwai struct snd_ctl_elem_value *ucontrol); 77ac519028STakashi Iwai static int snd_ac97_try_bit(struct snd_ac97 * ac97, int reg, int bit); 78ac519028STakashi Iwai static int snd_ac97_remove_ctl(struct snd_ac97 *ac97, const char *name, 79ac519028STakashi Iwai const char *suffix); 80ac519028STakashi Iwai static int snd_ac97_rename_ctl(struct snd_ac97 *ac97, const char *src, 81ac519028STakashi Iwai const char *dst, const char *suffix); 82ac519028STakashi Iwai static int snd_ac97_swap_ctl(struct snd_ac97 *ac97, const char *s1, 83ac519028STakashi Iwai const char *s2, const char *suffix); 84ac519028STakashi Iwai static void snd_ac97_rename_vol_ctl(struct snd_ac97 *ac97, const char *src, 85ac519028STakashi Iwai const char *dst); 86ac519028STakashi Iwai static void snd_ac97_restore_status(struct snd_ac97 *ac97); 87ac519028STakashi Iwai static void snd_ac97_restore_iec958(struct snd_ac97 *ac97); 88ac519028STakashi Iwai static int snd_ac97_info_enum_double(struct snd_kcontrol *kcontrol, 89ac519028STakashi Iwai struct snd_ctl_elem_info *uinfo); 90ac519028STakashi Iwai static int snd_ac97_get_enum_double(struct snd_kcontrol *kcontrol, 91ac519028STakashi Iwai struct snd_ctl_elem_value *ucontrol); 92ac519028STakashi Iwai static int snd_ac97_put_enum_double(struct snd_kcontrol *kcontrol, 93ac519028STakashi Iwai struct snd_ctl_elem_value *ucontrol); 94