11da177e4SLinus Torvalds /* 2c1017a4cSJaroslav 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) and to datasheets 71da177e4SLinus Torvalds * for specific codecs. 81da177e4SLinus Torvalds * 91da177e4SLinus Torvalds * 101da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify 111da177e4SLinus Torvalds * it under the terms of the GNU General Public License as published by 121da177e4SLinus Torvalds * the Free Software Foundation; either version 2 of the License, or 131da177e4SLinus Torvalds * (at your option) any later version. 141da177e4SLinus Torvalds * 151da177e4SLinus Torvalds * This program is distributed in the hope that it will be useful, 161da177e4SLinus Torvalds * but WITHOUT ANY WARRANTY; without even the implied warranty of 171da177e4SLinus Torvalds * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 181da177e4SLinus Torvalds * GNU General Public License for more details. 191da177e4SLinus Torvalds * 201da177e4SLinus Torvalds * You should have received a copy of the GNU General Public License 211da177e4SLinus Torvalds * along with this program; if not, write to the Free Software 221da177e4SLinus Torvalds * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 231da177e4SLinus Torvalds * 241da177e4SLinus Torvalds */ 251da177e4SLinus Torvalds 261da177e4SLinus Torvalds #include "ac97_local.h" 27ac519028STakashi Iwai #include "ac97_patch.h" 281da177e4SLinus Torvalds 291da177e4SLinus Torvalds /* 306ba9256cSAndreas Mohr * Forward declarations 316ba9256cSAndreas Mohr */ 326ba9256cSAndreas Mohr 336ba9256cSAndreas Mohr static struct snd_kcontrol *snd_ac97_find_mixer_ctl(struct snd_ac97 *ac97, 346ba9256cSAndreas Mohr const char *name); 356ba9256cSAndreas Mohr static int snd_ac97_add_vmaster(struct snd_ac97 *ac97, char *name, 361bc10bb6STakashi Iwai const unsigned int *tlv, 371bc10bb6STakashi Iwai const char * const *slaves); 386ba9256cSAndreas Mohr 396ba9256cSAndreas Mohr /* 401da177e4SLinus Torvalds * Chip specific initialization 411da177e4SLinus Torvalds */ 421da177e4SLinus Torvalds 43ee42381eSTakashi Iwai static int patch_build_controls(struct snd_ac97 * ac97, const struct snd_kcontrol_new *controls, int count) 441da177e4SLinus Torvalds { 451da177e4SLinus Torvalds int idx, err; 461da177e4SLinus Torvalds 471da177e4SLinus Torvalds for (idx = 0; idx < count; idx++) 481da177e4SLinus Torvalds if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&controls[idx], ac97))) < 0) 491da177e4SLinus Torvalds return err; 501da177e4SLinus Torvalds return 0; 511da177e4SLinus Torvalds } 521da177e4SLinus Torvalds 532f3482fbSTakashi Iwai /* replace with a new TLV */ 542f3482fbSTakashi Iwai static void reset_tlv(struct snd_ac97 *ac97, const char *name, 550cb29ea0STakashi Iwai const unsigned int *tlv) 562f3482fbSTakashi Iwai { 572f3482fbSTakashi Iwai struct snd_ctl_elem_id sid; 582f3482fbSTakashi Iwai struct snd_kcontrol *kctl; 592f3482fbSTakashi Iwai memset(&sid, 0, sizeof(sid)); 602f3482fbSTakashi Iwai strcpy(sid.name, name); 612f3482fbSTakashi Iwai sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 622f3482fbSTakashi Iwai kctl = snd_ctl_find_id(ac97->bus->card, &sid); 632f3482fbSTakashi Iwai if (kctl && kctl->tlv.p) 642f3482fbSTakashi Iwai kctl->tlv.p = tlv; 652f3482fbSTakashi Iwai } 662f3482fbSTakashi Iwai 671da177e4SLinus Torvalds /* set to the page, update bits and restore the page */ 68ee42381eSTakashi Iwai static int ac97_update_bits_page(struct snd_ac97 *ac97, unsigned short reg, unsigned short mask, unsigned short value, unsigned short page) 691da177e4SLinus Torvalds { 701da177e4SLinus Torvalds unsigned short page_save; 711da177e4SLinus Torvalds int ret; 721da177e4SLinus Torvalds 7362932df8SIngo Molnar mutex_lock(&ac97->page_mutex); 741da177e4SLinus Torvalds page_save = snd_ac97_read(ac97, AC97_INT_PAGING) & AC97_PAGE_MASK; 751da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page); 761da177e4SLinus Torvalds ret = snd_ac97_update_bits(ac97, reg, mask, value); 771da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page_save); 7862932df8SIngo Molnar mutex_unlock(&ac97->page_mutex); /* unlock paging */ 791da177e4SLinus Torvalds return ret; 801da177e4SLinus Torvalds } 811da177e4SLinus Torvalds 82eb8caf30STakashi Iwai /* 83eb8caf30STakashi Iwai * shared line-in/mic controls 84eb8caf30STakashi Iwai */ 85ee42381eSTakashi Iwai static int ac97_surround_jack_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 86eb8caf30STakashi Iwai { 873b7a00dcSTakashi Iwai static const char * const texts[] = { "Shared", "Independent" }; 883b7a00dcSTakashi Iwai 893b7a00dcSTakashi Iwai return snd_ctl_enum_info(uinfo, 1, 2, texts); 90eb8caf30STakashi Iwai } 91eb8caf30STakashi Iwai 92ee42381eSTakashi Iwai static int ac97_surround_jack_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 93eb8caf30STakashi Iwai { 94ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 95eb8caf30STakashi Iwai 96eb8caf30STakashi Iwai ucontrol->value.enumerated.item[0] = ac97->indep_surround; 97eb8caf30STakashi Iwai return 0; 98eb8caf30STakashi Iwai } 99eb8caf30STakashi Iwai 100ee42381eSTakashi Iwai static int ac97_surround_jack_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 101eb8caf30STakashi Iwai { 102ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 103eb8caf30STakashi Iwai unsigned char indep = !!ucontrol->value.enumerated.item[0]; 104eb8caf30STakashi Iwai 105eb8caf30STakashi Iwai if (indep != ac97->indep_surround) { 106eb8caf30STakashi Iwai ac97->indep_surround = indep; 107eb8caf30STakashi Iwai if (ac97->build_ops->update_jacks) 108eb8caf30STakashi Iwai ac97->build_ops->update_jacks(ac97); 109eb8caf30STakashi Iwai return 1; 110eb8caf30STakashi Iwai } 111eb8caf30STakashi Iwai return 0; 112eb8caf30STakashi Iwai } 113eb8caf30STakashi Iwai 114ee42381eSTakashi Iwai static int ac97_channel_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 115eb8caf30STakashi Iwai { 1163b7a00dcSTakashi Iwai static const char * const texts[] = { "2ch", "4ch", "6ch", "8ch" }; 1173b7a00dcSTakashi Iwai 1183b7a00dcSTakashi Iwai return snd_ctl_enum_info(uinfo, 1, kcontrol->private_value, texts); 119eb8caf30STakashi Iwai } 120eb8caf30STakashi Iwai 121ee42381eSTakashi Iwai static int ac97_channel_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 122eb8caf30STakashi Iwai { 123ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 124eb8caf30STakashi Iwai 125eb8caf30STakashi Iwai ucontrol->value.enumerated.item[0] = ac97->channel_mode; 126eb8caf30STakashi Iwai return 0; 127eb8caf30STakashi Iwai } 128eb8caf30STakashi Iwai 129ee42381eSTakashi Iwai static int ac97_channel_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 130eb8caf30STakashi Iwai { 131ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 132eb8caf30STakashi Iwai unsigned char mode = ucontrol->value.enumerated.item[0]; 133eb8caf30STakashi Iwai 1344235a317STakashi Iwai if (mode >= kcontrol->private_value) 1354e98d6a7STakashi Iwai return -EINVAL; 1364e98d6a7STakashi Iwai 137eb8caf30STakashi Iwai if (mode != ac97->channel_mode) { 138eb8caf30STakashi Iwai ac97->channel_mode = mode; 139eb8caf30STakashi Iwai if (ac97->build_ops->update_jacks) 140eb8caf30STakashi Iwai ac97->build_ops->update_jacks(ac97); 141eb8caf30STakashi Iwai return 1; 142eb8caf30STakashi Iwai } 143eb8caf30STakashi Iwai return 0; 144eb8caf30STakashi Iwai } 145eb8caf30STakashi Iwai 146eb8caf30STakashi Iwai #define AC97_SURROUND_JACK_MODE_CTL \ 147eb8caf30STakashi Iwai { \ 148eb8caf30STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 149eb8caf30STakashi Iwai .name = "Surround Jack Mode", \ 150eb8caf30STakashi Iwai .info = ac97_surround_jack_mode_info, \ 151eb8caf30STakashi Iwai .get = ac97_surround_jack_mode_get, \ 152eb8caf30STakashi Iwai .put = ac97_surround_jack_mode_put, \ 153eb8caf30STakashi Iwai } 1544235a317STakashi Iwai /* 6ch */ 155eb8caf30STakashi Iwai #define AC97_CHANNEL_MODE_CTL \ 156eb8caf30STakashi Iwai { \ 157eb8caf30STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 158eb8caf30STakashi Iwai .name = "Channel Mode", \ 159eb8caf30STakashi Iwai .info = ac97_channel_mode_info, \ 160eb8caf30STakashi Iwai .get = ac97_channel_mode_get, \ 161eb8caf30STakashi Iwai .put = ac97_channel_mode_put, \ 1624235a317STakashi Iwai .private_value = 3, \ 163eb8caf30STakashi Iwai } 1644235a317STakashi Iwai /* 4ch */ 165eb8caf30STakashi Iwai #define AC97_CHANNEL_MODE_4CH_CTL \ 166eb8caf30STakashi Iwai { \ 167eb8caf30STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 168eb8caf30STakashi Iwai .name = "Channel Mode", \ 169eb8caf30STakashi Iwai .info = ac97_channel_mode_info, \ 170eb8caf30STakashi Iwai .get = ac97_channel_mode_get, \ 171eb8caf30STakashi Iwai .put = ac97_channel_mode_put, \ 1724235a317STakashi Iwai .private_value = 2, \ 1734235a317STakashi Iwai } 1744235a317STakashi Iwai /* 8ch */ 1754235a317STakashi Iwai #define AC97_CHANNEL_MODE_8CH_CTL \ 1764235a317STakashi Iwai { \ 1774235a317STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 1784235a317STakashi Iwai .name = "Channel Mode", \ 1794235a317STakashi Iwai .info = ac97_channel_mode_info, \ 1804235a317STakashi Iwai .get = ac97_channel_mode_get, \ 1814235a317STakashi Iwai .put = ac97_channel_mode_put, \ 1824235a317STakashi Iwai .private_value = 4, \ 183eb8caf30STakashi Iwai } 184eb8caf30STakashi Iwai 185ee42381eSTakashi Iwai static inline int is_surround_on(struct snd_ac97 *ac97) 1864525c9f3STakashi Iwai { 1874525c9f3STakashi Iwai return ac97->channel_mode >= 1; 1884525c9f3STakashi Iwai } 1894525c9f3STakashi Iwai 190ee42381eSTakashi Iwai static inline int is_clfe_on(struct snd_ac97 *ac97) 1914525c9f3STakashi Iwai { 192eb9b4142STakashi Iwai return ac97->channel_mode >= 2; 1934525c9f3STakashi Iwai } 1944525c9f3STakashi Iwai 195831466f4SRandy Cushman /* system has shared jacks with surround out enabled */ 196831466f4SRandy Cushman static inline int is_shared_surrout(struct snd_ac97 *ac97) 197eb8caf30STakashi Iwai { 1984525c9f3STakashi Iwai return !ac97->indep_surround && is_surround_on(ac97); 199eb8caf30STakashi Iwai } 200eb8caf30STakashi Iwai 201831466f4SRandy Cushman /* system has shared jacks with center/lfe out enabled */ 202831466f4SRandy Cushman static inline int is_shared_clfeout(struct snd_ac97 *ac97) 203eb8caf30STakashi Iwai { 2044525c9f3STakashi Iwai return !ac97->indep_surround && is_clfe_on(ac97); 205eb8caf30STakashi Iwai } 206eb8caf30STakashi Iwai 207831466f4SRandy Cushman /* system has shared jacks with line in enabled */ 208831466f4SRandy Cushman static inline int is_shared_linein(struct snd_ac97 *ac97) 209831466f4SRandy Cushman { 210831466f4SRandy Cushman return !ac97->indep_surround && !is_surround_on(ac97); 211831466f4SRandy Cushman } 212831466f4SRandy Cushman 213831466f4SRandy Cushman /* system has shared jacks with mic in enabled */ 214831466f4SRandy Cushman static inline int is_shared_micin(struct snd_ac97 *ac97) 215831466f4SRandy Cushman { 216831466f4SRandy Cushman return !ac97->indep_surround && !is_clfe_on(ac97); 217831466f4SRandy Cushman } 218831466f4SRandy Cushman 2194235a317STakashi Iwai static inline int alc850_is_aux_back_surround(struct snd_ac97 *ac97) 2204235a317STakashi Iwai { 2214235a317STakashi Iwai return is_surround_on(ac97); 2224235a317STakashi Iwai } 223eb8caf30STakashi Iwai 2241da177e4SLinus Torvalds /* The following snd_ac97_ymf753_... items added by David Shust (dshust@shustring.com) */ 22543115f58SKeita Maehara /* Modified for YMF743 by Keita Maehara <maehara@debian.org> */ 2261da177e4SLinus Torvalds 22713043984SKeita Maehara /* It is possible to indicate to the Yamaha YMF7x3 the type of 22813043984SKeita Maehara speakers being used. */ 22913043984SKeita Maehara 23013043984SKeita Maehara static int snd_ac97_ymf7x3_info_speaker(struct snd_kcontrol *kcontrol, 23113043984SKeita Maehara struct snd_ctl_elem_info *uinfo) 2321da177e4SLinus Torvalds { 2333b7a00dcSTakashi Iwai static const char * const texts[3] = { 2341da177e4SLinus Torvalds "Standard", "Small", "Smaller" 2351da177e4SLinus Torvalds }; 2361da177e4SLinus Torvalds 2373b7a00dcSTakashi Iwai return snd_ctl_enum_info(uinfo, 1, 3, texts); 2381da177e4SLinus Torvalds } 2391da177e4SLinus Torvalds 24013043984SKeita Maehara static int snd_ac97_ymf7x3_get_speaker(struct snd_kcontrol *kcontrol, 24113043984SKeita Maehara struct snd_ctl_elem_value *ucontrol) 2421da177e4SLinus Torvalds { 243ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 2441da177e4SLinus Torvalds unsigned short val; 2451da177e4SLinus Torvalds 24613043984SKeita Maehara val = ac97->regs[AC97_YMF7X3_3D_MODE_SEL]; 2471da177e4SLinus Torvalds val = (val >> 10) & 3; 2481da177e4SLinus Torvalds if (val > 0) /* 0 = invalid */ 2491da177e4SLinus Torvalds val--; 2501da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = val; 2511da177e4SLinus Torvalds return 0; 2521da177e4SLinus Torvalds } 2531da177e4SLinus Torvalds 25413043984SKeita Maehara static int snd_ac97_ymf7x3_put_speaker(struct snd_kcontrol *kcontrol, 25513043984SKeita Maehara struct snd_ctl_elem_value *ucontrol) 2561da177e4SLinus Torvalds { 257ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 2581da177e4SLinus Torvalds unsigned short val; 2591da177e4SLinus Torvalds 2601da177e4SLinus Torvalds if (ucontrol->value.enumerated.item[0] > 2) 2611da177e4SLinus Torvalds return -EINVAL; 2621da177e4SLinus Torvalds val = (ucontrol->value.enumerated.item[0] + 1) << 10; 26313043984SKeita Maehara return snd_ac97_update(ac97, AC97_YMF7X3_3D_MODE_SEL, val); 2641da177e4SLinus Torvalds } 2651da177e4SLinus Torvalds 26613043984SKeita Maehara static const struct snd_kcontrol_new snd_ac97_ymf7x3_controls_speaker = 2671da177e4SLinus Torvalds { 2681da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2691da177e4SLinus Torvalds .name = "3D Control - Speaker", 27013043984SKeita Maehara .info = snd_ac97_ymf7x3_info_speaker, 27113043984SKeita Maehara .get = snd_ac97_ymf7x3_get_speaker, 27213043984SKeita Maehara .put = snd_ac97_ymf7x3_put_speaker, 2731da177e4SLinus Torvalds }; 2741da177e4SLinus Torvalds 27513043984SKeita Maehara /* It is possible to indicate to the Yamaha YMF7x3 the source to 27613043984SKeita Maehara direct to the S/PDIF output. */ 27713043984SKeita Maehara static int snd_ac97_ymf7x3_spdif_source_info(struct snd_kcontrol *kcontrol, 27813043984SKeita Maehara struct snd_ctl_elem_info *uinfo) 2791da177e4SLinus Torvalds { 2803b7a00dcSTakashi Iwai static const char * const texts[2] = { "AC-Link", "A/D Converter" }; 2811da177e4SLinus Torvalds 2823b7a00dcSTakashi Iwai return snd_ctl_enum_info(uinfo, 1, 2, texts); 2831da177e4SLinus Torvalds } 2841da177e4SLinus Torvalds 28513043984SKeita Maehara static int snd_ac97_ymf7x3_spdif_source_get(struct snd_kcontrol *kcontrol, 28613043984SKeita Maehara struct snd_ctl_elem_value *ucontrol) 2871da177e4SLinus Torvalds { 288ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 2891da177e4SLinus Torvalds unsigned short val; 2901da177e4SLinus Torvalds 29113043984SKeita Maehara val = ac97->regs[AC97_YMF7X3_DIT_CTRL]; 2921da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = (val >> 1) & 1; 2931da177e4SLinus Torvalds return 0; 2941da177e4SLinus Torvalds } 2951da177e4SLinus Torvalds 29613043984SKeita Maehara static int snd_ac97_ymf7x3_spdif_source_put(struct snd_kcontrol *kcontrol, 29713043984SKeita Maehara struct snd_ctl_elem_value *ucontrol) 2981da177e4SLinus Torvalds { 299ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 3001da177e4SLinus Torvalds unsigned short val; 3011da177e4SLinus Torvalds 3021da177e4SLinus Torvalds if (ucontrol->value.enumerated.item[0] > 1) 3031da177e4SLinus Torvalds return -EINVAL; 3041da177e4SLinus Torvalds val = ucontrol->value.enumerated.item[0] << 1; 30513043984SKeita Maehara return snd_ac97_update_bits(ac97, AC97_YMF7X3_DIT_CTRL, 0x0002, val); 3061da177e4SLinus Torvalds } 3071da177e4SLinus Torvalds 30843115f58SKeita Maehara static int patch_yamaha_ymf7x3_3d(struct snd_ac97 *ac97) 30943115f58SKeita Maehara { 31043115f58SKeita Maehara struct snd_kcontrol *kctl; 31143115f58SKeita Maehara int err; 31243115f58SKeita Maehara 31343115f58SKeita Maehara kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97); 31443115f58SKeita Maehara err = snd_ctl_add(ac97->bus->card, kctl); 31543115f58SKeita Maehara if (err < 0) 31643115f58SKeita Maehara return err; 31743115f58SKeita Maehara strcpy(kctl->id.name, "3D Control - Wide"); 31843115f58SKeita Maehara kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 9, 7, 0); 31943115f58SKeita Maehara snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000); 32043115f58SKeita Maehara err = snd_ctl_add(ac97->bus->card, 32143115f58SKeita Maehara snd_ac97_cnew(&snd_ac97_ymf7x3_controls_speaker, 32243115f58SKeita Maehara ac97)); 32343115f58SKeita Maehara if (err < 0) 32443115f58SKeita Maehara return err; 32543115f58SKeita Maehara snd_ac97_write_cache(ac97, AC97_YMF7X3_3D_MODE_SEL, 0x0c00); 32643115f58SKeita Maehara return 0; 32743115f58SKeita Maehara } 32843115f58SKeita Maehara 32943115f58SKeita Maehara static const struct snd_kcontrol_new snd_ac97_yamaha_ymf743_controls_spdif[3] = 33043115f58SKeita Maehara { 33143115f58SKeita Maehara AC97_SINGLE(SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH), 33243115f58SKeita Maehara AC97_YMF7X3_DIT_CTRL, 0, 1, 0), 33343115f58SKeita Maehara { 33443115f58SKeita Maehara .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 33543115f58SKeita Maehara .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, NONE) "Source", 33643115f58SKeita Maehara .info = snd_ac97_ymf7x3_spdif_source_info, 33743115f58SKeita Maehara .get = snd_ac97_ymf7x3_spdif_source_get, 33843115f58SKeita Maehara .put = snd_ac97_ymf7x3_spdif_source_put, 33943115f58SKeita Maehara }, 34043115f58SKeita Maehara AC97_SINGLE(SNDRV_CTL_NAME_IEC958("", NONE, NONE) "Mute", 34143115f58SKeita Maehara AC97_YMF7X3_DIT_CTRL, 2, 1, 1) 34243115f58SKeita Maehara }; 34343115f58SKeita Maehara 34443115f58SKeita Maehara static int patch_yamaha_ymf743_build_spdif(struct snd_ac97 *ac97) 34543115f58SKeita Maehara { 34643115f58SKeita Maehara int err; 34743115f58SKeita Maehara 34843115f58SKeita Maehara err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3); 34943115f58SKeita Maehara if (err < 0) 35043115f58SKeita Maehara return err; 35143115f58SKeita Maehara err = patch_build_controls(ac97, 35243115f58SKeita Maehara snd_ac97_yamaha_ymf743_controls_spdif, 3); 35343115f58SKeita Maehara if (err < 0) 35443115f58SKeita Maehara return err; 35543115f58SKeita Maehara /* set default PCM S/PDIF params */ 35643115f58SKeita Maehara /* PCM audio,no copyright,no preemphasis,PCM coder,original */ 35743115f58SKeita Maehara snd_ac97_write_cache(ac97, AC97_YMF7X3_DIT_CTRL, 0xa201); 35843115f58SKeita Maehara return 0; 35943115f58SKeita Maehara } 36043115f58SKeita Maehara 3613e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_yamaha_ymf743_ops = { 36243115f58SKeita Maehara .build_spdif = patch_yamaha_ymf743_build_spdif, 36343115f58SKeita Maehara .build_3d = patch_yamaha_ymf7x3_3d, 36443115f58SKeita Maehara }; 36543115f58SKeita Maehara 36643115f58SKeita Maehara static int patch_yamaha_ymf743(struct snd_ac97 *ac97) 36743115f58SKeita Maehara { 36843115f58SKeita Maehara ac97->build_ops = &patch_yamaha_ymf743_ops; 36943115f58SKeita Maehara ac97->caps |= AC97_BC_BASS_TREBLE; 37043115f58SKeita Maehara ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */ 37143115f58SKeita Maehara ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */ 37243115f58SKeita Maehara ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */ 37343115f58SKeita Maehara return 0; 37443115f58SKeita Maehara } 37543115f58SKeita Maehara 3761da177e4SLinus Torvalds /* The AC'97 spec states that the S/PDIF signal is to be output at pin 48. 3771da177e4SLinus Torvalds The YMF753 will output the S/PDIF signal to pin 43, 47 (EAPD), or 48. 3781da177e4SLinus Torvalds By default, no output pin is selected, and the S/PDIF signal is not output. 3791da177e4SLinus Torvalds There is also a bit to mute S/PDIF output in a vendor-specific register. */ 380ee42381eSTakashi Iwai static int snd_ac97_ymf753_spdif_output_pin_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 3811da177e4SLinus Torvalds { 3823b7a00dcSTakashi Iwai static const char * const texts[3] = { "Disabled", "Pin 43", "Pin 48" }; 3831da177e4SLinus Torvalds 3843b7a00dcSTakashi Iwai return snd_ctl_enum_info(uinfo, 1, 3, texts); 3851da177e4SLinus Torvalds } 3861da177e4SLinus Torvalds 387ee42381eSTakashi Iwai static int snd_ac97_ymf753_spdif_output_pin_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 3881da177e4SLinus Torvalds { 389ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 3901da177e4SLinus Torvalds unsigned short val; 3911da177e4SLinus Torvalds 39213043984SKeita Maehara val = ac97->regs[AC97_YMF7X3_DIT_CTRL]; 3931da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = (val & 0x0008) ? 2 : (val & 0x0020) ? 1 : 0; 3941da177e4SLinus Torvalds return 0; 3951da177e4SLinus Torvalds } 3961da177e4SLinus Torvalds 397ee42381eSTakashi Iwai static int snd_ac97_ymf753_spdif_output_pin_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 3981da177e4SLinus Torvalds { 399ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 4001da177e4SLinus Torvalds unsigned short val; 4011da177e4SLinus Torvalds 4021da177e4SLinus Torvalds if (ucontrol->value.enumerated.item[0] > 2) 4031da177e4SLinus Torvalds return -EINVAL; 4041da177e4SLinus Torvalds val = (ucontrol->value.enumerated.item[0] == 2) ? 0x0008 : 4051da177e4SLinus Torvalds (ucontrol->value.enumerated.item[0] == 1) ? 0x0020 : 0; 40613043984SKeita Maehara return snd_ac97_update_bits(ac97, AC97_YMF7X3_DIT_CTRL, 0x0028, val); 4071da177e4SLinus Torvalds /* The following can be used to direct S/PDIF output to pin 47 (EAPD). 4081da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x62, snd_ac97_read(ac97, 0x62) | 0x0008); */ 4091da177e4SLinus Torvalds } 4101da177e4SLinus Torvalds 411ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ymf753_controls_spdif[3] = { 4121da177e4SLinus Torvalds { 4131da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 4141da177e4SLinus Torvalds .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source", 41513043984SKeita Maehara .info = snd_ac97_ymf7x3_spdif_source_info, 41613043984SKeita Maehara .get = snd_ac97_ymf7x3_spdif_source_get, 41713043984SKeita Maehara .put = snd_ac97_ymf7x3_spdif_source_put, 4181da177e4SLinus Torvalds }, 4191da177e4SLinus Torvalds { 4201da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 4211da177e4SLinus Torvalds .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Output Pin", 4221da177e4SLinus Torvalds .info = snd_ac97_ymf753_spdif_output_pin_info, 4231da177e4SLinus Torvalds .get = snd_ac97_ymf753_spdif_output_pin_get, 4241da177e4SLinus Torvalds .put = snd_ac97_ymf753_spdif_output_pin_put, 4251da177e4SLinus Torvalds }, 42613043984SKeita Maehara AC97_SINGLE(SNDRV_CTL_NAME_IEC958("", NONE, NONE) "Mute", 42713043984SKeita Maehara AC97_YMF7X3_DIT_CTRL, 2, 1, 1) 4281da177e4SLinus Torvalds }; 4291da177e4SLinus Torvalds 430ee42381eSTakashi Iwai static int patch_yamaha_ymf753_post_spdif(struct snd_ac97 * ac97) 4311da177e4SLinus Torvalds { 4321da177e4SLinus Torvalds int err; 4331da177e4SLinus Torvalds 4341da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, snd_ac97_ymf753_controls_spdif, ARRAY_SIZE(snd_ac97_ymf753_controls_spdif))) < 0) 4351da177e4SLinus Torvalds return err; 4361da177e4SLinus Torvalds return 0; 4371da177e4SLinus Torvalds } 4381da177e4SLinus Torvalds 4393e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_yamaha_ymf753_ops = { 44013043984SKeita Maehara .build_3d = patch_yamaha_ymf7x3_3d, 4411da177e4SLinus Torvalds .build_post_spdif = patch_yamaha_ymf753_post_spdif 4421da177e4SLinus Torvalds }; 4431da177e4SLinus Torvalds 444ac519028STakashi Iwai static int patch_yamaha_ymf753(struct snd_ac97 * ac97) 4451da177e4SLinus Torvalds { 4461da177e4SLinus Torvalds /* Patch for Yamaha YMF753, Copyright (c) by David Shust, dshust@shustring.com. 4471da177e4SLinus Torvalds This chip has nonstandard and extended behaviour with regard to its S/PDIF output. 4481da177e4SLinus Torvalds The AC'97 spec states that the S/PDIF signal is to be output at pin 48. 4491da177e4SLinus Torvalds The YMF753 will ouput the S/PDIF signal to pin 43, 47 (EAPD), or 48. 4501da177e4SLinus Torvalds By default, no output pin is selected, and the S/PDIF signal is not output. 4511da177e4SLinus Torvalds There is also a bit to mute S/PDIF output in a vendor-specific register. 4521da177e4SLinus Torvalds */ 4531da177e4SLinus Torvalds ac97->build_ops = &patch_yamaha_ymf753_ops; 4541da177e4SLinus Torvalds ac97->caps |= AC97_BC_BASS_TREBLE; 4551da177e4SLinus Torvalds ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */ 4561da177e4SLinus Torvalds return 0; 4571da177e4SLinus Torvalds } 4581da177e4SLinus Torvalds 4591da177e4SLinus Torvalds /* 460d331124dSLiam Girdwood * May 2, 2003 Liam Girdwood <lrg@slimlogic.co.uk> 4611da177e4SLinus Torvalds * removed broken wolfson00 patch. 4621da177e4SLinus Torvalds * added support for WM9705,WM9708,WM9709,WM9710,WM9711,WM9712 and WM9717. 4631da177e4SLinus Torvalds */ 4641da177e4SLinus Torvalds 465ee42381eSTakashi Iwai static const struct snd_kcontrol_new wm97xx_snd_ac97_controls[] = { 4663998b70fSLiam Girdwood AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1), 4673998b70fSLiam Girdwood AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1), 4683998b70fSLiam Girdwood }; 4693998b70fSLiam Girdwood 470ee42381eSTakashi Iwai static int patch_wolfson_wm9703_specific(struct snd_ac97 * ac97) 4711da177e4SLinus Torvalds { 4721da177e4SLinus Torvalds /* This is known to work for the ViewSonic ViewPad 1000 4733998b70fSLiam Girdwood * Randolph Bentson <bentson@holmsjoen.com> 4743998b70fSLiam Girdwood * WM9703/9707/9708/9717 4753998b70fSLiam Girdwood */ 4763998b70fSLiam Girdwood int err, i; 4771da177e4SLinus Torvalds 4783998b70fSLiam Girdwood for (i = 0; i < ARRAY_SIZE(wm97xx_snd_ac97_controls); i++) { 4793998b70fSLiam Girdwood if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm97xx_snd_ac97_controls[i], ac97))) < 0) 4803998b70fSLiam Girdwood return err; 4813998b70fSLiam Girdwood } 4821da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808); 4831da177e4SLinus Torvalds return 0; 4841da177e4SLinus Torvalds } 4851da177e4SLinus Torvalds 4863e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_wolfson_wm9703_ops = { 4873998b70fSLiam Girdwood .build_specific = patch_wolfson_wm9703_specific, 4883998b70fSLiam Girdwood }; 4893998b70fSLiam Girdwood 490ac519028STakashi Iwai static int patch_wolfson03(struct snd_ac97 * ac97) 4913998b70fSLiam Girdwood { 4923998b70fSLiam Girdwood ac97->build_ops = &patch_wolfson_wm9703_ops; 4933998b70fSLiam Girdwood return 0; 4943998b70fSLiam Girdwood } 4953998b70fSLiam Girdwood 496ee42381eSTakashi Iwai static const struct snd_kcontrol_new wm9704_snd_ac97_controls[] = { 4973998b70fSLiam Girdwood AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1), 4983998b70fSLiam Girdwood AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1), 4993998b70fSLiam Girdwood AC97_DOUBLE("Rear Playback Volume", AC97_WM9704_RMIXER_VOL, 8, 0, 31, 1), 5003998b70fSLiam Girdwood AC97_SINGLE("Rear Playback Switch", AC97_WM9704_RMIXER_VOL, 15, 1, 1), 5013998b70fSLiam Girdwood AC97_DOUBLE("Rear DAC Volume", AC97_WM9704_RPCM_VOL, 8, 0, 31, 1), 5023998b70fSLiam Girdwood AC97_DOUBLE("Surround Volume", AC97_SURROUND_MASTER, 8, 0, 31, 1), 5033998b70fSLiam Girdwood }; 5043998b70fSLiam Girdwood 505ee42381eSTakashi Iwai static int patch_wolfson_wm9704_specific(struct snd_ac97 * ac97) 5063998b70fSLiam Girdwood { 5073998b70fSLiam Girdwood int err, i; 5083998b70fSLiam Girdwood for (i = 0; i < ARRAY_SIZE(wm9704_snd_ac97_controls); i++) { 5093998b70fSLiam Girdwood if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9704_snd_ac97_controls[i], ac97))) < 0) 5103998b70fSLiam Girdwood return err; 5113998b70fSLiam Girdwood } 5123998b70fSLiam Girdwood /* patch for DVD noise */ 5133998b70fSLiam Girdwood snd_ac97_write_cache(ac97, AC97_WM9704_TEST, 0x0200); 5143998b70fSLiam Girdwood return 0; 5153998b70fSLiam Girdwood } 5163998b70fSLiam Girdwood 5173e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_wolfson_wm9704_ops = { 5183998b70fSLiam Girdwood .build_specific = patch_wolfson_wm9704_specific, 5193998b70fSLiam Girdwood }; 5203998b70fSLiam Girdwood 521ac519028STakashi Iwai static int patch_wolfson04(struct snd_ac97 * ac97) 5221da177e4SLinus Torvalds { 5233998b70fSLiam Girdwood /* WM9704M/9704Q */ 5243998b70fSLiam Girdwood ac97->build_ops = &patch_wolfson_wm9704_ops; 5251da177e4SLinus Torvalds return 0; 5261da177e4SLinus Torvalds } 5271da177e4SLinus Torvalds 528ac519028STakashi Iwai static int patch_wolfson05(struct snd_ac97 * ac97) 5291da177e4SLinus Torvalds { 5303998b70fSLiam Girdwood /* WM9705, WM9710 */ 531dd3533ecSKrzysztof Helt ac97->build_ops = &patch_wolfson_wm9703_ops; 5321459c784SRodolfo Giometti #ifdef CONFIG_TOUCHSCREEN_WM9705 5331459c784SRodolfo Giometti /* WM9705 touchscreen uses AUX and VIDEO for touch */ 5348f88820eSLiam Girdwood ac97->flags |= AC97_HAS_NO_VIDEO | AC97_HAS_NO_AUX; 5351459c784SRodolfo Giometti #endif 5361da177e4SLinus Torvalds return 0; 5371da177e4SLinus Torvalds } 5381da177e4SLinus Torvalds 5393998b70fSLiam Girdwood static const char* wm9711_alc_select[] = {"None", "Left", "Right", "Stereo"}; 5403998b70fSLiam Girdwood static const char* wm9711_alc_mix[] = {"Stereo", "Right", "Left", "None"}; 5413998b70fSLiam Girdwood static const char* wm9711_out3_src[] = {"Left", "VREF", "Left + Right", "Mono"}; 5423998b70fSLiam Girdwood static const char* wm9711_out3_lrsrc[] = {"Master Mix", "Headphone Mix"}; 5433998b70fSLiam Girdwood static const char* wm9711_rec_adc[] = {"Stereo", "Left", "Right", "Mute"}; 5443998b70fSLiam Girdwood static const char* wm9711_base[] = {"Linear Control", "Adaptive Boost"}; 5453998b70fSLiam Girdwood static const char* wm9711_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"}; 5463998b70fSLiam Girdwood static const char* wm9711_mic[] = {"Mic 1", "Differential", "Mic 2", "Stereo"}; 5473998b70fSLiam Girdwood static const char* wm9711_rec_sel[] = 5483998b70fSLiam Girdwood {"Mic 1", "NC", "NC", "Master Mix", "Line", "Headphone Mix", "Phone Mix", "Phone"}; 5493998b70fSLiam Girdwood static const char* wm9711_ng_type[] = {"Constant Gain", "Mute"}; 5503998b70fSLiam Girdwood 5513998b70fSLiam Girdwood static const struct ac97_enum wm9711_enum[] = { 5523998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9711_alc_select), 5533998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_VIDEO, 10, 4, wm9711_alc_mix), 5543998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_AUX, 9, 4, wm9711_out3_src), 5553998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_AUX, 8, 2, wm9711_out3_lrsrc), 5563998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_REC_SEL, 12, 4, wm9711_rec_adc), 5573998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_MASTER_TONE, 15, 2, wm9711_base), 5583998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_REC_GAIN, 14, 6, 2, wm9711_rec_gain), 5593998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_MIC, 5, 4, wm9711_mic), 5603998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_REC_SEL, 8, 0, 8, wm9711_rec_sel), 5613998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9711_ng_type), 5623998b70fSLiam Girdwood }; 5633998b70fSLiam Girdwood 564ee42381eSTakashi Iwai static const struct snd_kcontrol_new wm9711_snd_ac97_controls[] = { 5653998b70fSLiam Girdwood AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0), 5663998b70fSLiam Girdwood AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0), 5673998b70fSLiam Girdwood AC97_SINGLE("ALC Decay Time", AC97_CODEC_CLASS_REV, 4, 15, 0), 5683998b70fSLiam Girdwood AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0), 5693998b70fSLiam Girdwood AC97_ENUM("ALC Function", wm9711_enum[0]), 5703998b70fSLiam Girdwood AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 1), 5713998b70fSLiam Girdwood AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 1), 5723998b70fSLiam Girdwood AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0), 5733998b70fSLiam Girdwood AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0), 5743998b70fSLiam Girdwood AC97_ENUM("ALC NG Type", wm9711_enum[9]), 5753998b70fSLiam Girdwood AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 1), 5763998b70fSLiam Girdwood 5773998b70fSLiam Girdwood AC97_SINGLE("Side Tone Switch", AC97_VIDEO, 15, 1, 1), 5783998b70fSLiam Girdwood AC97_SINGLE("Side Tone Volume", AC97_VIDEO, 12, 7, 1), 5793998b70fSLiam Girdwood AC97_ENUM("ALC Headphone Mux", wm9711_enum[1]), 5803998b70fSLiam Girdwood AC97_SINGLE("ALC Headphone Volume", AC97_VIDEO, 7, 7, 1), 5813998b70fSLiam Girdwood 5823998b70fSLiam Girdwood AC97_SINGLE("Out3 Switch", AC97_AUX, 15, 1, 1), 5832aedbda6SLuke Zhang AC97_SINGLE("Out3 ZC Switch", AC97_AUX, 7, 1, 0), 5843998b70fSLiam Girdwood AC97_ENUM("Out3 Mux", wm9711_enum[2]), 5853998b70fSLiam Girdwood AC97_ENUM("Out3 LR Mux", wm9711_enum[3]), 5863998b70fSLiam Girdwood AC97_SINGLE("Out3 Volume", AC97_AUX, 0, 31, 1), 5873998b70fSLiam Girdwood 5883998b70fSLiam Girdwood AC97_SINGLE("Beep to Headphone Switch", AC97_PC_BEEP, 15, 1, 1), 5893998b70fSLiam Girdwood AC97_SINGLE("Beep to Headphone Volume", AC97_PC_BEEP, 12, 7, 1), 5903998b70fSLiam Girdwood AC97_SINGLE("Beep to Side Tone Switch", AC97_PC_BEEP, 11, 1, 1), 5913998b70fSLiam Girdwood AC97_SINGLE("Beep to Side Tone Volume", AC97_PC_BEEP, 8, 7, 1), 5923998b70fSLiam Girdwood AC97_SINGLE("Beep to Phone Switch", AC97_PC_BEEP, 7, 1, 1), 5933998b70fSLiam Girdwood AC97_SINGLE("Beep to Phone Volume", AC97_PC_BEEP, 4, 7, 1), 5943998b70fSLiam Girdwood 5953998b70fSLiam Girdwood AC97_SINGLE("Aux to Headphone Switch", AC97_CD, 15, 1, 1), 5963998b70fSLiam Girdwood AC97_SINGLE("Aux to Headphone Volume", AC97_CD, 12, 7, 1), 5973998b70fSLiam Girdwood AC97_SINGLE("Aux to Side Tone Switch", AC97_CD, 11, 1, 1), 5983998b70fSLiam Girdwood AC97_SINGLE("Aux to Side Tone Volume", AC97_CD, 8, 7, 1), 5993998b70fSLiam Girdwood AC97_SINGLE("Aux to Phone Switch", AC97_CD, 7, 1, 1), 6003998b70fSLiam Girdwood AC97_SINGLE("Aux to Phone Volume", AC97_CD, 4, 7, 1), 6013998b70fSLiam Girdwood 6023998b70fSLiam Girdwood AC97_SINGLE("Phone to Headphone Switch", AC97_PHONE, 15, 1, 1), 6033998b70fSLiam Girdwood AC97_SINGLE("Phone to Master Switch", AC97_PHONE, 14, 1, 1), 6043998b70fSLiam Girdwood 6053998b70fSLiam Girdwood AC97_SINGLE("Line to Headphone Switch", AC97_LINE, 15, 1, 1), 6063998b70fSLiam Girdwood AC97_SINGLE("Line to Master Switch", AC97_LINE, 14, 1, 1), 6073998b70fSLiam Girdwood AC97_SINGLE("Line to Phone Switch", AC97_LINE, 13, 1, 1), 6083998b70fSLiam Girdwood 6093998b70fSLiam Girdwood AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PCM, 15, 1, 1), 6103998b70fSLiam Girdwood AC97_SINGLE("PCM Playback to Master Switch", AC97_PCM, 14, 1, 1), 6113998b70fSLiam Girdwood AC97_SINGLE("PCM Playback to Phone Switch", AC97_PCM, 13, 1, 1), 6123998b70fSLiam Girdwood 6133998b70fSLiam Girdwood AC97_SINGLE("Capture 20dB Boost Switch", AC97_REC_SEL, 14, 1, 0), 6143998b70fSLiam Girdwood AC97_ENUM("Capture to Phone Mux", wm9711_enum[4]), 6153998b70fSLiam Girdwood AC97_SINGLE("Capture to Phone 20dB Boost Switch", AC97_REC_SEL, 11, 1, 1), 6163998b70fSLiam Girdwood AC97_ENUM("Capture Select", wm9711_enum[8]), 6173998b70fSLiam Girdwood 6183998b70fSLiam Girdwood AC97_SINGLE("3D Upper Cut-off Switch", AC97_3D_CONTROL, 5, 1, 1), 6193998b70fSLiam Girdwood AC97_SINGLE("3D Lower Cut-off Switch", AC97_3D_CONTROL, 4, 1, 1), 6203998b70fSLiam Girdwood 6213998b70fSLiam Girdwood AC97_ENUM("Bass Control", wm9711_enum[5]), 6223998b70fSLiam Girdwood AC97_SINGLE("Bass Cut-off Switch", AC97_MASTER_TONE, 12, 1, 1), 6233998b70fSLiam Girdwood AC97_SINGLE("Tone Cut-off Switch", AC97_MASTER_TONE, 4, 1, 1), 6243998b70fSLiam Girdwood AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_MASTER_TONE, 6, 1, 0), 6253998b70fSLiam Girdwood 6263998b70fSLiam Girdwood AC97_SINGLE("ADC Switch", AC97_REC_GAIN, 15, 1, 1), 6273998b70fSLiam Girdwood AC97_ENUM("Capture Volume Steps", wm9711_enum[6]), 6282aedbda6SLuke Zhang AC97_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 63, 1), 6293998b70fSLiam Girdwood AC97_SINGLE("Capture ZC Switch", AC97_REC_GAIN, 7, 1, 0), 6303998b70fSLiam Girdwood 6313998b70fSLiam Girdwood AC97_SINGLE("Mic 1 to Phone Switch", AC97_MIC, 14, 1, 1), 6323998b70fSLiam Girdwood AC97_SINGLE("Mic 2 to Phone Switch", AC97_MIC, 13, 1, 1), 6333998b70fSLiam Girdwood AC97_ENUM("Mic Select Source", wm9711_enum[7]), 6342aedbda6SLuke Zhang AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1), 6352aedbda6SLuke Zhang AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1), 636d7f6f115SJames Courtier-Dutton AC97_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 7, 1, 0), 6373998b70fSLiam Girdwood 6380264b3b6SJuergen Beisert AC97_SINGLE("Master Left Inv Switch", AC97_MASTER, 6, 1, 0), 6393998b70fSLiam Girdwood AC97_SINGLE("Master ZC Switch", AC97_MASTER, 7, 1, 0), 6403998b70fSLiam Girdwood AC97_SINGLE("Headphone ZC Switch", AC97_HEADPHONE, 7, 1, 0), 6413998b70fSLiam Girdwood AC97_SINGLE("Mono ZC Switch", AC97_MASTER_MONO, 7, 1, 0), 6423998b70fSLiam Girdwood }; 6433998b70fSLiam Girdwood 644ee42381eSTakashi Iwai static int patch_wolfson_wm9711_specific(struct snd_ac97 * ac97) 6453998b70fSLiam Girdwood { 6463998b70fSLiam Girdwood int err, i; 6473998b70fSLiam Girdwood 6483998b70fSLiam Girdwood for (i = 0; i < ARRAY_SIZE(wm9711_snd_ac97_controls); i++) { 6493998b70fSLiam Girdwood if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9711_snd_ac97_controls[i], ac97))) < 0) 6503998b70fSLiam Girdwood return err; 6513998b70fSLiam Girdwood } 6523998b70fSLiam Girdwood snd_ac97_write_cache(ac97, AC97_CODEC_CLASS_REV, 0x0808); 6533998b70fSLiam Girdwood snd_ac97_write_cache(ac97, AC97_PCI_SVID, 0x0808); 6543998b70fSLiam Girdwood snd_ac97_write_cache(ac97, AC97_VIDEO, 0x0808); 6553998b70fSLiam Girdwood snd_ac97_write_cache(ac97, AC97_AUX, 0x0808); 6563998b70fSLiam Girdwood snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808); 6573998b70fSLiam Girdwood snd_ac97_write_cache(ac97, AC97_CD, 0x0000); 6583998b70fSLiam Girdwood return 0; 6593998b70fSLiam Girdwood } 6603998b70fSLiam Girdwood 6613e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_wolfson_wm9711_ops = { 6623998b70fSLiam Girdwood .build_specific = patch_wolfson_wm9711_specific, 6633998b70fSLiam Girdwood }; 6643998b70fSLiam Girdwood 665ac519028STakashi Iwai static int patch_wolfson11(struct snd_ac97 * ac97) 6661da177e4SLinus Torvalds { 6673998b70fSLiam Girdwood /* WM9711, WM9712 */ 6683998b70fSLiam Girdwood ac97->build_ops = &patch_wolfson_wm9711_ops; 6693998b70fSLiam Girdwood 6703998b70fSLiam Girdwood ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_MIC | 6713998b70fSLiam Girdwood AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD; 6723998b70fSLiam Girdwood 6731da177e4SLinus Torvalds return 0; 6741da177e4SLinus Torvalds } 6751da177e4SLinus Torvalds 6761da177e4SLinus Torvalds static const char* wm9713_mic_mixer[] = {"Stereo", "Mic 1", "Mic 2", "Mute"}; 6771da177e4SLinus Torvalds static const char* wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"}; 6783998b70fSLiam Girdwood static const char* wm9713_rec_src[] = 6793998b70fSLiam Girdwood {"Mic 1", "Mic 2", "Line", "Mono In", "Headphone Mix", "Master Mix", 6803998b70fSLiam Girdwood "Mono Mix", "Zh"}; 6813998b70fSLiam Girdwood static const char* wm9713_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"}; 6823998b70fSLiam Girdwood static const char* wm9713_alc_select[] = {"None", "Left", "Right", "Stereo"}; 6833998b70fSLiam Girdwood static const char* wm9713_mono_pga[] = {"Vmid", "Zh", "Mono Mix", "Inv 1"}; 6843998b70fSLiam Girdwood static const char* wm9713_spk_pga[] = 6853998b70fSLiam Girdwood {"Vmid", "Zh", "Headphone Mix", "Master Mix", "Inv", "NC", "NC", "NC"}; 6863998b70fSLiam Girdwood static const char* wm9713_hp_pga[] = {"Vmid", "Zh", "Headphone Mix", "NC"}; 6873998b70fSLiam Girdwood static const char* wm9713_out3_pga[] = {"Vmid", "Zh", "Inv 1", "NC"}; 6883998b70fSLiam Girdwood static const char* wm9713_out4_pga[] = {"Vmid", "Zh", "Inv 2", "NC"}; 6893998b70fSLiam Girdwood static const char* wm9713_dac_inv[] = 6903998b70fSLiam Girdwood {"Off", "Mono Mix", "Master Mix", "Headphone Mix L", "Headphone Mix R", 6913998b70fSLiam Girdwood "Headphone Mix Mono", "NC", "Vmid"}; 6923998b70fSLiam Girdwood static const char* wm9713_base[] = {"Linear Control", "Adaptive Boost"}; 6933998b70fSLiam Girdwood static const char* wm9713_ng_type[] = {"Constant Gain", "Mute"}; 6941da177e4SLinus Torvalds 6951da177e4SLinus Torvalds static const struct ac97_enum wm9713_enum[] = { 6961da177e4SLinus Torvalds AC97_ENUM_SINGLE(AC97_LINE, 3, 4, wm9713_mic_mixer), 6971da177e4SLinus Torvalds AC97_ENUM_SINGLE(AC97_VIDEO, 14, 4, wm9713_rec_mux), 6981da177e4SLinus Torvalds AC97_ENUM_SINGLE(AC97_VIDEO, 9, 4, wm9713_rec_mux), 6993998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_VIDEO, 3, 0, 8, wm9713_rec_src), 7003998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_CD, 14, 6, 2, wm9713_rec_gain), 7013998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9713_alc_select), 7023998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_REC_GAIN, 14, 4, wm9713_mono_pga), 7033998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_REC_GAIN, 11, 8, 8, wm9713_spk_pga), 7043998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_REC_GAIN, 6, 4, 4, wm9713_hp_pga), 7053998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_REC_GAIN, 2, 4, wm9713_out3_pga), 7063998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_REC_GAIN, 0, 4, wm9713_out4_pga), 7073998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_REC_GAIN_MIC, 13, 10, 8, wm9713_dac_inv), 7083998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, wm9713_base), 7093998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9713_ng_type), 7101da177e4SLinus Torvalds }; 7111da177e4SLinus Torvalds 712ee42381eSTakashi Iwai static const struct snd_kcontrol_new wm13_snd_ac97_controls[] = { 7131da177e4SLinus Torvalds AC97_DOUBLE("Line In Volume", AC97_PC_BEEP, 8, 0, 31, 1), 7143998b70fSLiam Girdwood AC97_SINGLE("Line In to Headphone Switch", AC97_PC_BEEP, 15, 1, 1), 7153998b70fSLiam Girdwood AC97_SINGLE("Line In to Master Switch", AC97_PC_BEEP, 14, 1, 1), 7163998b70fSLiam Girdwood AC97_SINGLE("Line In to Mono Switch", AC97_PC_BEEP, 13, 1, 1), 7173998b70fSLiam Girdwood 7183998b70fSLiam Girdwood AC97_DOUBLE("PCM Playback Volume", AC97_PHONE, 8, 0, 31, 1), 7193998b70fSLiam Girdwood AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PHONE, 15, 1, 1), 7203998b70fSLiam Girdwood AC97_SINGLE("PCM Playback to Master Switch", AC97_PHONE, 14, 1, 1), 7213998b70fSLiam Girdwood AC97_SINGLE("PCM Playback to Mono Switch", AC97_PHONE, 13, 1, 1), 7223998b70fSLiam Girdwood 7233998b70fSLiam Girdwood AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1), 7243998b70fSLiam Girdwood AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1), 7253998b70fSLiam Girdwood AC97_SINGLE("Mic 1 to Mono Switch", AC97_LINE, 7, 1, 1), 7263998b70fSLiam Girdwood AC97_SINGLE("Mic 2 to Mono Switch", AC97_LINE, 6, 1, 1), 727d7f6f115SJames Courtier-Dutton AC97_SINGLE("Mic Boost (+20dB) Switch", AC97_LINE, 5, 1, 0), 7283998b70fSLiam Girdwood AC97_ENUM("Mic to Headphone Mux", wm9713_enum[0]), 7293998b70fSLiam Girdwood AC97_SINGLE("Mic Headphone Mixer Volume", AC97_LINE, 0, 7, 1), 7303998b70fSLiam Girdwood 7313998b70fSLiam Girdwood AC97_SINGLE("Capture Switch", AC97_CD, 15, 1, 1), 7323998b70fSLiam Girdwood AC97_ENUM("Capture Volume Steps", wm9713_enum[4]), 7333998b70fSLiam Girdwood AC97_DOUBLE("Capture Volume", AC97_CD, 8, 0, 15, 0), 7343998b70fSLiam Girdwood AC97_SINGLE("Capture ZC Switch", AC97_CD, 7, 1, 0), 7353998b70fSLiam Girdwood 7363998b70fSLiam Girdwood AC97_ENUM("Capture to Headphone Mux", wm9713_enum[1]), 7373998b70fSLiam Girdwood AC97_SINGLE("Capture to Headphone Volume", AC97_VIDEO, 11, 7, 1), 7383998b70fSLiam Girdwood AC97_ENUM("Capture to Mono Mux", wm9713_enum[2]), 7393998b70fSLiam Girdwood AC97_SINGLE("Capture to Mono Boost (+20dB) Switch", AC97_VIDEO, 8, 1, 0), 7403998b70fSLiam Girdwood AC97_SINGLE("Capture ADC Boost (+20dB) Switch", AC97_VIDEO, 6, 1, 0), 7413998b70fSLiam Girdwood AC97_ENUM("Capture Select", wm9713_enum[3]), 7423998b70fSLiam Girdwood 7433998b70fSLiam Girdwood AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0), 7443998b70fSLiam Girdwood AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0), 7453998b70fSLiam Girdwood AC97_SINGLE("ALC Decay Time ", AC97_CODEC_CLASS_REV, 4, 15, 0), 7463998b70fSLiam Girdwood AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0), 7473998b70fSLiam Girdwood AC97_ENUM("ALC Function", wm9713_enum[5]), 7483998b70fSLiam Girdwood AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 0), 7493998b70fSLiam Girdwood AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 0), 7503998b70fSLiam Girdwood AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0), 7513998b70fSLiam Girdwood AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0), 7523998b70fSLiam Girdwood AC97_ENUM("ALC NG Type", wm9713_enum[13]), 7533998b70fSLiam Girdwood AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 0), 7543998b70fSLiam Girdwood 7553998b70fSLiam Girdwood AC97_DOUBLE("Master ZC Switch", AC97_MASTER, 14, 6, 1, 0), 7563998b70fSLiam Girdwood AC97_DOUBLE("Headphone ZC Switch", AC97_HEADPHONE, 14, 6, 1, 0), 7573998b70fSLiam Girdwood AC97_DOUBLE("Out3/4 ZC Switch", AC97_MASTER_MONO, 14, 6, 1, 0), 7583998b70fSLiam Girdwood AC97_SINGLE("Master Right Switch", AC97_MASTER, 7, 1, 1), 7593998b70fSLiam Girdwood AC97_SINGLE("Headphone Right Switch", AC97_HEADPHONE, 7, 1, 1), 7603998b70fSLiam Girdwood AC97_SINGLE("Out3/4 Right Switch", AC97_MASTER_MONO, 7, 1, 1), 7613998b70fSLiam Girdwood 7623998b70fSLiam Girdwood AC97_SINGLE("Mono In to Headphone Switch", AC97_MASTER_TONE, 15, 1, 1), 7633998b70fSLiam Girdwood AC97_SINGLE("Mono In to Master Switch", AC97_MASTER_TONE, 14, 1, 1), 7643998b70fSLiam Girdwood AC97_SINGLE("Mono In Volume", AC97_MASTER_TONE, 8, 31, 1), 7653998b70fSLiam Girdwood AC97_SINGLE("Mono Switch", AC97_MASTER_TONE, 7, 1, 1), 7663998b70fSLiam Girdwood AC97_SINGLE("Mono ZC Switch", AC97_MASTER_TONE, 6, 1, 0), 7673998b70fSLiam Girdwood AC97_SINGLE("Mono Volume", AC97_MASTER_TONE, 0, 31, 1), 7683998b70fSLiam Girdwood 769d355c82aSJaroslav Kysela AC97_SINGLE("Beep to Headphone Switch", AC97_AUX, 15, 1, 1), 770d355c82aSJaroslav Kysela AC97_SINGLE("Beep to Headphone Volume", AC97_AUX, 12, 7, 1), 771d355c82aSJaroslav Kysela AC97_SINGLE("Beep to Master Switch", AC97_AUX, 11, 1, 1), 772d355c82aSJaroslav Kysela AC97_SINGLE("Beep to Master Volume", AC97_AUX, 8, 7, 1), 773d355c82aSJaroslav Kysela AC97_SINGLE("Beep to Mono Switch", AC97_AUX, 7, 1, 1), 774d355c82aSJaroslav Kysela AC97_SINGLE("Beep to Mono Volume", AC97_AUX, 4, 7, 1), 7753998b70fSLiam Girdwood 7763998b70fSLiam Girdwood AC97_SINGLE("Voice to Headphone Switch", AC97_PCM, 15, 1, 1), 7773998b70fSLiam Girdwood AC97_SINGLE("Voice to Headphone Volume", AC97_PCM, 12, 7, 1), 7783998b70fSLiam Girdwood AC97_SINGLE("Voice to Master Switch", AC97_PCM, 11, 1, 1), 7793998b70fSLiam Girdwood AC97_SINGLE("Voice to Master Volume", AC97_PCM, 8, 7, 1), 7803998b70fSLiam Girdwood AC97_SINGLE("Voice to Mono Switch", AC97_PCM, 7, 1, 1), 7813998b70fSLiam Girdwood AC97_SINGLE("Voice to Mono Volume", AC97_PCM, 4, 7, 1), 7823998b70fSLiam Girdwood 7833998b70fSLiam Girdwood AC97_SINGLE("Aux to Headphone Switch", AC97_REC_SEL, 15, 1, 1), 7843998b70fSLiam Girdwood AC97_SINGLE("Aux to Headphone Volume", AC97_REC_SEL, 12, 7, 1), 7853998b70fSLiam Girdwood AC97_SINGLE("Aux to Master Switch", AC97_REC_SEL, 11, 1, 1), 7863998b70fSLiam Girdwood AC97_SINGLE("Aux to Master Volume", AC97_REC_SEL, 8, 7, 1), 7873998b70fSLiam Girdwood AC97_SINGLE("Aux to Mono Switch", AC97_REC_SEL, 7, 1, 1), 7883998b70fSLiam Girdwood AC97_SINGLE("Aux to Mono Volume", AC97_REC_SEL, 4, 7, 1), 7893998b70fSLiam Girdwood 7903998b70fSLiam Girdwood AC97_ENUM("Mono Input Mux", wm9713_enum[6]), 7913998b70fSLiam Girdwood AC97_ENUM("Master Input Mux", wm9713_enum[7]), 7923998b70fSLiam Girdwood AC97_ENUM("Headphone Input Mux", wm9713_enum[8]), 7933998b70fSLiam Girdwood AC97_ENUM("Out 3 Input Mux", wm9713_enum[9]), 7943998b70fSLiam Girdwood AC97_ENUM("Out 4 Input Mux", wm9713_enum[10]), 7953998b70fSLiam Girdwood 7963998b70fSLiam Girdwood AC97_ENUM("Bass Control", wm9713_enum[12]), 7973998b70fSLiam Girdwood AC97_SINGLE("Bass Cut-off Switch", AC97_GENERAL_PURPOSE, 12, 1, 1), 7983998b70fSLiam Girdwood AC97_SINGLE("Tone Cut-off Switch", AC97_GENERAL_PURPOSE, 4, 1, 1), 7993998b70fSLiam Girdwood AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_GENERAL_PURPOSE, 6, 1, 0), 8003998b70fSLiam Girdwood AC97_SINGLE("Bass Volume", AC97_GENERAL_PURPOSE, 8, 15, 1), 8013998b70fSLiam Girdwood AC97_SINGLE("Tone Volume", AC97_GENERAL_PURPOSE, 0, 15, 1), 8021da177e4SLinus Torvalds }; 8031da177e4SLinus Torvalds 804ee42381eSTakashi Iwai static const struct snd_kcontrol_new wm13_snd_ac97_controls_3d[] = { 8053998b70fSLiam Girdwood AC97_ENUM("Inv Input Mux", wm9713_enum[11]), 8063998b70fSLiam Girdwood AC97_SINGLE("3D Upper Cut-off Switch", AC97_REC_GAIN_MIC, 5, 1, 0), 8073998b70fSLiam Girdwood AC97_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC, 4, 1, 0), 8083998b70fSLiam Girdwood AC97_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1), 8091da177e4SLinus Torvalds }; 8101da177e4SLinus Torvalds 811ee42381eSTakashi Iwai static int patch_wolfson_wm9713_3d (struct snd_ac97 * ac97) 8123998b70fSLiam Girdwood { 8133998b70fSLiam Girdwood int err, i; 8141da177e4SLinus Torvalds 8153998b70fSLiam Girdwood for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_3d); i++) { 8163998b70fSLiam Girdwood if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_3d[i], ac97))) < 0) 8173998b70fSLiam Girdwood return err; 8183998b70fSLiam Girdwood } 8193998b70fSLiam Girdwood return 0; 8203998b70fSLiam Girdwood } 8211da177e4SLinus Torvalds 822ee42381eSTakashi Iwai static int patch_wolfson_wm9713_specific(struct snd_ac97 * ac97) 8231da177e4SLinus Torvalds { 8241da177e4SLinus Torvalds int err, i; 8251da177e4SLinus Torvalds 8263998b70fSLiam Girdwood for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls); i++) { 8273998b70fSLiam Girdwood if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls[i], ac97))) < 0) 8281da177e4SLinus Torvalds return err; 8291da177e4SLinus Torvalds } 8301da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808); 8311da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_PHONE, 0x0808); 8321da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_MIC, 0x0808); 8331da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_LINE, 0x00da); 8341da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_CD, 0x0808); 8351da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_VIDEO, 0xd612); 8361da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x1ba0); 8371da177e4SLinus Torvalds return 0; 8381da177e4SLinus Torvalds } 8391da177e4SLinus Torvalds 8401da177e4SLinus Torvalds #ifdef CONFIG_PM 841ee42381eSTakashi Iwai static void patch_wolfson_wm9713_suspend (struct snd_ac97 * ac97) 8421da177e4SLinus Torvalds { 8431da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xfeff); 8441da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0xffff); 8451da177e4SLinus Torvalds } 8461da177e4SLinus Torvalds 847ee42381eSTakashi Iwai static void patch_wolfson_wm9713_resume (struct snd_ac97 * ac97) 8481da177e4SLinus Torvalds { 8491da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00); 8501da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810); 8511da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0); 8521da177e4SLinus Torvalds } 8531da177e4SLinus Torvalds #endif 8541da177e4SLinus Torvalds 8553e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_wolfson_wm9713_ops = { 8561da177e4SLinus Torvalds .build_specific = patch_wolfson_wm9713_specific, 8573998b70fSLiam Girdwood .build_3d = patch_wolfson_wm9713_3d, 8581da177e4SLinus Torvalds #ifdef CONFIG_PM 8591da177e4SLinus Torvalds .suspend = patch_wolfson_wm9713_suspend, 8601da177e4SLinus Torvalds .resume = patch_wolfson_wm9713_resume 8611da177e4SLinus Torvalds #endif 8621da177e4SLinus Torvalds }; 8631da177e4SLinus Torvalds 864ac519028STakashi Iwai static int patch_wolfson13(struct snd_ac97 * ac97) 8651da177e4SLinus Torvalds { 8663998b70fSLiam Girdwood /* WM9713, WM9714 */ 8671da177e4SLinus Torvalds ac97->build_ops = &patch_wolfson_wm9713_ops; 8681da177e4SLinus Torvalds 8691da177e4SLinus Torvalds ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_PHONE | 8703998b70fSLiam Girdwood AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD | AC97_HAS_NO_TONE | 8713998b70fSLiam Girdwood AC97_HAS_NO_STD_PCM; 872064d2112SLiam Girdwood ac97->scaps &= ~AC97_SCAP_MODEM; 8731da177e4SLinus Torvalds 8741da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00); 8751da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810); 8761da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0); 8771da177e4SLinus Torvalds 8781da177e4SLinus Torvalds return 0; 8791da177e4SLinus Torvalds } 8801da177e4SLinus Torvalds 8811da177e4SLinus Torvalds /* 8821da177e4SLinus Torvalds * Tritech codec 8831da177e4SLinus Torvalds */ 884ac519028STakashi Iwai static int patch_tritech_tr28028(struct snd_ac97 * ac97) 8851da177e4SLinus Torvalds { 8861da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x26, 0x0300); 8871da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x26, 0x0000); 8881da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SURROUND_MASTER, 0x0000); 8891da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SPDIF, 0x0000); 8901da177e4SLinus Torvalds return 0; 8911da177e4SLinus Torvalds } 8921da177e4SLinus Torvalds 8931da177e4SLinus Torvalds /* 8941da177e4SLinus Torvalds * Sigmatel STAC97xx codecs 8951da177e4SLinus Torvalds */ 896ee42381eSTakashi Iwai static int patch_sigmatel_stac9700_3d(struct snd_ac97 * ac97) 8971da177e4SLinus Torvalds { 898ee42381eSTakashi Iwai struct snd_kcontrol *kctl; 8991da177e4SLinus Torvalds int err; 9001da177e4SLinus Torvalds 9011da177e4SLinus Torvalds if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0) 9021da177e4SLinus Torvalds return err; 9031da177e4SLinus Torvalds strcpy(kctl->id.name, "3D Control Sigmatel - Depth"); 9041da177e4SLinus Torvalds kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0); 9051da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000); 9061da177e4SLinus Torvalds return 0; 9071da177e4SLinus Torvalds } 9081da177e4SLinus Torvalds 909ee42381eSTakashi Iwai static int patch_sigmatel_stac9708_3d(struct snd_ac97 * ac97) 9101da177e4SLinus Torvalds { 911ee42381eSTakashi Iwai struct snd_kcontrol *kctl; 9121da177e4SLinus Torvalds int err; 9131da177e4SLinus Torvalds 9141da177e4SLinus Torvalds if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0) 9151da177e4SLinus Torvalds return err; 9161da177e4SLinus Torvalds strcpy(kctl->id.name, "3D Control Sigmatel - Depth"); 9171da177e4SLinus Torvalds kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 0, 3, 0); 9181da177e4SLinus Torvalds if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0) 9191da177e4SLinus Torvalds return err; 9201da177e4SLinus Torvalds strcpy(kctl->id.name, "3D Control Sigmatel - Rear Depth"); 9211da177e4SLinus Torvalds kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0); 9221da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000); 9231da177e4SLinus Torvalds return 0; 9241da177e4SLinus Torvalds } 9251da177e4SLinus Torvalds 926ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_sigmatel_4speaker = 927afe6d7e3SAndreas Mohr AC97_SINGLE("Sigmatel 4-Speaker Stereo Playback Switch", 928afe6d7e3SAndreas Mohr AC97_SIGMATEL_DAC2INVERT, 2, 1, 0); 9291da177e4SLinus Torvalds 930afe6d7e3SAndreas Mohr /* "Sigmatel " removed due to excessive name length: */ 931ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_sigmatel_phaseinvert = 932afe6d7e3SAndreas Mohr AC97_SINGLE("Surround Phase Inversion Playback Switch", 933afe6d7e3SAndreas Mohr AC97_SIGMATEL_DAC2INVERT, 3, 1, 0); 9341da177e4SLinus Torvalds 935ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_sigmatel_controls[] = { 9361da177e4SLinus Torvalds AC97_SINGLE("Sigmatel DAC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 1, 1, 0), 9371da177e4SLinus Torvalds AC97_SINGLE("Sigmatel ADC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 0, 1, 0) 9381da177e4SLinus Torvalds }; 9391da177e4SLinus Torvalds 940ee42381eSTakashi Iwai static int patch_sigmatel_stac97xx_specific(struct snd_ac97 * ac97) 9411da177e4SLinus Torvalds { 9421da177e4SLinus Torvalds int err; 9431da177e4SLinus Torvalds 9441da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_ANALOG, snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) & ~0x0003); 9451da177e4SLinus Torvalds if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 1)) 9461da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[0], 1)) < 0) 9471da177e4SLinus Torvalds return err; 9481da177e4SLinus Torvalds if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 0)) 9491da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[1], 1)) < 0) 9501da177e4SLinus Torvalds return err; 9511da177e4SLinus Torvalds if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 2)) 9521da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_4speaker, 1)) < 0) 9531da177e4SLinus Torvalds return err; 9541da177e4SLinus Torvalds if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 3)) 9551da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_phaseinvert, 1)) < 0) 9561da177e4SLinus Torvalds return err; 9571da177e4SLinus Torvalds return 0; 9581da177e4SLinus Torvalds } 9591da177e4SLinus Torvalds 9603e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_sigmatel_stac9700_ops = { 9611da177e4SLinus Torvalds .build_3d = patch_sigmatel_stac9700_3d, 9621da177e4SLinus Torvalds .build_specific = patch_sigmatel_stac97xx_specific 9631da177e4SLinus Torvalds }; 9641da177e4SLinus Torvalds 965ac519028STakashi Iwai static int patch_sigmatel_stac9700(struct snd_ac97 * ac97) 9661da177e4SLinus Torvalds { 9671da177e4SLinus Torvalds ac97->build_ops = &patch_sigmatel_stac9700_ops; 9681da177e4SLinus Torvalds return 0; 9691da177e4SLinus Torvalds } 9701da177e4SLinus Torvalds 971ee42381eSTakashi Iwai static int snd_ac97_stac9708_put_bias(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 9721da177e4SLinus Torvalds { 973ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 9741da177e4SLinus Torvalds int err; 9751da177e4SLinus Torvalds 97662932df8SIngo Molnar mutex_lock(&ac97->page_mutex); 9771da177e4SLinus Torvalds snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0xabba); 9781da177e4SLinus Torvalds err = snd_ac97_update_bits(ac97, AC97_SIGMATEL_BIAS2, 0x0010, 9791da177e4SLinus Torvalds (ucontrol->value.integer.value[0] & 1) << 4); 9801da177e4SLinus Torvalds snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0); 98162932df8SIngo Molnar mutex_unlock(&ac97->page_mutex); 9821da177e4SLinus Torvalds return err; 9831da177e4SLinus Torvalds } 9841da177e4SLinus Torvalds 985ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_stac9708_bias_control = { 9861da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 9871da177e4SLinus Torvalds .name = "Sigmatel Output Bias Switch", 9881da177e4SLinus Torvalds .info = snd_ac97_info_volsw, 9891da177e4SLinus Torvalds .get = snd_ac97_get_volsw, 9901da177e4SLinus Torvalds .put = snd_ac97_stac9708_put_bias, 9911da177e4SLinus Torvalds .private_value = AC97_SINGLE_VALUE(AC97_SIGMATEL_BIAS2, 4, 1, 0), 9921da177e4SLinus Torvalds }; 9931da177e4SLinus Torvalds 994ee42381eSTakashi Iwai static int patch_sigmatel_stac9708_specific(struct snd_ac97 *ac97) 9951da177e4SLinus Torvalds { 9961da177e4SLinus Torvalds int err; 9971da177e4SLinus Torvalds 998e4c3bf0fSJames C Georgas /* the register bit is writable, but the function is not implemented: */ 999e4c3bf0fSJames C Georgas snd_ac97_remove_ctl(ac97, "PCM Out Path & Mute", NULL); 1000e4c3bf0fSJames C Georgas 10011da177e4SLinus Torvalds snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Sigmatel Surround Playback"); 10021da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_stac9708_bias_control, 1)) < 0) 10031da177e4SLinus Torvalds return err; 10041da177e4SLinus Torvalds return patch_sigmatel_stac97xx_specific(ac97); 10051da177e4SLinus Torvalds } 10061da177e4SLinus Torvalds 10073e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_sigmatel_stac9708_ops = { 10081da177e4SLinus Torvalds .build_3d = patch_sigmatel_stac9708_3d, 10091da177e4SLinus Torvalds .build_specific = patch_sigmatel_stac9708_specific 10101da177e4SLinus Torvalds }; 10111da177e4SLinus Torvalds 1012ac519028STakashi Iwai static int patch_sigmatel_stac9708(struct snd_ac97 * ac97) 10131da177e4SLinus Torvalds { 10141da177e4SLinus Torvalds unsigned int codec72, codec6c; 10151da177e4SLinus Torvalds 10161da177e4SLinus Torvalds ac97->build_ops = &patch_sigmatel_stac9708_ops; 10171da177e4SLinus Torvalds ac97->caps |= 0x10; /* HP (sigmatel surround) support */ 10181da177e4SLinus Torvalds 10191da177e4SLinus Torvalds codec72 = snd_ac97_read(ac97, AC97_SIGMATEL_BIAS2) & 0x8000; 10201da177e4SLinus Torvalds codec6c = snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG); 10211da177e4SLinus Torvalds 10221da177e4SLinus Torvalds if ((codec72==0) && (codec6c==0)) { 10231da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); 10241da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1000); 10251da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba); 10261da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0007); 10271da177e4SLinus Torvalds } else if ((codec72==0x8000) && (codec6c==0)) { 10281da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); 10291da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1001); 10301da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_DAC2INVERT, 0x0008); 10311da177e4SLinus Torvalds } else if ((codec72==0x8000) && (codec6c==0x0080)) { 10321da177e4SLinus Torvalds /* nothing */ 10331da177e4SLinus Torvalds } 10341da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000); 10351da177e4SLinus Torvalds return 0; 10361da177e4SLinus Torvalds } 10371da177e4SLinus Torvalds 1038ac519028STakashi Iwai static int patch_sigmatel_stac9721(struct snd_ac97 * ac97) 10391da177e4SLinus Torvalds { 10401da177e4SLinus Torvalds ac97->build_ops = &patch_sigmatel_stac9700_ops; 10411da177e4SLinus Torvalds if (snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) == 0) { 10421da177e4SLinus Torvalds // patch for SigmaTel 10431da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); 10441da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x4000); 10451da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba); 10461da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002); 10471da177e4SLinus Torvalds } 10481da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000); 10491da177e4SLinus Torvalds return 0; 10501da177e4SLinus Torvalds } 10511da177e4SLinus Torvalds 1052ac519028STakashi Iwai static int patch_sigmatel_stac9744(struct snd_ac97 * ac97) 10531da177e4SLinus Torvalds { 10541da177e4SLinus Torvalds // patch for SigmaTel 10551da177e4SLinus Torvalds ac97->build_ops = &patch_sigmatel_stac9700_ops; 10561da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); 10571da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */ 10581da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba); 10591da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002); 10601da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000); 10611da177e4SLinus Torvalds return 0; 10621da177e4SLinus Torvalds } 10631da177e4SLinus Torvalds 1064ac519028STakashi Iwai static int patch_sigmatel_stac9756(struct snd_ac97 * ac97) 10651da177e4SLinus Torvalds { 10661da177e4SLinus Torvalds // patch for SigmaTel 10671da177e4SLinus Torvalds ac97->build_ops = &patch_sigmatel_stac9700_ops; 10681da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); 10691da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */ 10701da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba); 10711da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002); 10721da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000); 10731da177e4SLinus Torvalds return 0; 10741da177e4SLinus Torvalds } 10751da177e4SLinus Torvalds 1076ee42381eSTakashi Iwai static int snd_ac97_stac9758_output_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 10771da177e4SLinus Torvalds { 10783b7a00dcSTakashi Iwai static const char * const texts[5] = { 10793b7a00dcSTakashi Iwai "Input/Disabled", "Front Output", 10801da177e4SLinus Torvalds "Rear Output", "Center/LFE Output", "Mixer Output" }; 10811da177e4SLinus Torvalds 10823b7a00dcSTakashi Iwai return snd_ctl_enum_info(uinfo, 1, 5, texts); 10831da177e4SLinus Torvalds } 10841da177e4SLinus Torvalds 1085ee42381eSTakashi Iwai static int snd_ac97_stac9758_output_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 10861da177e4SLinus Torvalds { 1087ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 10881da177e4SLinus Torvalds int shift = kcontrol->private_value; 10891da177e4SLinus Torvalds unsigned short val; 10901da177e4SLinus Torvalds 10911da177e4SLinus Torvalds val = ac97->regs[AC97_SIGMATEL_OUTSEL] >> shift; 10921da177e4SLinus Torvalds if (!(val & 4)) 10931da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = 0; 10941da177e4SLinus Torvalds else 10951da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = 1 + (val & 3); 10961da177e4SLinus Torvalds return 0; 10971da177e4SLinus Torvalds } 10981da177e4SLinus Torvalds 1099ee42381eSTakashi Iwai static int snd_ac97_stac9758_output_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 11001da177e4SLinus Torvalds { 1101ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 11021da177e4SLinus Torvalds int shift = kcontrol->private_value; 11031da177e4SLinus Torvalds unsigned short val; 11041da177e4SLinus Torvalds 11051da177e4SLinus Torvalds if (ucontrol->value.enumerated.item[0] > 4) 11061da177e4SLinus Torvalds return -EINVAL; 11071da177e4SLinus Torvalds if (ucontrol->value.enumerated.item[0] == 0) 11081da177e4SLinus Torvalds val = 0; 11091da177e4SLinus Torvalds else 11101da177e4SLinus Torvalds val = 4 | (ucontrol->value.enumerated.item[0] - 1); 11111da177e4SLinus Torvalds return ac97_update_bits_page(ac97, AC97_SIGMATEL_OUTSEL, 11121da177e4SLinus Torvalds 7 << shift, val << shift, 0); 11131da177e4SLinus Torvalds } 11141da177e4SLinus Torvalds 1115ee42381eSTakashi Iwai static int snd_ac97_stac9758_input_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 11161da177e4SLinus Torvalds { 11173b7a00dcSTakashi Iwai static const char * const texts[7] = { 11183b7a00dcSTakashi Iwai "Mic2 Jack", "Mic1 Jack", "Line In Jack", 11191da177e4SLinus Torvalds "Front Jack", "Rear Jack", "Center/LFE Jack", "Mute" }; 11201da177e4SLinus Torvalds 11213b7a00dcSTakashi Iwai return snd_ctl_enum_info(uinfo, 1, 7, texts); 11221da177e4SLinus Torvalds } 11231da177e4SLinus Torvalds 1124ee42381eSTakashi Iwai static int snd_ac97_stac9758_input_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 11251da177e4SLinus Torvalds { 1126ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 11271da177e4SLinus Torvalds int shift = kcontrol->private_value; 11281da177e4SLinus Torvalds unsigned short val; 11291da177e4SLinus Torvalds 11301da177e4SLinus Torvalds val = ac97->regs[AC97_SIGMATEL_INSEL]; 11311da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = (val >> shift) & 7; 11321da177e4SLinus Torvalds return 0; 11331da177e4SLinus Torvalds } 11341da177e4SLinus Torvalds 1135ee42381eSTakashi Iwai static int snd_ac97_stac9758_input_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 11361da177e4SLinus Torvalds { 1137ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 11381da177e4SLinus Torvalds int shift = kcontrol->private_value; 11391da177e4SLinus Torvalds 11401da177e4SLinus Torvalds return ac97_update_bits_page(ac97, AC97_SIGMATEL_INSEL, 7 << shift, 11411da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] << shift, 0); 11421da177e4SLinus Torvalds } 11431da177e4SLinus Torvalds 1144ee42381eSTakashi Iwai static int snd_ac97_stac9758_phonesel_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 11451da177e4SLinus Torvalds { 11463b7a00dcSTakashi Iwai static const char * const texts[3] = { 11473b7a00dcSTakashi Iwai "None", "Front Jack", "Rear Jack" 11483b7a00dcSTakashi Iwai }; 11491da177e4SLinus Torvalds 11503b7a00dcSTakashi Iwai return snd_ctl_enum_info(uinfo, 1, 3, texts); 11511da177e4SLinus Torvalds } 11521da177e4SLinus Torvalds 1153ee42381eSTakashi Iwai static int snd_ac97_stac9758_phonesel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 11541da177e4SLinus Torvalds { 1155ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 11561da177e4SLinus Torvalds 11571da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = ac97->regs[AC97_SIGMATEL_IOMISC] & 3; 11581da177e4SLinus Torvalds return 0; 11591da177e4SLinus Torvalds } 11601da177e4SLinus Torvalds 1161ee42381eSTakashi Iwai static int snd_ac97_stac9758_phonesel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 11621da177e4SLinus Torvalds { 1163ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 11641da177e4SLinus Torvalds 11651da177e4SLinus Torvalds return ac97_update_bits_page(ac97, AC97_SIGMATEL_IOMISC, 3, 11661da177e4SLinus Torvalds ucontrol->value.enumerated.item[0], 0); 11671da177e4SLinus Torvalds } 11681da177e4SLinus Torvalds 11691da177e4SLinus Torvalds #define STAC9758_OUTPUT_JACK(xname, shift) \ 11701da177e4SLinus Torvalds { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 11711da177e4SLinus Torvalds .info = snd_ac97_stac9758_output_jack_info, \ 11721da177e4SLinus Torvalds .get = snd_ac97_stac9758_output_jack_get, \ 11731da177e4SLinus Torvalds .put = snd_ac97_stac9758_output_jack_put, \ 11741da177e4SLinus Torvalds .private_value = shift } 11751da177e4SLinus Torvalds #define STAC9758_INPUT_JACK(xname, shift) \ 11761da177e4SLinus Torvalds { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 11771da177e4SLinus Torvalds .info = snd_ac97_stac9758_input_jack_info, \ 11781da177e4SLinus Torvalds .get = snd_ac97_stac9758_input_jack_get, \ 11791da177e4SLinus Torvalds .put = snd_ac97_stac9758_input_jack_put, \ 11801da177e4SLinus Torvalds .private_value = shift } 1181ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_sigmatel_stac9758_controls[] = { 11821da177e4SLinus Torvalds STAC9758_OUTPUT_JACK("Mic1 Jack", 1), 11831da177e4SLinus Torvalds STAC9758_OUTPUT_JACK("LineIn Jack", 4), 11841da177e4SLinus Torvalds STAC9758_OUTPUT_JACK("Front Jack", 7), 11851da177e4SLinus Torvalds STAC9758_OUTPUT_JACK("Rear Jack", 10), 11861da177e4SLinus Torvalds STAC9758_OUTPUT_JACK("Center/LFE Jack", 13), 11871da177e4SLinus Torvalds STAC9758_INPUT_JACK("Mic Input Source", 0), 11881da177e4SLinus Torvalds STAC9758_INPUT_JACK("Line Input Source", 8), 11891da177e4SLinus Torvalds { 11901da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 11911da177e4SLinus Torvalds .name = "Headphone Amp", 11921da177e4SLinus Torvalds .info = snd_ac97_stac9758_phonesel_info, 11931da177e4SLinus Torvalds .get = snd_ac97_stac9758_phonesel_get, 11941da177e4SLinus Torvalds .put = snd_ac97_stac9758_phonesel_put 11951da177e4SLinus Torvalds }, 11961da177e4SLinus Torvalds AC97_SINGLE("Exchange Center/LFE", AC97_SIGMATEL_IOMISC, 4, 1, 0), 11971da177e4SLinus Torvalds AC97_SINGLE("Headphone +3dB Boost", AC97_SIGMATEL_IOMISC, 8, 1, 0) 11981da177e4SLinus Torvalds }; 11991da177e4SLinus Torvalds 1200ee42381eSTakashi Iwai static int patch_sigmatel_stac9758_specific(struct snd_ac97 *ac97) 12011da177e4SLinus Torvalds { 12021da177e4SLinus Torvalds int err; 12031da177e4SLinus Torvalds 12041da177e4SLinus Torvalds err = patch_sigmatel_stac97xx_specific(ac97); 12051da177e4SLinus Torvalds if (err < 0) 12061da177e4SLinus Torvalds return err; 12071da177e4SLinus Torvalds err = patch_build_controls(ac97, snd_ac97_sigmatel_stac9758_controls, 12081da177e4SLinus Torvalds ARRAY_SIZE(snd_ac97_sigmatel_stac9758_controls)); 12091da177e4SLinus Torvalds if (err < 0) 12101da177e4SLinus Torvalds return err; 12111da177e4SLinus Torvalds /* DAC-A direct */ 12121da177e4SLinus Torvalds snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Front Playback"); 12131da177e4SLinus Torvalds /* DAC-A to Mix = PCM */ 12141da177e4SLinus Torvalds /* DAC-B direct = Surround */ 12151da177e4SLinus Torvalds /* DAC-B to Mix */ 12161da177e4SLinus Torvalds snd_ac97_rename_vol_ctl(ac97, "Video Playback", "Surround Mix Playback"); 12171da177e4SLinus Torvalds /* DAC-C direct = Center/LFE */ 12181da177e4SLinus Torvalds 12191da177e4SLinus Torvalds return 0; 12201da177e4SLinus Torvalds } 12211da177e4SLinus Torvalds 12223e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_sigmatel_stac9758_ops = { 12231da177e4SLinus Torvalds .build_3d = patch_sigmatel_stac9700_3d, 12241da177e4SLinus Torvalds .build_specific = patch_sigmatel_stac9758_specific 12251da177e4SLinus Torvalds }; 12261da177e4SLinus Torvalds 1227ac519028STakashi Iwai static int patch_sigmatel_stac9758(struct snd_ac97 * ac97) 12281da177e4SLinus Torvalds { 12291da177e4SLinus Torvalds static unsigned short regs[4] = { 12301da177e4SLinus Torvalds AC97_SIGMATEL_OUTSEL, 12311da177e4SLinus Torvalds AC97_SIGMATEL_IOMISC, 12321da177e4SLinus Torvalds AC97_SIGMATEL_INSEL, 12331da177e4SLinus Torvalds AC97_SIGMATEL_VARIOUS 12341da177e4SLinus Torvalds }; 12351da177e4SLinus Torvalds static unsigned short def_regs[4] = { 12361da177e4SLinus Torvalds /* OUTSEL */ 0xd794, /* CL:CL, SR:SR, LO:MX, LI:DS, MI:DS */ 12371da177e4SLinus Torvalds /* IOMISC */ 0x2001, 12381da177e4SLinus Torvalds /* INSEL */ 0x0201, /* LI:LI, MI:M1 */ 12391da177e4SLinus Torvalds /* VARIOUS */ 0x0040 12401da177e4SLinus Torvalds }; 12411da177e4SLinus Torvalds static unsigned short m675_regs[4] = { 12421da177e4SLinus Torvalds /* OUTSEL */ 0xfc70, /* CL:MX, SR:MX, LO:DS, LI:MX, MI:DS */ 12431da177e4SLinus Torvalds /* IOMISC */ 0x2102, /* HP amp on */ 12441da177e4SLinus Torvalds /* INSEL */ 0x0203, /* LI:LI, MI:FR */ 12451da177e4SLinus Torvalds /* VARIOUS */ 0x0041 /* stereo mic */ 12461da177e4SLinus Torvalds }; 12471da177e4SLinus Torvalds unsigned short *pregs = def_regs; 12481da177e4SLinus Torvalds int i; 12491da177e4SLinus Torvalds 12501da177e4SLinus Torvalds /* Gateway M675 notebook */ 12511da177e4SLinus Torvalds if (ac97->pci && 12521da177e4SLinus Torvalds ac97->subsystem_vendor == 0x107b && 12531da177e4SLinus Torvalds ac97->subsystem_device == 0x0601) 12541da177e4SLinus Torvalds pregs = m675_regs; 12551da177e4SLinus Torvalds 12561da177e4SLinus Torvalds // patch for SigmaTel 12571da177e4SLinus Torvalds ac97->build_ops = &patch_sigmatel_stac9758_ops; 12581da177e4SLinus Torvalds /* FIXME: assume only page 0 for writing cache */ 12591da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR); 12601da177e4SLinus Torvalds for (i = 0; i < 4; i++) 12611da177e4SLinus Torvalds snd_ac97_write_cache(ac97, regs[i], pregs[i]); 12621da177e4SLinus Torvalds 12631da177e4SLinus Torvalds ac97->flags |= AC97_STEREO_MUTES; 12641da177e4SLinus Torvalds return 0; 12651da177e4SLinus Torvalds } 12661da177e4SLinus Torvalds 12671da177e4SLinus Torvalds /* 12681da177e4SLinus Torvalds * Cirrus Logic CS42xx codecs 12691da177e4SLinus Torvalds */ 1270ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_cirrus_controls_spdif[2] = { 12711da177e4SLinus Torvalds AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CSR_SPDIF, 15, 1, 0), 12721da177e4SLinus Torvalds AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "AC97-SPSA", AC97_CSR_ACMODE, 0, 3, 0) 12731da177e4SLinus Torvalds }; 12741da177e4SLinus Torvalds 1275ee42381eSTakashi Iwai static int patch_cirrus_build_spdif(struct snd_ac97 * ac97) 12761da177e4SLinus Torvalds { 12771da177e4SLinus Torvalds int err; 12781da177e4SLinus Torvalds 12791da177e4SLinus Torvalds /* con mask, pro mask, default */ 12801da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0) 12811da177e4SLinus Torvalds return err; 12821da177e4SLinus Torvalds /* switch, spsa */ 12831da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[0], 1)) < 0) 12841da177e4SLinus Torvalds return err; 12851da177e4SLinus Torvalds switch (ac97->id & AC97_ID_CS_MASK) { 12861da177e4SLinus Torvalds case AC97_ID_CS4205: 12871da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[1], 1)) < 0) 12881da177e4SLinus Torvalds return err; 12891da177e4SLinus Torvalds break; 12901da177e4SLinus Torvalds } 12911da177e4SLinus Torvalds /* set default PCM S/PDIF params */ 12921da177e4SLinus Torvalds /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */ 12931da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_CSR_SPDIF, 0x0a20); 12941da177e4SLinus Torvalds return 0; 12951da177e4SLinus Torvalds } 12961da177e4SLinus Torvalds 12973e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_cirrus_ops = { 12981da177e4SLinus Torvalds .build_spdif = patch_cirrus_build_spdif 12991da177e4SLinus Torvalds }; 13001da177e4SLinus Torvalds 1301ac519028STakashi Iwai static int patch_cirrus_spdif(struct snd_ac97 * ac97) 13021da177e4SLinus Torvalds { 13031da177e4SLinus Torvalds /* Basically, the cs4201/cs4205/cs4297a has non-standard sp/dif registers. 13041da177e4SLinus Torvalds WHY CAN'T ANYONE FOLLOW THE BLOODY SPEC? *sigh* 13051da177e4SLinus Torvalds - sp/dif EA ID is not set, but sp/dif is always present. 13061da177e4SLinus Torvalds - enable/disable is spdif register bit 15. 13071da177e4SLinus Torvalds - sp/dif control register is 0x68. differs from AC97: 13081da177e4SLinus Torvalds - valid is bit 14 (vs 15) 13091da177e4SLinus Torvalds - no DRS 13101da177e4SLinus Torvalds - only 44.1/48k [00 = 48, 01=44,1] (AC97 is 00=44.1, 10=48) 13111da177e4SLinus Torvalds - sp/dif ssource select is in 0x5e bits 0,1. 13121da177e4SLinus Torvalds */ 13131da177e4SLinus Torvalds 13141da177e4SLinus Torvalds ac97->build_ops = &patch_cirrus_ops; 13151da177e4SLinus Torvalds ac97->flags |= AC97_CS_SPDIF; 13161da177e4SLinus Torvalds ac97->rates[AC97_RATES_SPDIF] &= ~SNDRV_PCM_RATE_32000; 13171da177e4SLinus Torvalds ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */ 13181da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_CSR_ACMODE, 0x0080); 13191da177e4SLinus Torvalds return 0; 13201da177e4SLinus Torvalds } 13211da177e4SLinus Torvalds 1322ac519028STakashi Iwai static int patch_cirrus_cs4299(struct snd_ac97 * ac97) 13231da177e4SLinus Torvalds { 13241da177e4SLinus Torvalds /* force the detection of PC Beep */ 13251da177e4SLinus Torvalds ac97->flags |= AC97_HAS_PC_BEEP; 13261da177e4SLinus Torvalds 13271da177e4SLinus Torvalds return patch_cirrus_spdif(ac97); 13281da177e4SLinus Torvalds } 13291da177e4SLinus Torvalds 13301da177e4SLinus Torvalds /* 13311da177e4SLinus Torvalds * Conexant codecs 13321da177e4SLinus Torvalds */ 1333ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_conexant_controls_spdif[1] = { 13341da177e4SLinus Torvalds AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CXR_AUDIO_MISC, 3, 1, 0), 13351da177e4SLinus Torvalds }; 13361da177e4SLinus Torvalds 1337ee42381eSTakashi Iwai static int patch_conexant_build_spdif(struct snd_ac97 * ac97) 13381da177e4SLinus Torvalds { 13391da177e4SLinus Torvalds int err; 13401da177e4SLinus Torvalds 13411da177e4SLinus Torvalds /* con mask, pro mask, default */ 13421da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0) 13431da177e4SLinus Torvalds return err; 13441da177e4SLinus Torvalds /* switch */ 13451da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_conexant_controls_spdif[0], 1)) < 0) 13461da177e4SLinus Torvalds return err; 13471da177e4SLinus Torvalds /* set default PCM S/PDIF params */ 13481da177e4SLinus Torvalds /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */ 13491da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_CXR_AUDIO_MISC, 13501da177e4SLinus Torvalds snd_ac97_read(ac97, AC97_CXR_AUDIO_MISC) & ~(AC97_CXR_SPDIFEN|AC97_CXR_COPYRGT|AC97_CXR_SPDIF_MASK)); 13511da177e4SLinus Torvalds return 0; 13521da177e4SLinus Torvalds } 13531da177e4SLinus Torvalds 13543e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_conexant_ops = { 13551da177e4SLinus Torvalds .build_spdif = patch_conexant_build_spdif 13561da177e4SLinus Torvalds }; 13571da177e4SLinus Torvalds 1358ac519028STakashi Iwai static int patch_conexant(struct snd_ac97 * ac97) 13591da177e4SLinus Torvalds { 13601da177e4SLinus Torvalds ac97->build_ops = &patch_conexant_ops; 13611da177e4SLinus Torvalds ac97->flags |= AC97_CX_SPDIF; 13621da177e4SLinus Torvalds ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */ 13631da177e4SLinus Torvalds ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */ 13641da177e4SLinus Torvalds return 0; 13651da177e4SLinus Torvalds } 13661da177e4SLinus Torvalds 1367ac519028STakashi Iwai static int patch_cx20551(struct snd_ac97 *ac97) 13689e292c00STakashi Iwai { 13699e292c00STakashi Iwai snd_ac97_update_bits(ac97, 0x5c, 0x01, 0x01); 13709e292c00STakashi Iwai return 0; 13719e292c00STakashi Iwai } 13729e292c00STakashi Iwai 13731da177e4SLinus Torvalds /* 13741da177e4SLinus Torvalds * Analog Device AD18xx, AD19xx codecs 13751da177e4SLinus Torvalds */ 13761da177e4SLinus Torvalds #ifdef CONFIG_PM 1377ee42381eSTakashi Iwai static void ad18xx_resume(struct snd_ac97 *ac97) 13781da177e4SLinus Torvalds { 13791da177e4SLinus Torvalds static unsigned short setup_regs[] = { 13801da177e4SLinus Torvalds AC97_AD_MISC, AC97_AD_SERIAL_CFG, AC97_AD_JACK_SPDIF, 13811da177e4SLinus Torvalds }; 13821da177e4SLinus Torvalds int i, codec; 13831da177e4SLinus Torvalds 13841da177e4SLinus Torvalds for (i = 0; i < (int)ARRAY_SIZE(setup_regs); i++) { 13851da177e4SLinus Torvalds unsigned short reg = setup_regs[i]; 13861da177e4SLinus Torvalds if (test_bit(reg, ac97->reg_accessed)) { 13871da177e4SLinus Torvalds snd_ac97_write(ac97, reg, ac97->regs[reg]); 13881da177e4SLinus Torvalds snd_ac97_read(ac97, reg); 13891da177e4SLinus Torvalds } 13901da177e4SLinus Torvalds } 13911da177e4SLinus Torvalds 13921da177e4SLinus Torvalds if (! (ac97->flags & AC97_AD_MULTI)) 13931da177e4SLinus Torvalds /* normal restore */ 13941da177e4SLinus Torvalds snd_ac97_restore_status(ac97); 13951da177e4SLinus Torvalds else { 13961da177e4SLinus Torvalds /* restore the AD18xx codec configurations */ 13971da177e4SLinus Torvalds for (codec = 0; codec < 3; codec++) { 13981da177e4SLinus Torvalds if (! ac97->spec.ad18xx.id[codec]) 13991da177e4SLinus Torvalds continue; 14001da177e4SLinus Torvalds /* select single codec */ 14011da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 14021da177e4SLinus Torvalds ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]); 14031da177e4SLinus Torvalds ac97->bus->ops->write(ac97, AC97_AD_CODEC_CFG, ac97->spec.ad18xx.codec_cfg[codec]); 14041da177e4SLinus Torvalds } 14051da177e4SLinus Torvalds /* select all codecs */ 14061da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000); 14071da177e4SLinus Torvalds 14081da177e4SLinus Torvalds /* restore status */ 14091da177e4SLinus Torvalds for (i = 2; i < 0x7c ; i += 2) { 14101da177e4SLinus Torvalds if (i == AC97_POWERDOWN || i == AC97_EXTENDED_ID) 14111da177e4SLinus Torvalds continue; 14121da177e4SLinus Torvalds if (test_bit(i, ac97->reg_accessed)) { 14131da177e4SLinus Torvalds /* handle multi codecs for AD18xx */ 14141da177e4SLinus Torvalds if (i == AC97_PCM) { 14151da177e4SLinus Torvalds for (codec = 0; codec < 3; codec++) { 14161da177e4SLinus Torvalds if (! ac97->spec.ad18xx.id[codec]) 14171da177e4SLinus Torvalds continue; 14181da177e4SLinus Torvalds /* select single codec */ 14191da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 14201da177e4SLinus Torvalds ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]); 14211da177e4SLinus Torvalds /* update PCM bits */ 14221da177e4SLinus Torvalds ac97->bus->ops->write(ac97, AC97_PCM, ac97->spec.ad18xx.pcmreg[codec]); 14231da177e4SLinus Torvalds } 14241da177e4SLinus Torvalds /* select all codecs */ 14251da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000); 14261da177e4SLinus Torvalds continue; 14271da177e4SLinus Torvalds } else if (i == AC97_AD_TEST || 14281da177e4SLinus Torvalds i == AC97_AD_CODEC_CFG || 14291da177e4SLinus Torvalds i == AC97_AD_SERIAL_CFG) 14301da177e4SLinus Torvalds continue; /* ignore */ 14311da177e4SLinus Torvalds } 14321da177e4SLinus Torvalds snd_ac97_write(ac97, i, ac97->regs[i]); 14331da177e4SLinus Torvalds snd_ac97_read(ac97, i); 14341da177e4SLinus Torvalds } 14351da177e4SLinus Torvalds } 14361da177e4SLinus Torvalds 14371da177e4SLinus Torvalds snd_ac97_restore_iec958(ac97); 14381da177e4SLinus Torvalds } 14391561f09aSJaya Kumar 14401561f09aSJaya Kumar static void ad1888_resume(struct snd_ac97 *ac97) 14411561f09aSJaya Kumar { 14421561f09aSJaya Kumar ad18xx_resume(ac97); 14431561f09aSJaya Kumar snd_ac97_write_cache(ac97, AC97_CODEC_CLASS_REV, 0x8080); 14441561f09aSJaya Kumar } 14451561f09aSJaya Kumar 14461da177e4SLinus Torvalds #endif 14471da177e4SLinus Torvalds 1448bd25b7caSVille Syrjala static const struct snd_ac97_res_table ad1819_restbl[] = { 1449bd25b7caSVille Syrjala { AC97_PHONE, 0x9f1f }, 1450bd25b7caSVille Syrjala { AC97_MIC, 0x9f1f }, 1451bd25b7caSVille Syrjala { AC97_LINE, 0x9f1f }, 1452bd25b7caSVille Syrjala { AC97_CD, 0x9f1f }, 1453bd25b7caSVille Syrjala { AC97_VIDEO, 0x9f1f }, 1454bd25b7caSVille Syrjala { AC97_AUX, 0x9f1f }, 1455bd25b7caSVille Syrjala { AC97_PCM, 0x9f1f }, 1456bd25b7caSVille Syrjala { } /* terminator */ 1457bd25b7caSVille Syrjala }; 1458bd25b7caSVille Syrjala 1459ac519028STakashi Iwai static int patch_ad1819(struct snd_ac97 * ac97) 14601da177e4SLinus Torvalds { 14611da177e4SLinus Torvalds unsigned short scfg; 14621da177e4SLinus Torvalds 14631da177e4SLinus Torvalds // patch for Analog Devices 14641da177e4SLinus Torvalds scfg = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG); 14651da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, scfg | 0x7000); /* select all codecs */ 1466bd25b7caSVille Syrjala ac97->res_table = ad1819_restbl; 14671da177e4SLinus Torvalds return 0; 14681da177e4SLinus Torvalds } 14691da177e4SLinus Torvalds 1470ee42381eSTakashi Iwai static unsigned short patch_ad1881_unchained(struct snd_ac97 * ac97, int idx, unsigned short mask) 14711da177e4SLinus Torvalds { 14721da177e4SLinus Torvalds unsigned short val; 14731da177e4SLinus Torvalds 14741da177e4SLinus Torvalds // test for unchained codec 14751da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, mask); 14761da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000); /* ID0C, ID1C, SDIE = off */ 14771da177e4SLinus Torvalds val = snd_ac97_read(ac97, AC97_VENDOR_ID2); 14781da177e4SLinus Torvalds if ((val & 0xff40) != 0x5340) 14791da177e4SLinus Torvalds return 0; 14801da177e4SLinus Torvalds ac97->spec.ad18xx.unchained[idx] = mask; 14811da177e4SLinus Torvalds ac97->spec.ad18xx.id[idx] = val; 14821da177e4SLinus Torvalds ac97->spec.ad18xx.codec_cfg[idx] = 0x0000; 14831da177e4SLinus Torvalds return mask; 14841da177e4SLinus Torvalds } 14851da177e4SLinus Torvalds 1486ee42381eSTakashi Iwai static int patch_ad1881_chained1(struct snd_ac97 * ac97, int idx, unsigned short codec_bits) 14871da177e4SLinus Torvalds { 14881da177e4SLinus Torvalds static int cfg_bits[3] = { 1<<12, 1<<14, 1<<13 }; 14891da177e4SLinus Torvalds unsigned short val; 14901da177e4SLinus Torvalds 14911da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, cfg_bits[idx]); 14921da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0004); // SDIE 14931da177e4SLinus Torvalds val = snd_ac97_read(ac97, AC97_VENDOR_ID2); 14941da177e4SLinus Torvalds if ((val & 0xff40) != 0x5340) 14951da177e4SLinus Torvalds return 0; 14961da177e4SLinus Torvalds if (codec_bits) 14971da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, codec_bits); 14981da177e4SLinus Torvalds ac97->spec.ad18xx.chained[idx] = cfg_bits[idx]; 14991da177e4SLinus Torvalds ac97->spec.ad18xx.id[idx] = val; 15001da177e4SLinus Torvalds ac97->spec.ad18xx.codec_cfg[idx] = codec_bits ? codec_bits : 0x0004; 15011da177e4SLinus Torvalds return 1; 15021da177e4SLinus Torvalds } 15031da177e4SLinus Torvalds 1504ee42381eSTakashi Iwai static void patch_ad1881_chained(struct snd_ac97 * ac97, int unchained_idx, int cidx1, int cidx2) 15051da177e4SLinus Torvalds { 15061da177e4SLinus Torvalds // already detected? 15071da177e4SLinus Torvalds if (ac97->spec.ad18xx.unchained[cidx1] || ac97->spec.ad18xx.chained[cidx1]) 15081da177e4SLinus Torvalds cidx1 = -1; 15091da177e4SLinus Torvalds if (ac97->spec.ad18xx.unchained[cidx2] || ac97->spec.ad18xx.chained[cidx2]) 15101da177e4SLinus Torvalds cidx2 = -1; 15111da177e4SLinus Torvalds if (cidx1 < 0 && cidx2 < 0) 15121da177e4SLinus Torvalds return; 15131da177e4SLinus Torvalds // test for chained codecs 15141da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 15151da177e4SLinus Torvalds ac97->spec.ad18xx.unchained[unchained_idx]); 15161da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0002); // ID1C 15171da177e4SLinus Torvalds ac97->spec.ad18xx.codec_cfg[unchained_idx] = 0x0002; 15181da177e4SLinus Torvalds if (cidx1 >= 0) { 1519c19bcdc6STakashi Iwai if (cidx2 < 0) 1520c19bcdc6STakashi Iwai patch_ad1881_chained1(ac97, cidx1, 0); 1521c19bcdc6STakashi Iwai else if (patch_ad1881_chained1(ac97, cidx1, 0x0006)) // SDIE | ID1C 15221da177e4SLinus Torvalds patch_ad1881_chained1(ac97, cidx2, 0); 15231da177e4SLinus Torvalds else if (patch_ad1881_chained1(ac97, cidx2, 0x0006)) // SDIE | ID1C 15241da177e4SLinus Torvalds patch_ad1881_chained1(ac97, cidx1, 0); 15251da177e4SLinus Torvalds } else if (cidx2 >= 0) { 15261da177e4SLinus Torvalds patch_ad1881_chained1(ac97, cidx2, 0); 15271da177e4SLinus Torvalds } 15281da177e4SLinus Torvalds } 15291da177e4SLinus Torvalds 15303e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ad1881_build_ops = { 15311da177e4SLinus Torvalds #ifdef CONFIG_PM 15321da177e4SLinus Torvalds .resume = ad18xx_resume 15331da177e4SLinus Torvalds #endif 15341da177e4SLinus Torvalds }; 15351da177e4SLinus Torvalds 1536ac519028STakashi Iwai static int patch_ad1881(struct snd_ac97 * ac97) 15371da177e4SLinus Torvalds { 15381da177e4SLinus Torvalds static const char cfg_idxs[3][2] = { 15391da177e4SLinus Torvalds {2, 1}, 15401da177e4SLinus Torvalds {0, 2}, 15411da177e4SLinus Torvalds {0, 1} 15421da177e4SLinus Torvalds }; 15431da177e4SLinus Torvalds 15441da177e4SLinus Torvalds // patch for Analog Devices 15451da177e4SLinus Torvalds unsigned short codecs[3]; 15461da177e4SLinus Torvalds unsigned short val; 15471da177e4SLinus Torvalds int idx, num; 15481da177e4SLinus Torvalds 15491da177e4SLinus Torvalds val = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG); 15501da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, val); 15511da177e4SLinus Torvalds codecs[0] = patch_ad1881_unchained(ac97, 0, (1<<12)); 15521da177e4SLinus Torvalds codecs[1] = patch_ad1881_unchained(ac97, 1, (1<<14)); 15531da177e4SLinus Torvalds codecs[2] = patch_ad1881_unchained(ac97, 2, (1<<13)); 15541da177e4SLinus Torvalds 15557c22f1aaSTakashi Iwai if (! (codecs[0] || codecs[1] || codecs[2])) 15567c22f1aaSTakashi Iwai goto __end; 15571da177e4SLinus Torvalds 15581da177e4SLinus Torvalds for (idx = 0; idx < 3; idx++) 15591da177e4SLinus Torvalds if (ac97->spec.ad18xx.unchained[idx]) 15601da177e4SLinus Torvalds patch_ad1881_chained(ac97, idx, cfg_idxs[idx][0], cfg_idxs[idx][1]); 15611da177e4SLinus Torvalds 15621da177e4SLinus Torvalds if (ac97->spec.ad18xx.id[1]) { 15631da177e4SLinus Torvalds ac97->flags |= AC97_AD_MULTI; 15641da177e4SLinus Torvalds ac97->scaps |= AC97_SCAP_SURROUND_DAC; 15651da177e4SLinus Torvalds } 15661da177e4SLinus Torvalds if (ac97->spec.ad18xx.id[2]) { 15671da177e4SLinus Torvalds ac97->flags |= AC97_AD_MULTI; 15681da177e4SLinus Torvalds ac97->scaps |= AC97_SCAP_CENTER_LFE_DAC; 15691da177e4SLinus Torvalds } 15701da177e4SLinus Torvalds 15711da177e4SLinus Torvalds __end: 15721da177e4SLinus Torvalds /* select all codecs */ 15731da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000); 15741da177e4SLinus Torvalds /* check if only one codec is present */ 15751da177e4SLinus Torvalds for (idx = num = 0; idx < 3; idx++) 15761da177e4SLinus Torvalds if (ac97->spec.ad18xx.id[idx]) 15771da177e4SLinus Torvalds num++; 15781da177e4SLinus Torvalds if (num == 1) { 15791da177e4SLinus Torvalds /* ok, deselect all ID bits */ 15801da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000); 15811da177e4SLinus Torvalds ac97->spec.ad18xx.codec_cfg[0] = 15821da177e4SLinus Torvalds ac97->spec.ad18xx.codec_cfg[1] = 15831da177e4SLinus Torvalds ac97->spec.ad18xx.codec_cfg[2] = 0x0000; 15841da177e4SLinus Torvalds } 15851da177e4SLinus Torvalds /* required for AD1886/AD1885 combination */ 15861da177e4SLinus Torvalds ac97->ext_id = snd_ac97_read(ac97, AC97_EXTENDED_ID); 15871da177e4SLinus Torvalds if (ac97->spec.ad18xx.id[0]) { 15881da177e4SLinus Torvalds ac97->id &= 0xffff0000; 15891da177e4SLinus Torvalds ac97->id |= ac97->spec.ad18xx.id[0]; 15901da177e4SLinus Torvalds } 15911da177e4SLinus Torvalds ac97->build_ops = &patch_ad1881_build_ops; 15921da177e4SLinus Torvalds return 0; 15931da177e4SLinus Torvalds } 15941da177e4SLinus Torvalds 1595ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_ad1885[] = { 15961da177e4SLinus Torvalds AC97_SINGLE("Digital Mono Direct", AC97_AD_MISC, 11, 1, 0), 15971da177e4SLinus Torvalds /* AC97_SINGLE("Digital Audio Mode", AC97_AD_MISC, 12, 1, 0), */ /* seems problematic */ 15981da177e4SLinus Torvalds AC97_SINGLE("Low Power Mixer", AC97_AD_MISC, 14, 1, 0), 15991da177e4SLinus Torvalds AC97_SINGLE("Zero Fill DAC", AC97_AD_MISC, 15, 1, 0), 16001da177e4SLinus Torvalds AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 9, 1, 1), /* inverted */ 16011da177e4SLinus Torvalds AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 8, 1, 1), /* inverted */ 16021da177e4SLinus Torvalds }; 16031da177e4SLinus Torvalds 16040cb29ea0STakashi Iwai static const DECLARE_TLV_DB_SCALE(db_scale_6bit_6db_max, -8850, 150, 0); 16052f3482fbSTakashi Iwai 1606ee42381eSTakashi Iwai static int patch_ad1885_specific(struct snd_ac97 * ac97) 16071da177e4SLinus Torvalds { 16081da177e4SLinus Torvalds int err; 16091da177e4SLinus Torvalds 16101da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, snd_ac97_controls_ad1885, ARRAY_SIZE(snd_ac97_controls_ad1885))) < 0) 16111da177e4SLinus Torvalds return err; 16122f3482fbSTakashi Iwai reset_tlv(ac97, "Headphone Playback Volume", 16132f3482fbSTakashi Iwai db_scale_6bit_6db_max); 16141da177e4SLinus Torvalds return 0; 16151da177e4SLinus Torvalds } 16161da177e4SLinus Torvalds 16173e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ad1885_build_ops = { 16181da177e4SLinus Torvalds .build_specific = &patch_ad1885_specific, 16191da177e4SLinus Torvalds #ifdef CONFIG_PM 16201da177e4SLinus Torvalds .resume = ad18xx_resume 16211da177e4SLinus Torvalds #endif 16221da177e4SLinus Torvalds }; 16231da177e4SLinus Torvalds 1624ac519028STakashi Iwai static int patch_ad1885(struct snd_ac97 * ac97) 16251da177e4SLinus Torvalds { 16261da177e4SLinus Torvalds patch_ad1881(ac97); 16271da177e4SLinus Torvalds /* This is required to deal with the Intel D815EEAL2 */ 16281da177e4SLinus Torvalds /* i.e. Line out is actually headphone out from codec */ 16291da177e4SLinus Torvalds 16301da177e4SLinus Torvalds /* set default */ 16311da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_AD_MISC, 0x0404); 16321da177e4SLinus Torvalds 16331da177e4SLinus Torvalds ac97->build_ops = &patch_ad1885_build_ops; 16341da177e4SLinus Torvalds return 0; 16351da177e4SLinus Torvalds } 16361da177e4SLinus Torvalds 16372f3482fbSTakashi Iwai static int patch_ad1886_specific(struct snd_ac97 * ac97) 16382f3482fbSTakashi Iwai { 16392f3482fbSTakashi Iwai reset_tlv(ac97, "Headphone Playback Volume", 16402f3482fbSTakashi Iwai db_scale_6bit_6db_max); 16412f3482fbSTakashi Iwai return 0; 16422f3482fbSTakashi Iwai } 16432f3482fbSTakashi Iwai 16443e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ad1886_build_ops = { 16452f3482fbSTakashi Iwai .build_specific = &patch_ad1886_specific, 16462f3482fbSTakashi Iwai #ifdef CONFIG_PM 16472f3482fbSTakashi Iwai .resume = ad18xx_resume 16482f3482fbSTakashi Iwai #endif 16492f3482fbSTakashi Iwai }; 16502f3482fbSTakashi Iwai 1651ac519028STakashi Iwai static int patch_ad1886(struct snd_ac97 * ac97) 16521da177e4SLinus Torvalds { 16531da177e4SLinus Torvalds patch_ad1881(ac97); 16541da177e4SLinus Torvalds /* Presario700 workaround */ 16551da177e4SLinus Torvalds /* for Jack Sense/SPDIF Register misetting causing */ 16561da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_AD_JACK_SPDIF, 0x0010); 16572f3482fbSTakashi Iwai ac97->build_ops = &patch_ad1886_build_ops; 16581da177e4SLinus Torvalds return 0; 16591da177e4SLinus Torvalds } 16601da177e4SLinus Torvalds 166167e9f4b6SRandy Cushman /* MISC bits (AD1888/AD1980/AD1985 register 0x76) */ 16621da177e4SLinus Torvalds #define AC97_AD198X_MBC 0x0003 /* mic boost */ 16631da177e4SLinus Torvalds #define AC97_AD198X_MBC_20 0x0000 /* +20dB */ 16641da177e4SLinus Torvalds #define AC97_AD198X_MBC_10 0x0001 /* +10dB */ 16651da177e4SLinus Torvalds #define AC97_AD198X_MBC_30 0x0002 /* +30dB */ 16661da177e4SLinus Torvalds #define AC97_AD198X_VREFD 0x0004 /* VREF high-Z */ 16676428ea1bSRandy Cushman #define AC97_AD198X_VREFH 0x0008 /* 0=2.25V, 1=3.7V */ 16686428ea1bSRandy Cushman #define AC97_AD198X_VREF_0 0x000c /* 0V (AD1985 only) */ 16696428ea1bSRandy Cushman #define AC97_AD198X_VREF_MASK (AC97_AD198X_VREFH | AC97_AD198X_VREFD) 16706428ea1bSRandy Cushman #define AC97_AD198X_VREF_SHIFT 2 16711da177e4SLinus Torvalds #define AC97_AD198X_SRU 0x0010 /* sample rate unlock */ 16721da177e4SLinus Torvalds #define AC97_AD198X_LOSEL 0x0020 /* LINE_OUT amplifiers input select */ 16731da177e4SLinus Torvalds #define AC97_AD198X_2MIC 0x0040 /* 2-channel mic select */ 16741da177e4SLinus Torvalds #define AC97_AD198X_SPRD 0x0080 /* SPREAD enable */ 16756428ea1bSRandy Cushman #define AC97_AD198X_DMIX0 0x0100 /* downmix mode: */ 16766428ea1bSRandy Cushman /* 0 = 6-to-4, 1 = 6-to-2 downmix */ 16771da177e4SLinus Torvalds #define AC97_AD198X_DMIX1 0x0200 /* downmix mode: 1 = enabled */ 16781da177e4SLinus Torvalds #define AC97_AD198X_HPSEL 0x0400 /* headphone amplifier input select */ 16791da177e4SLinus Torvalds #define AC97_AD198X_CLDIS 0x0800 /* center/lfe disable */ 16801da177e4SLinus Torvalds #define AC97_AD198X_LODIS 0x1000 /* LINE_OUT disable */ 16811da177e4SLinus Torvalds #define AC97_AD198X_MSPLT 0x2000 /* mute split */ 16821da177e4SLinus Torvalds #define AC97_AD198X_AC97NC 0x4000 /* AC97 no compatible mode */ 16831da177e4SLinus Torvalds #define AC97_AD198X_DACZ 0x8000 /* DAC zero-fill mode */ 16841da177e4SLinus Torvalds 168567e9f4b6SRandy Cushman /* MISC 1 bits (AD1986 register 0x76) */ 168667e9f4b6SRandy Cushman #define AC97_AD1986_MBC 0x0003 /* mic boost */ 168767e9f4b6SRandy Cushman #define AC97_AD1986_MBC_20 0x0000 /* +20dB */ 168867e9f4b6SRandy Cushman #define AC97_AD1986_MBC_10 0x0001 /* +10dB */ 168967e9f4b6SRandy Cushman #define AC97_AD1986_MBC_30 0x0002 /* +30dB */ 169067e9f4b6SRandy Cushman #define AC97_AD1986_LISEL0 0x0004 /* LINE_IN select bit 0 */ 169167e9f4b6SRandy Cushman #define AC97_AD1986_LISEL1 0x0008 /* LINE_IN select bit 1 */ 169267e9f4b6SRandy Cushman #define AC97_AD1986_LISEL_MASK (AC97_AD1986_LISEL1 | AC97_AD1986_LISEL0) 169367e9f4b6SRandy Cushman #define AC97_AD1986_LISEL_LI 0x0000 /* LINE_IN pins as LINE_IN source */ 169467e9f4b6SRandy Cushman #define AC97_AD1986_LISEL_SURR 0x0004 /* SURROUND pins as LINE_IN source */ 169567e9f4b6SRandy Cushman #define AC97_AD1986_LISEL_MIC 0x0008 /* MIC_1/2 pins as LINE_IN source */ 169667e9f4b6SRandy Cushman #define AC97_AD1986_SRU 0x0010 /* sample rate unlock */ 169767e9f4b6SRandy Cushman #define AC97_AD1986_SOSEL 0x0020 /* SURROUND_OUT amplifiers input sel */ 169867e9f4b6SRandy Cushman #define AC97_AD1986_2MIC 0x0040 /* 2-channel mic select */ 169967e9f4b6SRandy Cushman #define AC97_AD1986_SPRD 0x0080 /* SPREAD enable */ 170067e9f4b6SRandy Cushman #define AC97_AD1986_DMIX0 0x0100 /* downmix mode: */ 170167e9f4b6SRandy Cushman /* 0 = 6-to-4, 1 = 6-to-2 downmix */ 170267e9f4b6SRandy Cushman #define AC97_AD1986_DMIX1 0x0200 /* downmix mode: 1 = enabled */ 170367e9f4b6SRandy Cushman #define AC97_AD1986_CLDIS 0x0800 /* center/lfe disable */ 170467e9f4b6SRandy Cushman #define AC97_AD1986_SODIS 0x1000 /* SURROUND_OUT disable */ 170567e9f4b6SRandy Cushman #define AC97_AD1986_MSPLT 0x2000 /* mute split (read only 1) */ 170667e9f4b6SRandy Cushman #define AC97_AD1986_AC97NC 0x4000 /* AC97 no compatible mode (r/o 1) */ 170767e9f4b6SRandy Cushman #define AC97_AD1986_DACZ 0x8000 /* DAC zero-fill mode */ 170867e9f4b6SRandy Cushman 170967e9f4b6SRandy Cushman /* MISC 2 bits (AD1986 register 0x70) */ 171067e9f4b6SRandy Cushman #define AC97_AD_MISC2 0x70 /* Misc Control Bits 2 (AD1986) */ 171167e9f4b6SRandy Cushman 171267e9f4b6SRandy Cushman #define AC97_AD1986_CVREF0 0x0004 /* C/LFE VREF_OUT 2.25V */ 171367e9f4b6SRandy Cushman #define AC97_AD1986_CVREF1 0x0008 /* C/LFE VREF_OUT 0V */ 171467e9f4b6SRandy Cushman #define AC97_AD1986_CVREF2 0x0010 /* C/LFE VREF_OUT 3.7V */ 171567e9f4b6SRandy Cushman #define AC97_AD1986_CVREF_MASK \ 171667e9f4b6SRandy Cushman (AC97_AD1986_CVREF2 | AC97_AD1986_CVREF1 | AC97_AD1986_CVREF0) 171767e9f4b6SRandy Cushman #define AC97_AD1986_JSMAP 0x0020 /* Jack Sense Mapping 1 = alternate */ 171867e9f4b6SRandy Cushman #define AC97_AD1986_MMDIS 0x0080 /* Mono Mute Disable */ 171967e9f4b6SRandy Cushman #define AC97_AD1986_MVREF0 0x0400 /* MIC VREF_OUT 2.25V */ 172067e9f4b6SRandy Cushman #define AC97_AD1986_MVREF1 0x0800 /* MIC VREF_OUT 0V */ 172167e9f4b6SRandy Cushman #define AC97_AD1986_MVREF2 0x1000 /* MIC VREF_OUT 3.7V */ 172267e9f4b6SRandy Cushman #define AC97_AD1986_MVREF_MASK \ 172367e9f4b6SRandy Cushman (AC97_AD1986_MVREF2 | AC97_AD1986_MVREF1 | AC97_AD1986_MVREF0) 172467e9f4b6SRandy Cushman 172567e9f4b6SRandy Cushman /* MISC 3 bits (AD1986 register 0x7a) */ 172667e9f4b6SRandy Cushman #define AC97_AD_MISC3 0x7a /* Misc Control Bits 3 (AD1986) */ 172767e9f4b6SRandy Cushman 172867e9f4b6SRandy Cushman #define AC97_AD1986_MMIX 0x0004 /* Mic Mix, left/right */ 172967e9f4b6SRandy Cushman #define AC97_AD1986_GPO 0x0008 /* General Purpose Out */ 173067e9f4b6SRandy Cushman #define AC97_AD1986_LOHPEN 0x0010 /* LINE_OUT headphone drive */ 173167e9f4b6SRandy Cushman #define AC97_AD1986_LVREF0 0x0100 /* LINE_OUT VREF_OUT 2.25V */ 173267e9f4b6SRandy Cushman #define AC97_AD1986_LVREF1 0x0200 /* LINE_OUT VREF_OUT 0V */ 173367e9f4b6SRandy Cushman #define AC97_AD1986_LVREF2 0x0400 /* LINE_OUT VREF_OUT 3.7V */ 173467e9f4b6SRandy Cushman #define AC97_AD1986_LVREF_MASK \ 173567e9f4b6SRandy Cushman (AC97_AD1986_LVREF2 | AC97_AD1986_LVREF1 | AC97_AD1986_LVREF0) 173667e9f4b6SRandy Cushman #define AC97_AD1986_JSINVA 0x0800 /* Jack Sense Invert SENSE_A */ 173767e9f4b6SRandy Cushman #define AC97_AD1986_LOSEL 0x1000 /* LINE_OUT amplifiers input select */ 173867e9f4b6SRandy Cushman #define AC97_AD1986_HPSEL0 0x2000 /* Headphone amplifiers */ 173967e9f4b6SRandy Cushman /* input select Surround DACs */ 174067e9f4b6SRandy Cushman #define AC97_AD1986_HPSEL1 0x4000 /* Headphone amplifiers input */ 174167e9f4b6SRandy Cushman /* select C/LFE DACs */ 174267e9f4b6SRandy Cushman #define AC97_AD1986_JSINVB 0x8000 /* Jack Sense Invert SENSE_B */ 174367e9f4b6SRandy Cushman 174467e9f4b6SRandy Cushman /* Serial Config bits (AD1986 register 0x74) (incomplete) */ 174567e9f4b6SRandy Cushman #define AC97_AD1986_OMS0 0x0100 /* Optional Mic Selector bit 0 */ 174667e9f4b6SRandy Cushman #define AC97_AD1986_OMS1 0x0200 /* Optional Mic Selector bit 1 */ 174767e9f4b6SRandy Cushman #define AC97_AD1986_OMS2 0x0400 /* Optional Mic Selector bit 2 */ 174867e9f4b6SRandy Cushman #define AC97_AD1986_OMS_MASK \ 174967e9f4b6SRandy Cushman (AC97_AD1986_OMS2 | AC97_AD1986_OMS1 | AC97_AD1986_OMS0) 175067e9f4b6SRandy Cushman #define AC97_AD1986_OMS_M 0x0000 /* MIC_1/2 pins are MIC sources */ 175167e9f4b6SRandy Cushman #define AC97_AD1986_OMS_L 0x0100 /* LINE_IN pins are MIC sources */ 175267e9f4b6SRandy Cushman #define AC97_AD1986_OMS_C 0x0200 /* Center/LFE pins are MCI sources */ 175367e9f4b6SRandy Cushman #define AC97_AD1986_OMS_MC 0x0400 /* Mix of MIC and C/LFE pins */ 175467e9f4b6SRandy Cushman /* are MIC sources */ 175567e9f4b6SRandy Cushman #define AC97_AD1986_OMS_ML 0x0500 /* MIX of MIC and LINE_IN pins */ 175667e9f4b6SRandy Cushman /* are MIC sources */ 175767e9f4b6SRandy Cushman #define AC97_AD1986_OMS_LC 0x0600 /* MIX of LINE_IN and C/LFE pins */ 175867e9f4b6SRandy Cushman /* are MIC sources */ 175967e9f4b6SRandy Cushman #define AC97_AD1986_OMS_MLC 0x0700 /* MIX of MIC, LINE_IN, C/LFE pins */ 176067e9f4b6SRandy Cushman /* are MIC sources */ 176167e9f4b6SRandy Cushman 17621da177e4SLinus Torvalds 1763ee42381eSTakashi Iwai static int snd_ac97_ad198x_spdif_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 17641da177e4SLinus Torvalds { 17653b7a00dcSTakashi Iwai static const char * const texts[2] = { "AC-Link", "A/D Converter" }; 17661da177e4SLinus Torvalds 17673b7a00dcSTakashi Iwai return snd_ctl_enum_info(uinfo, 1, 2, texts); 17681da177e4SLinus Torvalds } 17691da177e4SLinus Torvalds 1770ee42381eSTakashi Iwai static int snd_ac97_ad198x_spdif_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 17711da177e4SLinus Torvalds { 1772ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 17731da177e4SLinus Torvalds unsigned short val; 17741da177e4SLinus Torvalds 17751da177e4SLinus Torvalds val = ac97->regs[AC97_AD_SERIAL_CFG]; 17761da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = (val >> 2) & 1; 17771da177e4SLinus Torvalds return 0; 17781da177e4SLinus Torvalds } 17791da177e4SLinus Torvalds 1780ee42381eSTakashi Iwai static int snd_ac97_ad198x_spdif_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 17811da177e4SLinus Torvalds { 1782ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 17831da177e4SLinus Torvalds unsigned short val; 17841da177e4SLinus Torvalds 17851da177e4SLinus Torvalds if (ucontrol->value.enumerated.item[0] > 1) 17861da177e4SLinus Torvalds return -EINVAL; 17871da177e4SLinus Torvalds val = ucontrol->value.enumerated.item[0] << 2; 17881da177e4SLinus Torvalds return snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x0004, val); 17891da177e4SLinus Torvalds } 17901da177e4SLinus Torvalds 1791ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ad198x_spdif_source = { 17921da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 17931da177e4SLinus Torvalds .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source", 17941da177e4SLinus Torvalds .info = snd_ac97_ad198x_spdif_source_info, 17951da177e4SLinus Torvalds .get = snd_ac97_ad198x_spdif_source_get, 17961da177e4SLinus Torvalds .put = snd_ac97_ad198x_spdif_source_put, 17971da177e4SLinus Torvalds }; 17981da177e4SLinus Torvalds 1799ee42381eSTakashi Iwai static int patch_ad198x_post_spdif(struct snd_ac97 * ac97) 18001da177e4SLinus Torvalds { 18011da177e4SLinus Torvalds return patch_build_controls(ac97, &snd_ac97_ad198x_spdif_source, 1); 18021da177e4SLinus Torvalds } 18031da177e4SLinus Torvalds 1804ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ad1981x_jack_sense[] = { 18051da177e4SLinus Torvalds AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 11, 1, 0), 18061da177e4SLinus Torvalds AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0), 18071da177e4SLinus Torvalds }; 18081da177e4SLinus Torvalds 1809128a46a5STakashi Iwai /* black list to avoid HP/Line jack-sense controls 1810128a46a5STakashi Iwai * (SS vendor << 16 | device) 1811128a46a5STakashi Iwai */ 1812128a46a5STakashi Iwai static unsigned int ad1981_jacks_blacklist[] = { 1813a31e8c72STakashi Iwai 0x10140523, /* Thinkpad R40 */ 1814a31e8c72STakashi Iwai 0x10140534, /* Thinkpad X31 */ 1815a43c4d4dSTakashi Iwai 0x10140537, /* Thinkpad T41p */ 1816e1f7f02bSDaniel T Chen 0x1014053e, /* Thinkpad R40e */ 1817128a46a5STakashi Iwai 0x10140554, /* Thinkpad T42p/R50p */ 18188286c53eSDaniel T Chen 0x10140567, /* Thinkpad T43p 2668-G7U */ 18198286c53eSDaniel T Chen 0x10140581, /* Thinkpad X41-2527 */ 1820af9a75ddSDaniel T Chen 0x10280160, /* Dell Dimension 2400 */ 18218286c53eSDaniel T Chen 0x104380b0, /* Asus A7V8X-MX */ 18228286c53eSDaniel T Chen 0x11790241, /* Toshiba Satellite A-15 S127 */ 18235cd165e7SDaniel Chen 0x1179ff10, /* Toshiba P500 */ 18248286c53eSDaniel T Chen 0x144dc01a, /* Samsung NP-X20C004/SEG */ 1825128a46a5STakashi Iwai 0 /* end */ 1826128a46a5STakashi Iwai }; 1827128a46a5STakashi Iwai 1828128a46a5STakashi Iwai static int check_list(struct snd_ac97 *ac97, const unsigned int *list) 1829128a46a5STakashi Iwai { 1830128a46a5STakashi Iwai u32 subid = ((u32)ac97->subsystem_vendor << 16) | ac97->subsystem_device; 1831128a46a5STakashi Iwai for (; *list; list++) 1832128a46a5STakashi Iwai if (*list == subid) 1833128a46a5STakashi Iwai return 1; 1834128a46a5STakashi Iwai return 0; 1835128a46a5STakashi Iwai } 1836128a46a5STakashi Iwai 1837ee42381eSTakashi Iwai static int patch_ad1981a_specific(struct snd_ac97 * ac97) 18381da177e4SLinus Torvalds { 1839128a46a5STakashi Iwai if (check_list(ac97, ad1981_jacks_blacklist)) 1840128a46a5STakashi Iwai return 0; 18411da177e4SLinus Torvalds return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense, 18421da177e4SLinus Torvalds ARRAY_SIZE(snd_ac97_ad1981x_jack_sense)); 18431da177e4SLinus Torvalds } 18441da177e4SLinus Torvalds 18453e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ad1981a_build_ops = { 18461da177e4SLinus Torvalds .build_post_spdif = patch_ad198x_post_spdif, 18471da177e4SLinus Torvalds .build_specific = patch_ad1981a_specific, 18481da177e4SLinus Torvalds #ifdef CONFIG_PM 18491da177e4SLinus Torvalds .resume = ad18xx_resume 18501da177e4SLinus Torvalds #endif 18511da177e4SLinus Torvalds }; 18521da177e4SLinus Torvalds 1853128a46a5STakashi Iwai /* white list to enable HP jack-sense bits 1854128a46a5STakashi Iwai * (SS vendor << 16 | device) 1855128a46a5STakashi Iwai */ 1856128a46a5STakashi Iwai static unsigned int ad1981_jacks_whitelist[] = { 1857128a46a5STakashi Iwai 0x0e11005a, /* HP nc4000/4010 */ 1858128a46a5STakashi Iwai 0x103c0890, /* HP nc6000 */ 1859128a46a5STakashi Iwai 0x103c0938, /* HP nc4220 */ 1860128a46a5STakashi Iwai 0x103c099c, /* HP nx6110 */ 1861128a46a5STakashi Iwai 0x103c0944, /* HP nc6220 */ 1862128a46a5STakashi Iwai 0x103c0934, /* HP nc8220 */ 1863128a46a5STakashi Iwai 0x103c006d, /* HP nx9105 */ 1864eade7b28SDaniel T Chen 0x103c300d, /* HP Compaq dc5100 SFF(PT003AW) */ 1865128a46a5STakashi Iwai 0x17340088, /* FSC Scenic-W */ 1866128a46a5STakashi Iwai 0 /* end */ 1867128a46a5STakashi Iwai }; 1868128a46a5STakashi Iwai 1869ee42381eSTakashi Iwai static void check_ad1981_hp_jack_sense(struct snd_ac97 *ac97) 18701da177e4SLinus Torvalds { 1871128a46a5STakashi Iwai if (check_list(ac97, ad1981_jacks_whitelist)) 18721da177e4SLinus Torvalds /* enable headphone jack sense */ 18731da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_AD_JACK_SPDIF, 1<<11, 1<<11); 18741da177e4SLinus Torvalds } 18751da177e4SLinus Torvalds 1876ac519028STakashi Iwai static int patch_ad1981a(struct snd_ac97 *ac97) 18771da177e4SLinus Torvalds { 18781da177e4SLinus Torvalds patch_ad1881(ac97); 18791da177e4SLinus Torvalds ac97->build_ops = &patch_ad1981a_build_ops; 18801da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT); 18811da177e4SLinus Torvalds ac97->flags |= AC97_STEREO_MUTES; 18821da177e4SLinus Torvalds check_ad1981_hp_jack_sense(ac97); 18831da177e4SLinus Torvalds return 0; 18841da177e4SLinus Torvalds } 18851da177e4SLinus Torvalds 1886ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ad198x_2cmic = 18871da177e4SLinus Torvalds AC97_SINGLE("Stereo Mic", AC97_AD_MISC, 6, 1, 0); 18881da177e4SLinus Torvalds 1889ee42381eSTakashi Iwai static int patch_ad1981b_specific(struct snd_ac97 *ac97) 18901da177e4SLinus Torvalds { 18911da177e4SLinus Torvalds int err; 18921da177e4SLinus Torvalds 18931da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0) 18941da177e4SLinus Torvalds return err; 1895128a46a5STakashi Iwai if (check_list(ac97, ad1981_jacks_blacklist)) 1896128a46a5STakashi Iwai return 0; 18971da177e4SLinus Torvalds return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense, 18981da177e4SLinus Torvalds ARRAY_SIZE(snd_ac97_ad1981x_jack_sense)); 18991da177e4SLinus Torvalds } 19001da177e4SLinus Torvalds 19013e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ad1981b_build_ops = { 19021da177e4SLinus Torvalds .build_post_spdif = patch_ad198x_post_spdif, 19031da177e4SLinus Torvalds .build_specific = patch_ad1981b_specific, 19041da177e4SLinus Torvalds #ifdef CONFIG_PM 19051da177e4SLinus Torvalds .resume = ad18xx_resume 19061da177e4SLinus Torvalds #endif 19071da177e4SLinus Torvalds }; 19081da177e4SLinus Torvalds 1909ac519028STakashi Iwai static int patch_ad1981b(struct snd_ac97 *ac97) 19101da177e4SLinus Torvalds { 19111da177e4SLinus Torvalds patch_ad1881(ac97); 19121da177e4SLinus Torvalds ac97->build_ops = &patch_ad1981b_build_ops; 19131da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT); 19141da177e4SLinus Torvalds ac97->flags |= AC97_STEREO_MUTES; 19151da177e4SLinus Torvalds check_ad1981_hp_jack_sense(ac97); 19161da177e4SLinus Torvalds return 0; 19171da177e4SLinus Torvalds } 19181da177e4SLinus Torvalds 1919a5ce8890STakashi Iwai #define snd_ac97_ad1888_lohpsel_info snd_ctl_boolean_mono_info 19201da177e4SLinus Torvalds 1921ee42381eSTakashi Iwai static int snd_ac97_ad1888_lohpsel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 19221da177e4SLinus Torvalds { 1923ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 19241da177e4SLinus Torvalds unsigned short val; 19251da177e4SLinus Torvalds 19261da177e4SLinus Torvalds val = ac97->regs[AC97_AD_MISC]; 19271da177e4SLinus Torvalds ucontrol->value.integer.value[0] = !(val & AC97_AD198X_LOSEL); 1928e48d6d97STakashi Iwai if (ac97->spec.ad18xx.lo_as_master) 1929e48d6d97STakashi Iwai ucontrol->value.integer.value[0] = 1930e48d6d97STakashi Iwai !ucontrol->value.integer.value[0]; 19311da177e4SLinus Torvalds return 0; 19321da177e4SLinus Torvalds } 19331da177e4SLinus Torvalds 1934ee42381eSTakashi Iwai static int snd_ac97_ad1888_lohpsel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 19351da177e4SLinus Torvalds { 1936ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 19371da177e4SLinus Torvalds unsigned short val; 19381da177e4SLinus Torvalds 1939e48d6d97STakashi Iwai val = !ucontrol->value.integer.value[0]; 1940e48d6d97STakashi Iwai if (ac97->spec.ad18xx.lo_as_master) 1941e48d6d97STakashi Iwai val = !val; 1942e48d6d97STakashi Iwai val = val ? (AC97_AD198X_LOSEL | AC97_AD198X_HPSEL) : 0; 19431da177e4SLinus Torvalds return snd_ac97_update_bits(ac97, AC97_AD_MISC, 19441da177e4SLinus Torvalds AC97_AD198X_LOSEL | AC97_AD198X_HPSEL, val); 19451da177e4SLinus Torvalds } 19461da177e4SLinus Torvalds 1947ee42381eSTakashi Iwai static int snd_ac97_ad1888_downmix_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 19481da177e4SLinus Torvalds { 19493b7a00dcSTakashi Iwai static const char * const texts[3] = {"Off", "6 -> 4", "6 -> 2"}; 19501da177e4SLinus Torvalds 19513b7a00dcSTakashi Iwai return snd_ctl_enum_info(uinfo, 1, 3, texts); 19521da177e4SLinus Torvalds } 19531da177e4SLinus Torvalds 1954ee42381eSTakashi Iwai static int snd_ac97_ad1888_downmix_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 19551da177e4SLinus Torvalds { 1956ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 19571da177e4SLinus Torvalds unsigned short val; 19581da177e4SLinus Torvalds 19591da177e4SLinus Torvalds val = ac97->regs[AC97_AD_MISC]; 19601da177e4SLinus Torvalds if (!(val & AC97_AD198X_DMIX1)) 19611da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = 0; 19621da177e4SLinus Torvalds else 19631da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = 1 + ((val >> 8) & 1); 19641da177e4SLinus Torvalds return 0; 19651da177e4SLinus Torvalds } 19661da177e4SLinus Torvalds 1967ee42381eSTakashi Iwai static int snd_ac97_ad1888_downmix_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 19681da177e4SLinus Torvalds { 1969ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 19701da177e4SLinus Torvalds unsigned short val; 19711da177e4SLinus Torvalds 19721da177e4SLinus Torvalds if (ucontrol->value.enumerated.item[0] > 2) 19731da177e4SLinus Torvalds return -EINVAL; 19741da177e4SLinus Torvalds if (ucontrol->value.enumerated.item[0] == 0) 19751da177e4SLinus Torvalds val = 0; 19761da177e4SLinus Torvalds else 19771da177e4SLinus Torvalds val = AC97_AD198X_DMIX1 | 19781da177e4SLinus Torvalds ((ucontrol->value.enumerated.item[0] - 1) << 8); 19791da177e4SLinus Torvalds return snd_ac97_update_bits(ac97, AC97_AD_MISC, 19801da177e4SLinus Torvalds AC97_AD198X_DMIX0 | AC97_AD198X_DMIX1, val); 19811da177e4SLinus Torvalds } 19821da177e4SLinus Torvalds 1983ee42381eSTakashi Iwai static void ad1888_update_jacks(struct snd_ac97 *ac97) 1984eb8caf30STakashi Iwai { 19854525c9f3STakashi Iwai unsigned short val = 0; 1986c26a8de2SRandy Cushman /* clear LODIS if shared jack is to be used for Surround out */ 1987e48d6d97STakashi Iwai if (!ac97->spec.ad18xx.lo_as_master && is_shared_linein(ac97)) 19884525c9f3STakashi Iwai val |= (1 << 12); 1989c26a8de2SRandy Cushman /* clear CLDIS if shared jack is to be used for C/LFE out */ 1990c26a8de2SRandy Cushman if (is_shared_micin(ac97)) 19914525c9f3STakashi Iwai val |= (1 << 11); 1992eb8caf30STakashi Iwai /* shared Line-In */ 19934525c9f3STakashi Iwai snd_ac97_update_bits(ac97, AC97_AD_MISC, (1 << 11) | (1 << 12), val); 1994eb8caf30STakashi Iwai } 1995eb8caf30STakashi Iwai 1996ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ad1888_controls[] = { 19971da177e4SLinus Torvalds { 19981da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 19991da177e4SLinus Torvalds .name = "Exchange Front/Surround", 20001da177e4SLinus Torvalds .info = snd_ac97_ad1888_lohpsel_info, 20011da177e4SLinus Torvalds .get = snd_ac97_ad1888_lohpsel_get, 20021da177e4SLinus Torvalds .put = snd_ac97_ad1888_lohpsel_put 20031da177e4SLinus Torvalds }, 20040bed7b29SAndres Salomon AC97_SINGLE("V_REFOUT Enable", AC97_AD_MISC, AC97_AD_VREFD_SHIFT, 1, 1), 20050bed7b29SAndres Salomon AC97_SINGLE("High Pass Filter Enable", AC97_AD_TEST2, 20060bed7b29SAndres Salomon AC97_AD_HPFD_SHIFT, 1, 1), 20071da177e4SLinus Torvalds AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC, 7, 1, 0), 20081da177e4SLinus Torvalds { 20091da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 20101da177e4SLinus Torvalds .name = "Downmix", 20111da177e4SLinus Torvalds .info = snd_ac97_ad1888_downmix_info, 20121da177e4SLinus Torvalds .get = snd_ac97_ad1888_downmix_get, 20131da177e4SLinus Torvalds .put = snd_ac97_ad1888_downmix_put 20141da177e4SLinus Torvalds }, 2015eb8caf30STakashi Iwai AC97_SURROUND_JACK_MODE_CTL, 2016eb8caf30STakashi Iwai AC97_CHANNEL_MODE_CTL, 2017eeacb545SSergey Ulanov 2018eeacb545SSergey Ulanov AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0), 2019eeacb545SSergey Ulanov AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0), 20201da177e4SLinus Torvalds }; 20211da177e4SLinus Torvalds 2022ee42381eSTakashi Iwai static int patch_ad1888_specific(struct snd_ac97 *ac97) 20231da177e4SLinus Torvalds { 2024e48d6d97STakashi Iwai if (!ac97->spec.ad18xx.lo_as_master) { 20251da177e4SLinus Torvalds /* rename 0x04 as "Master" and 0x02 as "Master Surround" */ 2026e48d6d97STakashi Iwai snd_ac97_rename_vol_ctl(ac97, "Master Playback", 2027e48d6d97STakashi Iwai "Master Surround Playback"); 2028e48d6d97STakashi Iwai snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", 2029e48d6d97STakashi Iwai "Master Playback"); 2030e48d6d97STakashi Iwai } 20311da177e4SLinus Torvalds return patch_build_controls(ac97, snd_ac97_ad1888_controls, ARRAY_SIZE(snd_ac97_ad1888_controls)); 20321da177e4SLinus Torvalds } 20331da177e4SLinus Torvalds 20343e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ad1888_build_ops = { 20351da177e4SLinus Torvalds .build_post_spdif = patch_ad198x_post_spdif, 20361da177e4SLinus Torvalds .build_specific = patch_ad1888_specific, 20371da177e4SLinus Torvalds #ifdef CONFIG_PM 20381561f09aSJaya Kumar .resume = ad1888_resume, 20391da177e4SLinus Torvalds #endif 2040eb8caf30STakashi Iwai .update_jacks = ad1888_update_jacks, 20411da177e4SLinus Torvalds }; 20421da177e4SLinus Torvalds 2043ac519028STakashi Iwai static int patch_ad1888(struct snd_ac97 * ac97) 20441da177e4SLinus Torvalds { 20451da177e4SLinus Torvalds unsigned short misc; 20461da177e4SLinus Torvalds 20471da177e4SLinus Torvalds patch_ad1881(ac97); 20481da177e4SLinus Torvalds ac97->build_ops = &patch_ad1888_build_ops; 2049e48d6d97STakashi Iwai 2050e48d6d97STakashi Iwai /* 2051e48d6d97STakashi Iwai * LO can be used as a real line-out on some devices, 2052e48d6d97STakashi Iwai * and we need to revert the front/surround mixer switches 2053e48d6d97STakashi Iwai */ 2054e48d6d97STakashi Iwai if (ac97->subsystem_vendor == 0x1043 && 2055e48d6d97STakashi Iwai ac97->subsystem_device == 0x1193) /* ASUS A9T laptop */ 2056e48d6d97STakashi Iwai ac97->spec.ad18xx.lo_as_master = 1; 2057e48d6d97STakashi Iwai 2058e48d6d97STakashi Iwai misc = snd_ac97_read(ac97, AC97_AD_MISC); 20591da177e4SLinus Torvalds /* AD-compatible mode */ 20601da177e4SLinus Torvalds /* Stereo mutes enabled */ 2061e48d6d97STakashi Iwai misc |= AC97_AD198X_MSPLT | AC97_AD198X_AC97NC; 2062e48d6d97STakashi Iwai if (!ac97->spec.ad18xx.lo_as_master) 2063e48d6d97STakashi Iwai /* Switch FRONT/SURROUND LINE-OUT/HP-OUT default connection */ 2064e48d6d97STakashi Iwai /* it seems that most vendors connect line-out connector to 2065e48d6d97STakashi Iwai * headphone out of AC'97 2066e48d6d97STakashi Iwai */ 2067e48d6d97STakashi Iwai misc |= AC97_AD198X_LOSEL | AC97_AD198X_HPSEL; 2068e48d6d97STakashi Iwai 2069e48d6d97STakashi Iwai snd_ac97_write_cache(ac97, AC97_AD_MISC, misc); 20701da177e4SLinus Torvalds ac97->flags |= AC97_STEREO_MUTES; 20711da177e4SLinus Torvalds return 0; 20721da177e4SLinus Torvalds } 20731da177e4SLinus Torvalds 2074ee42381eSTakashi Iwai static int patch_ad1980_specific(struct snd_ac97 *ac97) 20751da177e4SLinus Torvalds { 20761da177e4SLinus Torvalds int err; 20771da177e4SLinus Torvalds 20781da177e4SLinus Torvalds if ((err = patch_ad1888_specific(ac97)) < 0) 20791da177e4SLinus Torvalds return err; 20801da177e4SLinus Torvalds return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1); 20811da177e4SLinus Torvalds } 20821da177e4SLinus Torvalds 20833e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ad1980_build_ops = { 20841da177e4SLinus Torvalds .build_post_spdif = patch_ad198x_post_spdif, 20851da177e4SLinus Torvalds .build_specific = patch_ad1980_specific, 20861da177e4SLinus Torvalds #ifdef CONFIG_PM 2087462c4173SClemens Ladisch .resume = ad18xx_resume, 20881da177e4SLinus Torvalds #endif 2089462c4173SClemens Ladisch .update_jacks = ad1888_update_jacks, 20901da177e4SLinus Torvalds }; 20911da177e4SLinus Torvalds 2092ac519028STakashi Iwai static int patch_ad1980(struct snd_ac97 * ac97) 20931da177e4SLinus Torvalds { 20941da177e4SLinus Torvalds patch_ad1888(ac97); 20951da177e4SLinus Torvalds ac97->build_ops = &patch_ad1980_build_ops; 20961da177e4SLinus Torvalds return 0; 20971da177e4SLinus Torvalds } 20981da177e4SLinus Torvalds 20996428ea1bSRandy Cushman static int snd_ac97_ad1985_vrefout_info(struct snd_kcontrol *kcontrol, 21006428ea1bSRandy Cushman struct snd_ctl_elem_info *uinfo) 21016428ea1bSRandy Cushman { 21023b7a00dcSTakashi Iwai static const char * const texts[4] = { 21033b7a00dcSTakashi Iwai "High-Z", "3.7 V", "2.25 V", "0 V" 21043b7a00dcSTakashi Iwai }; 21056428ea1bSRandy Cushman 21063b7a00dcSTakashi Iwai return snd_ctl_enum_info(uinfo, 1, 4, texts); 21076428ea1bSRandy Cushman } 21086428ea1bSRandy Cushman 21096428ea1bSRandy Cushman static int snd_ac97_ad1985_vrefout_get(struct snd_kcontrol *kcontrol, 21106428ea1bSRandy Cushman struct snd_ctl_elem_value *ucontrol) 21116428ea1bSRandy Cushman { 21126428ea1bSRandy Cushman static const int reg2ctrl[4] = {2, 0, 1, 3}; 21136428ea1bSRandy Cushman struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 21146428ea1bSRandy Cushman unsigned short val; 21156428ea1bSRandy Cushman val = (ac97->regs[AC97_AD_MISC] & AC97_AD198X_VREF_MASK) 21166428ea1bSRandy Cushman >> AC97_AD198X_VREF_SHIFT; 21176428ea1bSRandy Cushman ucontrol->value.enumerated.item[0] = reg2ctrl[val]; 21186428ea1bSRandy Cushman return 0; 21196428ea1bSRandy Cushman } 21206428ea1bSRandy Cushman 21216428ea1bSRandy Cushman static int snd_ac97_ad1985_vrefout_put(struct snd_kcontrol *kcontrol, 21226428ea1bSRandy Cushman struct snd_ctl_elem_value *ucontrol) 21236428ea1bSRandy Cushman { 21246428ea1bSRandy Cushman static const int ctrl2reg[4] = {1, 2, 0, 3}; 21256428ea1bSRandy Cushman struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 21266428ea1bSRandy Cushman unsigned short val; 21276428ea1bSRandy Cushman 21284e98d6a7STakashi Iwai if (ucontrol->value.enumerated.item[0] > 3) 21296428ea1bSRandy Cushman return -EINVAL; 21306428ea1bSRandy Cushman val = ctrl2reg[ucontrol->value.enumerated.item[0]] 21316428ea1bSRandy Cushman << AC97_AD198X_VREF_SHIFT; 21326428ea1bSRandy Cushman return snd_ac97_update_bits(ac97, AC97_AD_MISC, 21336428ea1bSRandy Cushman AC97_AD198X_VREF_MASK, val); 21346428ea1bSRandy Cushman } 21356428ea1bSRandy Cushman 2136ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ad1985_controls[] = { 21376428ea1bSRandy Cushman AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0), 21386428ea1bSRandy Cushman { 21396428ea1bSRandy Cushman .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 21406428ea1bSRandy Cushman .name = "Exchange Front/Surround", 21416428ea1bSRandy Cushman .info = snd_ac97_ad1888_lohpsel_info, 21426428ea1bSRandy Cushman .get = snd_ac97_ad1888_lohpsel_get, 21436428ea1bSRandy Cushman .put = snd_ac97_ad1888_lohpsel_put 21446428ea1bSRandy Cushman }, 21456428ea1bSRandy Cushman AC97_SINGLE("High Pass Filter Enable", AC97_AD_TEST2, 12, 1, 1), 21466428ea1bSRandy Cushman AC97_SINGLE("Spread Front to Surround and Center/LFE", 21476428ea1bSRandy Cushman AC97_AD_MISC, 7, 1, 0), 21486428ea1bSRandy Cushman { 21496428ea1bSRandy Cushman .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 21506428ea1bSRandy Cushman .name = "Downmix", 21516428ea1bSRandy Cushman .info = snd_ac97_ad1888_downmix_info, 21526428ea1bSRandy Cushman .get = snd_ac97_ad1888_downmix_get, 21536428ea1bSRandy Cushman .put = snd_ac97_ad1888_downmix_put 21546428ea1bSRandy Cushman }, 21556428ea1bSRandy Cushman { 21566428ea1bSRandy Cushman .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 21576428ea1bSRandy Cushman .name = "V_REFOUT", 21586428ea1bSRandy Cushman .info = snd_ac97_ad1985_vrefout_info, 21596428ea1bSRandy Cushman .get = snd_ac97_ad1985_vrefout_get, 21606428ea1bSRandy Cushman .put = snd_ac97_ad1985_vrefout_put 21616428ea1bSRandy Cushman }, 21626428ea1bSRandy Cushman AC97_SURROUND_JACK_MODE_CTL, 21636428ea1bSRandy Cushman AC97_CHANNEL_MODE_CTL, 21646428ea1bSRandy Cushman 21656428ea1bSRandy Cushman AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0), 21666428ea1bSRandy Cushman AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0), 21671da177e4SLinus Torvalds }; 21681da177e4SLinus Torvalds 2169ee42381eSTakashi Iwai static void ad1985_update_jacks(struct snd_ac97 *ac97) 2170e5b3f45fSTakashi Iwai { 21714525c9f3STakashi Iwai ad1888_update_jacks(ac97); 2172c26a8de2SRandy Cushman /* clear OMS if shared jack is to be used for C/LFE out */ 2173fc232c6eSTakashi Iwai snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 1 << 9, 2174c26a8de2SRandy Cushman is_shared_micin(ac97) ? 1 << 9 : 0); 2175e5b3f45fSTakashi Iwai } 2176e5b3f45fSTakashi Iwai 2177ee42381eSTakashi Iwai static int patch_ad1985_specific(struct snd_ac97 *ac97) 21781da177e4SLinus Torvalds { 21791da177e4SLinus Torvalds int err; 21801da177e4SLinus Torvalds 21816428ea1bSRandy Cushman /* rename 0x04 as "Master" and 0x02 as "Master Surround" */ 21826428ea1bSRandy Cushman snd_ac97_rename_vol_ctl(ac97, "Master Playback", 21836428ea1bSRandy Cushman "Master Surround Playback"); 21846428ea1bSRandy Cushman snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback"); 21856428ea1bSRandy Cushman 21866428ea1bSRandy Cushman if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0) 21871da177e4SLinus Torvalds return err; 21886428ea1bSRandy Cushman 21896428ea1bSRandy Cushman return patch_build_controls(ac97, snd_ac97_ad1985_controls, 21906428ea1bSRandy Cushman ARRAY_SIZE(snd_ac97_ad1985_controls)); 21911da177e4SLinus Torvalds } 21921da177e4SLinus Torvalds 21933e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ad1985_build_ops = { 21941da177e4SLinus Torvalds .build_post_spdif = patch_ad198x_post_spdif, 21951da177e4SLinus Torvalds .build_specific = patch_ad1985_specific, 21961da177e4SLinus Torvalds #ifdef CONFIG_PM 2197462c4173SClemens Ladisch .resume = ad18xx_resume, 21981da177e4SLinus Torvalds #endif 2199e5b3f45fSTakashi Iwai .update_jacks = ad1985_update_jacks, 22001da177e4SLinus Torvalds }; 22011da177e4SLinus Torvalds 2202ac519028STakashi Iwai static int patch_ad1985(struct snd_ac97 * ac97) 22031da177e4SLinus Torvalds { 22041da177e4SLinus Torvalds unsigned short misc; 22051da177e4SLinus Torvalds 22061da177e4SLinus Torvalds patch_ad1881(ac97); 22071da177e4SLinus Torvalds ac97->build_ops = &patch_ad1985_build_ops; 22081da177e4SLinus Torvalds misc = snd_ac97_read(ac97, AC97_AD_MISC); 22091da177e4SLinus Torvalds /* switch front/surround line-out/hp-out */ 22101da177e4SLinus Torvalds /* AD-compatible mode */ 22111da177e4SLinus Torvalds /* Stereo mutes enabled */ 22121da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_AD_MISC, misc | 22131da177e4SLinus Torvalds AC97_AD198X_LOSEL | 22141da177e4SLinus Torvalds AC97_AD198X_HPSEL | 22151da177e4SLinus Torvalds AC97_AD198X_MSPLT | 22161da177e4SLinus Torvalds AC97_AD198X_AC97NC); 22171da177e4SLinus Torvalds ac97->flags |= AC97_STEREO_MUTES; 22186428ea1bSRandy Cushman 22196428ea1bSRandy Cushman /* update current jack configuration */ 22206428ea1bSRandy Cushman ad1985_update_jacks(ac97); 22216428ea1bSRandy Cushman 22221da177e4SLinus Torvalds /* on AD1985 rev. 3, AC'97 revision bits are zero */ 22231da177e4SLinus Torvalds ac97->ext_id = (ac97->ext_id & ~AC97_EI_REV_MASK) | AC97_EI_REV_23; 22241da177e4SLinus Torvalds return 0; 22251da177e4SLinus Torvalds } 22261da177e4SLinus Torvalds 2227a5ce8890STakashi Iwai #define snd_ac97_ad1986_bool_info snd_ctl_boolean_mono_info 222867e9f4b6SRandy Cushman 222967e9f4b6SRandy Cushman static int snd_ac97_ad1986_lososel_get(struct snd_kcontrol *kcontrol, 223067e9f4b6SRandy Cushman struct snd_ctl_elem_value *ucontrol) 223167e9f4b6SRandy Cushman { 223267e9f4b6SRandy Cushman struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 223367e9f4b6SRandy Cushman unsigned short val; 223467e9f4b6SRandy Cushman 223567e9f4b6SRandy Cushman val = ac97->regs[AC97_AD_MISC3]; 223667e9f4b6SRandy Cushman ucontrol->value.integer.value[0] = (val & AC97_AD1986_LOSEL) != 0; 223767e9f4b6SRandy Cushman return 0; 223867e9f4b6SRandy Cushman } 223967e9f4b6SRandy Cushman 224067e9f4b6SRandy Cushman static int snd_ac97_ad1986_lososel_put(struct snd_kcontrol *kcontrol, 224167e9f4b6SRandy Cushman struct snd_ctl_elem_value *ucontrol) 224267e9f4b6SRandy Cushman { 224367e9f4b6SRandy Cushman struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 224467e9f4b6SRandy Cushman int ret0; 224567e9f4b6SRandy Cushman int ret1; 224667e9f4b6SRandy Cushman int sprd = (ac97->regs[AC97_AD_MISC] & AC97_AD1986_SPRD) != 0; 224767e9f4b6SRandy Cushman 224867e9f4b6SRandy Cushman ret0 = snd_ac97_update_bits(ac97, AC97_AD_MISC3, AC97_AD1986_LOSEL, 224967e9f4b6SRandy Cushman ucontrol->value.integer.value[0] != 0 225067e9f4b6SRandy Cushman ? AC97_AD1986_LOSEL : 0); 225167e9f4b6SRandy Cushman if (ret0 < 0) 225267e9f4b6SRandy Cushman return ret0; 225367e9f4b6SRandy Cushman 225467e9f4b6SRandy Cushman /* SOSEL is set to values of "Spread" or "Exchange F/S" controls */ 225567e9f4b6SRandy Cushman ret1 = snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD1986_SOSEL, 225667e9f4b6SRandy Cushman (ucontrol->value.integer.value[0] != 0 225767e9f4b6SRandy Cushman || sprd) 225867e9f4b6SRandy Cushman ? AC97_AD1986_SOSEL : 0); 225967e9f4b6SRandy Cushman if (ret1 < 0) 226067e9f4b6SRandy Cushman return ret1; 226167e9f4b6SRandy Cushman 226267e9f4b6SRandy Cushman return (ret0 > 0 || ret1 > 0) ? 1 : 0; 226367e9f4b6SRandy Cushman } 226467e9f4b6SRandy Cushman 226567e9f4b6SRandy Cushman static int snd_ac97_ad1986_spread_get(struct snd_kcontrol *kcontrol, 226667e9f4b6SRandy Cushman struct snd_ctl_elem_value *ucontrol) 226767e9f4b6SRandy Cushman { 226867e9f4b6SRandy Cushman struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 226967e9f4b6SRandy Cushman unsigned short val; 227067e9f4b6SRandy Cushman 227167e9f4b6SRandy Cushman val = ac97->regs[AC97_AD_MISC]; 227267e9f4b6SRandy Cushman ucontrol->value.integer.value[0] = (val & AC97_AD1986_SPRD) != 0; 227367e9f4b6SRandy Cushman return 0; 227467e9f4b6SRandy Cushman } 227567e9f4b6SRandy Cushman 227667e9f4b6SRandy Cushman static int snd_ac97_ad1986_spread_put(struct snd_kcontrol *kcontrol, 227767e9f4b6SRandy Cushman struct snd_ctl_elem_value *ucontrol) 227867e9f4b6SRandy Cushman { 227967e9f4b6SRandy Cushman struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 228067e9f4b6SRandy Cushman int ret0; 228167e9f4b6SRandy Cushman int ret1; 228267e9f4b6SRandy Cushman int sprd = (ac97->regs[AC97_AD_MISC3] & AC97_AD1986_LOSEL) != 0; 228367e9f4b6SRandy Cushman 228467e9f4b6SRandy Cushman ret0 = snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD1986_SPRD, 228567e9f4b6SRandy Cushman ucontrol->value.integer.value[0] != 0 228667e9f4b6SRandy Cushman ? AC97_AD1986_SPRD : 0); 228767e9f4b6SRandy Cushman if (ret0 < 0) 228867e9f4b6SRandy Cushman return ret0; 228967e9f4b6SRandy Cushman 229067e9f4b6SRandy Cushman /* SOSEL is set to values of "Spread" or "Exchange F/S" controls */ 229167e9f4b6SRandy Cushman ret1 = snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD1986_SOSEL, 229267e9f4b6SRandy Cushman (ucontrol->value.integer.value[0] != 0 229367e9f4b6SRandy Cushman || sprd) 229467e9f4b6SRandy Cushman ? AC97_AD1986_SOSEL : 0); 229567e9f4b6SRandy Cushman if (ret1 < 0) 229667e9f4b6SRandy Cushman return ret1; 229767e9f4b6SRandy Cushman 229867e9f4b6SRandy Cushman return (ret0 > 0 || ret1 > 0) ? 1 : 0; 229967e9f4b6SRandy Cushman } 230067e9f4b6SRandy Cushman 230167e9f4b6SRandy Cushman static int snd_ac97_ad1986_miclisel_get(struct snd_kcontrol *kcontrol, 230267e9f4b6SRandy Cushman struct snd_ctl_elem_value *ucontrol) 230367e9f4b6SRandy Cushman { 230467e9f4b6SRandy Cushman struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 230567e9f4b6SRandy Cushman 230667e9f4b6SRandy Cushman ucontrol->value.integer.value[0] = ac97->spec.ad18xx.swap_mic_linein; 230767e9f4b6SRandy Cushman return 0; 230867e9f4b6SRandy Cushman } 230967e9f4b6SRandy Cushman 231067e9f4b6SRandy Cushman static int snd_ac97_ad1986_miclisel_put(struct snd_kcontrol *kcontrol, 231167e9f4b6SRandy Cushman struct snd_ctl_elem_value *ucontrol) 231267e9f4b6SRandy Cushman { 231367e9f4b6SRandy Cushman struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 231467e9f4b6SRandy Cushman unsigned char swap = ucontrol->value.integer.value[0] != 0; 231567e9f4b6SRandy Cushman 231667e9f4b6SRandy Cushman if (swap != ac97->spec.ad18xx.swap_mic_linein) { 231767e9f4b6SRandy Cushman ac97->spec.ad18xx.swap_mic_linein = swap; 231867e9f4b6SRandy Cushman if (ac97->build_ops->update_jacks) 231967e9f4b6SRandy Cushman ac97->build_ops->update_jacks(ac97); 232067e9f4b6SRandy Cushman return 1; 232167e9f4b6SRandy Cushman } 232267e9f4b6SRandy Cushman return 0; 232367e9f4b6SRandy Cushman } 232467e9f4b6SRandy Cushman 232567e9f4b6SRandy Cushman static int snd_ac97_ad1986_vrefout_get(struct snd_kcontrol *kcontrol, 232667e9f4b6SRandy Cushman struct snd_ctl_elem_value *ucontrol) 232767e9f4b6SRandy Cushman { 232867e9f4b6SRandy Cushman /* Use MIC_1/2 V_REFOUT as the "get" value */ 232967e9f4b6SRandy Cushman struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 233067e9f4b6SRandy Cushman unsigned short val; 233167e9f4b6SRandy Cushman unsigned short reg = ac97->regs[AC97_AD_MISC2]; 233267e9f4b6SRandy Cushman if ((reg & AC97_AD1986_MVREF0) != 0) 233367e9f4b6SRandy Cushman val = 2; 233467e9f4b6SRandy Cushman else if ((reg & AC97_AD1986_MVREF1) != 0) 233567e9f4b6SRandy Cushman val = 3; 233667e9f4b6SRandy Cushman else if ((reg & AC97_AD1986_MVREF2) != 0) 233767e9f4b6SRandy Cushman val = 1; 233867e9f4b6SRandy Cushman else 233967e9f4b6SRandy Cushman val = 0; 234067e9f4b6SRandy Cushman ucontrol->value.enumerated.item[0] = val; 234167e9f4b6SRandy Cushman return 0; 234267e9f4b6SRandy Cushman } 234367e9f4b6SRandy Cushman 234467e9f4b6SRandy Cushman static int snd_ac97_ad1986_vrefout_put(struct snd_kcontrol *kcontrol, 234567e9f4b6SRandy Cushman struct snd_ctl_elem_value *ucontrol) 234667e9f4b6SRandy Cushman { 234767e9f4b6SRandy Cushman struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 234867e9f4b6SRandy Cushman unsigned short cval; 234967e9f4b6SRandy Cushman unsigned short lval; 235067e9f4b6SRandy Cushman unsigned short mval; 235167e9f4b6SRandy Cushman int cret; 235267e9f4b6SRandy Cushman int lret; 235367e9f4b6SRandy Cushman int mret; 235467e9f4b6SRandy Cushman 235567e9f4b6SRandy Cushman switch (ucontrol->value.enumerated.item[0]) 235667e9f4b6SRandy Cushman { 235767e9f4b6SRandy Cushman case 0: /* High-Z */ 235867e9f4b6SRandy Cushman cval = 0; 235967e9f4b6SRandy Cushman lval = 0; 236067e9f4b6SRandy Cushman mval = 0; 236167e9f4b6SRandy Cushman break; 236267e9f4b6SRandy Cushman case 1: /* 3.7 V */ 236367e9f4b6SRandy Cushman cval = AC97_AD1986_CVREF2; 236467e9f4b6SRandy Cushman lval = AC97_AD1986_LVREF2; 236567e9f4b6SRandy Cushman mval = AC97_AD1986_MVREF2; 236667e9f4b6SRandy Cushman break; 236767e9f4b6SRandy Cushman case 2: /* 2.25 V */ 236867e9f4b6SRandy Cushman cval = AC97_AD1986_CVREF0; 236967e9f4b6SRandy Cushman lval = AC97_AD1986_LVREF0; 237067e9f4b6SRandy Cushman mval = AC97_AD1986_MVREF0; 237167e9f4b6SRandy Cushman break; 237267e9f4b6SRandy Cushman case 3: /* 0 V */ 237367e9f4b6SRandy Cushman cval = AC97_AD1986_CVREF1; 237467e9f4b6SRandy Cushman lval = AC97_AD1986_LVREF1; 237567e9f4b6SRandy Cushman mval = AC97_AD1986_MVREF1; 237667e9f4b6SRandy Cushman break; 237767e9f4b6SRandy Cushman default: 237867e9f4b6SRandy Cushman return -EINVAL; 237967e9f4b6SRandy Cushman } 238067e9f4b6SRandy Cushman 238167e9f4b6SRandy Cushman cret = snd_ac97_update_bits(ac97, AC97_AD_MISC2, 238267e9f4b6SRandy Cushman AC97_AD1986_CVREF_MASK, cval); 238367e9f4b6SRandy Cushman if (cret < 0) 238467e9f4b6SRandy Cushman return cret; 238567e9f4b6SRandy Cushman lret = snd_ac97_update_bits(ac97, AC97_AD_MISC3, 238667e9f4b6SRandy Cushman AC97_AD1986_LVREF_MASK, lval); 238767e9f4b6SRandy Cushman if (lret < 0) 238867e9f4b6SRandy Cushman return lret; 238967e9f4b6SRandy Cushman mret = snd_ac97_update_bits(ac97, AC97_AD_MISC2, 239067e9f4b6SRandy Cushman AC97_AD1986_MVREF_MASK, mval); 239167e9f4b6SRandy Cushman if (mret < 0) 239267e9f4b6SRandy Cushman return mret; 239367e9f4b6SRandy Cushman 239467e9f4b6SRandy Cushman return (cret > 0 || lret > 0 || mret > 0) ? 1 : 0; 239567e9f4b6SRandy Cushman } 239667e9f4b6SRandy Cushman 239767e9f4b6SRandy Cushman static const struct snd_kcontrol_new snd_ac97_ad1986_controls[] = { 239867e9f4b6SRandy Cushman AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0), 239967e9f4b6SRandy Cushman { 240067e9f4b6SRandy Cushman .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 240167e9f4b6SRandy Cushman .name = "Exchange Front/Surround", 240267e9f4b6SRandy Cushman .info = snd_ac97_ad1986_bool_info, 240367e9f4b6SRandy Cushman .get = snd_ac97_ad1986_lososel_get, 240467e9f4b6SRandy Cushman .put = snd_ac97_ad1986_lososel_put 240567e9f4b6SRandy Cushman }, 240667e9f4b6SRandy Cushman { 240767e9f4b6SRandy Cushman .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 240867e9f4b6SRandy Cushman .name = "Exchange Mic/Line In", 240967e9f4b6SRandy Cushman .info = snd_ac97_ad1986_bool_info, 241067e9f4b6SRandy Cushman .get = snd_ac97_ad1986_miclisel_get, 241167e9f4b6SRandy Cushman .put = snd_ac97_ad1986_miclisel_put 241267e9f4b6SRandy Cushman }, 241367e9f4b6SRandy Cushman { 241467e9f4b6SRandy Cushman .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 241567e9f4b6SRandy Cushman .name = "Spread Front to Surround and Center/LFE", 241667e9f4b6SRandy Cushman .info = snd_ac97_ad1986_bool_info, 241767e9f4b6SRandy Cushman .get = snd_ac97_ad1986_spread_get, 241867e9f4b6SRandy Cushman .put = snd_ac97_ad1986_spread_put 241967e9f4b6SRandy Cushman }, 242067e9f4b6SRandy Cushman { 242167e9f4b6SRandy Cushman .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 242267e9f4b6SRandy Cushman .name = "Downmix", 242367e9f4b6SRandy Cushman .info = snd_ac97_ad1888_downmix_info, 242467e9f4b6SRandy Cushman .get = snd_ac97_ad1888_downmix_get, 242567e9f4b6SRandy Cushman .put = snd_ac97_ad1888_downmix_put 242667e9f4b6SRandy Cushman }, 242767e9f4b6SRandy Cushman { 242867e9f4b6SRandy Cushman .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 242967e9f4b6SRandy Cushman .name = "V_REFOUT", 243067e9f4b6SRandy Cushman .info = snd_ac97_ad1985_vrefout_info, 243167e9f4b6SRandy Cushman .get = snd_ac97_ad1986_vrefout_get, 243267e9f4b6SRandy Cushman .put = snd_ac97_ad1986_vrefout_put 243367e9f4b6SRandy Cushman }, 243467e9f4b6SRandy Cushman AC97_SURROUND_JACK_MODE_CTL, 243567e9f4b6SRandy Cushman AC97_CHANNEL_MODE_CTL, 243667e9f4b6SRandy Cushman 243767e9f4b6SRandy Cushman AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0), 243867e9f4b6SRandy Cushman AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0) 243967e9f4b6SRandy Cushman }; 244067e9f4b6SRandy Cushman 244167e9f4b6SRandy Cushman static void ad1986_update_jacks(struct snd_ac97 *ac97) 244267e9f4b6SRandy Cushman { 244367e9f4b6SRandy Cushman unsigned short misc_val = 0; 244467e9f4b6SRandy Cushman unsigned short ser_val; 244567e9f4b6SRandy Cushman 244667e9f4b6SRandy Cushman /* disable SURROUND and CENTER/LFE if not surround mode */ 244767e9f4b6SRandy Cushman if (!is_surround_on(ac97)) 244867e9f4b6SRandy Cushman misc_val |= AC97_AD1986_SODIS; 244967e9f4b6SRandy Cushman if (!is_clfe_on(ac97)) 245067e9f4b6SRandy Cushman misc_val |= AC97_AD1986_CLDIS; 245167e9f4b6SRandy Cushman 245267e9f4b6SRandy Cushman /* select line input (default=LINE_IN, SURROUND or MIC_1/2) */ 245367e9f4b6SRandy Cushman if (is_shared_linein(ac97)) 245467e9f4b6SRandy Cushman misc_val |= AC97_AD1986_LISEL_SURR; 245567e9f4b6SRandy Cushman else if (ac97->spec.ad18xx.swap_mic_linein != 0) 245667e9f4b6SRandy Cushman misc_val |= AC97_AD1986_LISEL_MIC; 245767e9f4b6SRandy Cushman snd_ac97_update_bits(ac97, AC97_AD_MISC, 245867e9f4b6SRandy Cushman AC97_AD1986_SODIS | AC97_AD1986_CLDIS | 245967e9f4b6SRandy Cushman AC97_AD1986_LISEL_MASK, 246067e9f4b6SRandy Cushman misc_val); 246167e9f4b6SRandy Cushman 246267e9f4b6SRandy Cushman /* select microphone input (MIC_1/2, Center/LFE or LINE_IN) */ 246367e9f4b6SRandy Cushman if (is_shared_micin(ac97)) 246467e9f4b6SRandy Cushman ser_val = AC97_AD1986_OMS_C; 246567e9f4b6SRandy Cushman else if (ac97->spec.ad18xx.swap_mic_linein != 0) 246667e9f4b6SRandy Cushman ser_val = AC97_AD1986_OMS_L; 246767e9f4b6SRandy Cushman else 246867e9f4b6SRandy Cushman ser_val = AC97_AD1986_OMS_M; 246967e9f4b6SRandy Cushman snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 247067e9f4b6SRandy Cushman AC97_AD1986_OMS_MASK, 247167e9f4b6SRandy Cushman ser_val); 247267e9f4b6SRandy Cushman } 247367e9f4b6SRandy Cushman 247467e9f4b6SRandy Cushman static int patch_ad1986_specific(struct snd_ac97 *ac97) 247567e9f4b6SRandy Cushman { 247667e9f4b6SRandy Cushman int err; 247767e9f4b6SRandy Cushman 247867e9f4b6SRandy Cushman if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0) 247967e9f4b6SRandy Cushman return err; 248067e9f4b6SRandy Cushman 248167e9f4b6SRandy Cushman return patch_build_controls(ac97, snd_ac97_ad1986_controls, 248267e9f4b6SRandy Cushman ARRAY_SIZE(snd_ac97_ad1985_controls)); 248367e9f4b6SRandy Cushman } 248467e9f4b6SRandy Cushman 24853e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ad1986_build_ops = { 248667e9f4b6SRandy Cushman .build_post_spdif = patch_ad198x_post_spdif, 248767e9f4b6SRandy Cushman .build_specific = patch_ad1986_specific, 248867e9f4b6SRandy Cushman #ifdef CONFIG_PM 248967e9f4b6SRandy Cushman .resume = ad18xx_resume, 249067e9f4b6SRandy Cushman #endif 249167e9f4b6SRandy Cushman .update_jacks = ad1986_update_jacks, 249267e9f4b6SRandy Cushman }; 249367e9f4b6SRandy Cushman 2494ac519028STakashi Iwai static int patch_ad1986(struct snd_ac97 * ac97) 249567e9f4b6SRandy Cushman { 249667e9f4b6SRandy Cushman patch_ad1881(ac97); 249767e9f4b6SRandy Cushman ac97->build_ops = &patch_ad1986_build_ops; 249867e9f4b6SRandy Cushman ac97->flags |= AC97_STEREO_MUTES; 249967e9f4b6SRandy Cushman 250067e9f4b6SRandy Cushman /* update current jack configuration */ 250167e9f4b6SRandy Cushman ad1986_update_jacks(ac97); 250267e9f4b6SRandy Cushman 250367e9f4b6SRandy Cushman return 0; 250467e9f4b6SRandy Cushman } 250567e9f4b6SRandy Cushman 25068f4f4ef6STakashi Iwai /* 25078f4f4ef6STakashi Iwai * realtek ALC203: use mono-out for pin 37 25088f4f4ef6STakashi Iwai */ 25098f4f4ef6STakashi Iwai static int patch_alc203(struct snd_ac97 *ac97) 25108f4f4ef6STakashi Iwai { 25118f4f4ef6STakashi Iwai snd_ac97_update_bits(ac97, 0x7a, 0x400, 0x400); 25128f4f4ef6STakashi Iwai return 0; 25138f4f4ef6STakashi Iwai } 251467e9f4b6SRandy Cushman 25151da177e4SLinus Torvalds /* 25161da177e4SLinus Torvalds * realtek ALC65x/850 codecs 25171da177e4SLinus Torvalds */ 2518ee42381eSTakashi Iwai static void alc650_update_jacks(struct snd_ac97 *ac97) 25191da177e4SLinus Torvalds { 2520eb8caf30STakashi Iwai int shared; 25211da177e4SLinus Torvalds 2522831466f4SRandy Cushman /* shared Line-In / Surround Out */ 2523831466f4SRandy Cushman shared = is_shared_surrout(ac97); 2524eb8caf30STakashi Iwai snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 9, 2525eb8caf30STakashi Iwai shared ? (1 << 9) : 0); 2526831466f4SRandy Cushman /* update shared Mic In / Center/LFE Out */ 2527831466f4SRandy Cushman shared = is_shared_clfeout(ac97); 25281da177e4SLinus Torvalds /* disable/enable vref */ 25291da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12, 2530eb8caf30STakashi Iwai shared ? (1 << 12) : 0); 25311da177e4SLinus Torvalds /* turn on/off center-on-mic */ 25321da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 10, 2533eb8caf30STakashi Iwai shared ? (1 << 10) : 0); 25341da177e4SLinus Torvalds /* GPIO0 high for mic */ 25351da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_ALC650_GPIO_STATUS, 0x100, 2536eb8caf30STakashi Iwai shared ? 0 : 0x100); 25371da177e4SLinus Torvalds } 25381da177e4SLinus Torvalds 2539833a493bSTakashi Iwai static int alc650_swap_surround_put(struct snd_kcontrol *kcontrol, 2540833a493bSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 2541833a493bSTakashi Iwai { 2542833a493bSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 2543833a493bSTakashi Iwai struct snd_pcm_chmap *map = ac97->chmaps[SNDRV_PCM_STREAM_PLAYBACK]; 2544833a493bSTakashi Iwai 2545833a493bSTakashi Iwai if (map) { 2546833a493bSTakashi Iwai if (ucontrol->value.integer.value[0]) 2547833a493bSTakashi Iwai map->chmap = snd_pcm_std_chmaps; 2548833a493bSTakashi Iwai else 2549833a493bSTakashi Iwai map->chmap = snd_pcm_alt_chmaps; 2550833a493bSTakashi Iwai } 2551833a493bSTakashi Iwai return snd_ac97_put_volsw(kcontrol, ucontrol); 2552833a493bSTakashi Iwai } 2553833a493bSTakashi Iwai 2554ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_alc650[] = { 25551da177e4SLinus Torvalds AC97_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0), 25561da177e4SLinus Torvalds AC97_SINGLE("Surround Down Mix", AC97_ALC650_MULTICH, 1, 1, 0), 25571da177e4SLinus Torvalds AC97_SINGLE("Center/LFE Down Mix", AC97_ALC650_MULTICH, 2, 1, 0), 25581da177e4SLinus Torvalds AC97_SINGLE("Exchange Center/LFE", AC97_ALC650_MULTICH, 3, 1, 0), 25591da177e4SLinus Torvalds /* 4: Analog Input To Surround */ 25601da177e4SLinus Torvalds /* 5: Analog Input To Center/LFE */ 25611da177e4SLinus Torvalds /* 6: Independent Master Volume Right */ 25621da177e4SLinus Torvalds /* 7: Independent Master Volume Left */ 25631da177e4SLinus Torvalds /* 8: reserved */ 2564eb8caf30STakashi Iwai /* 9: Line-In/Surround share */ 2565eb8caf30STakashi Iwai /* 10: Mic/CLFE share */ 25661da177e4SLinus Torvalds /* 11-13: in IEC958 controls */ 2567833a493bSTakashi Iwai { 2568833a493bSTakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2569833a493bSTakashi Iwai .name = "Swap Surround Slot", 2570833a493bSTakashi Iwai .info = snd_ac97_info_volsw, 2571833a493bSTakashi Iwai .get = snd_ac97_get_volsw, 2572833a493bSTakashi Iwai .put = alc650_swap_surround_put, 2573833a493bSTakashi Iwai .private_value = AC97_SINGLE_VALUE(AC97_ALC650_MULTICH, 14, 1, 0), 2574833a493bSTakashi Iwai }, 25751da177e4SLinus Torvalds #if 0 /* always set in patch_alc650 */ 25761da177e4SLinus Torvalds AC97_SINGLE("IEC958 Input Clock Enable", AC97_ALC650_CLOCK, 0, 1, 0), 25771da177e4SLinus Torvalds AC97_SINGLE("IEC958 Input Pin Enable", AC97_ALC650_CLOCK, 1, 1, 0), 25781da177e4SLinus Torvalds AC97_SINGLE("Surround DAC Switch", AC97_ALC650_SURR_DAC_VOL, 15, 1, 1), 25791da177e4SLinus Torvalds AC97_DOUBLE("Surround DAC Volume", AC97_ALC650_SURR_DAC_VOL, 8, 0, 31, 1), 25801da177e4SLinus Torvalds AC97_SINGLE("Center/LFE DAC Switch", AC97_ALC650_LFE_DAC_VOL, 15, 1, 1), 25811da177e4SLinus Torvalds AC97_DOUBLE("Center/LFE DAC Volume", AC97_ALC650_LFE_DAC_VOL, 8, 0, 31, 1), 25821da177e4SLinus Torvalds #endif 2583eb8caf30STakashi Iwai AC97_SURROUND_JACK_MODE_CTL, 2584eb8caf30STakashi Iwai AC97_CHANNEL_MODE_CTL, 25851da177e4SLinus Torvalds }; 25861da177e4SLinus Torvalds 2587ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc650[] = { 258810e8d78aSClemens Ladisch AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0), 25891da177e4SLinus Torvalds AC97_SINGLE("Analog to IEC958 Output", AC97_ALC650_MULTICH, 12, 1, 0), 25901da177e4SLinus Torvalds /* disable this controls since it doesn't work as expected */ 25911da177e4SLinus Torvalds /* AC97_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 13, 1, 0), */ 25921da177e4SLinus Torvalds }; 25931da177e4SLinus Torvalds 25940cb29ea0STakashi Iwai static const DECLARE_TLV_DB_SCALE(db_scale_5bit_3db_max, -4350, 150, 0); 25952f3482fbSTakashi Iwai 2596ee42381eSTakashi Iwai static int patch_alc650_specific(struct snd_ac97 * ac97) 25971da177e4SLinus Torvalds { 25981da177e4SLinus Torvalds int err; 25991da177e4SLinus Torvalds 26001da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, snd_ac97_controls_alc650, ARRAY_SIZE(snd_ac97_controls_alc650))) < 0) 26011da177e4SLinus Torvalds return err; 26021da177e4SLinus Torvalds if (ac97->ext_id & AC97_EI_SPDIF) { 26031da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc650, ARRAY_SIZE(snd_ac97_spdif_controls_alc650))) < 0) 26041da177e4SLinus Torvalds return err; 26051da177e4SLinus Torvalds } 26062f3482fbSTakashi Iwai if (ac97->id != AC97_ID_ALC650F) 26072f3482fbSTakashi Iwai reset_tlv(ac97, "Master Playback Volume", 26082f3482fbSTakashi Iwai db_scale_5bit_3db_max); 26091da177e4SLinus Torvalds return 0; 26101da177e4SLinus Torvalds } 26111da177e4SLinus Torvalds 26123e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_alc650_ops = { 2613eb8caf30STakashi Iwai .build_specific = patch_alc650_specific, 2614eb8caf30STakashi Iwai .update_jacks = alc650_update_jacks 26151da177e4SLinus Torvalds }; 26161da177e4SLinus Torvalds 2617ac519028STakashi Iwai static int patch_alc650(struct snd_ac97 * ac97) 26181da177e4SLinus Torvalds { 26191da177e4SLinus Torvalds unsigned short val; 26201da177e4SLinus Torvalds 26211da177e4SLinus Torvalds ac97->build_ops = &patch_alc650_ops; 26221da177e4SLinus Torvalds 26231da177e4SLinus Torvalds /* determine the revision */ 26241da177e4SLinus Torvalds val = snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f; 26251da177e4SLinus Torvalds if (val < 3) 26261da177e4SLinus Torvalds ac97->id = 0x414c4720; /* Old version */ 26271da177e4SLinus Torvalds else if (val < 0x10) 26281da177e4SLinus Torvalds ac97->id = 0x414c4721; /* D version */ 26291da177e4SLinus Torvalds else if (val < 0x20) 26301da177e4SLinus Torvalds ac97->id = 0x414c4722; /* E version */ 26311da177e4SLinus Torvalds else if (val < 0x30) 26321da177e4SLinus Torvalds ac97->id = 0x414c4723; /* F version */ 26331da177e4SLinus Torvalds 26341da177e4SLinus Torvalds /* revision E or F */ 26351da177e4SLinus Torvalds /* FIXME: what about revision D ? */ 26361da177e4SLinus Torvalds ac97->spec.dev_flags = (ac97->id == 0x414c4722 || 26371da177e4SLinus Torvalds ac97->id == 0x414c4723); 26381da177e4SLinus Torvalds 26391da177e4SLinus Torvalds /* enable AC97_ALC650_GPIO_SETUP, AC97_ALC650_CLOCK for R/W */ 26401da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS, 26411da177e4SLinus Torvalds snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x8000); 26421da177e4SLinus Torvalds 26431da177e4SLinus Torvalds /* Enable SPDIF-IN only on Rev.E and above */ 26441da177e4SLinus Torvalds val = snd_ac97_read(ac97, AC97_ALC650_CLOCK); 26451da177e4SLinus Torvalds /* SPDIF IN with pin 47 */ 2646eed65649STakashi Iwai if (ac97->spec.dev_flags && 2647eed65649STakashi Iwai /* ASUS A6KM requires EAPD */ 2648eed65649STakashi Iwai ! (ac97->subsystem_vendor == 0x1043 && 2649eed65649STakashi Iwai ac97->subsystem_device == 0x1103)) 26501da177e4SLinus Torvalds val |= 0x03; /* enable */ 26511da177e4SLinus Torvalds else 26521da177e4SLinus Torvalds val &= ~0x03; /* disable */ 26531da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_CLOCK, val); 26541da177e4SLinus Torvalds 26551da177e4SLinus Torvalds /* set default: slot 3,4,7,8,6,9 26561da177e4SLinus Torvalds spdif-in monitor off, analog-spdif off, spdif-in off 26571da177e4SLinus Torvalds center on mic off, surround on line-in off 26581da177e4SLinus Torvalds downmix off, duplicate front off 26591da177e4SLinus Torvalds */ 26601da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 0); 26611da177e4SLinus Torvalds 26621da177e4SLinus Torvalds /* set GPIO0 for mic bias */ 26631da177e4SLinus Torvalds /* GPIO0 pin output, no interrupt, high */ 26641da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_SETUP, 26651da177e4SLinus Torvalds snd_ac97_read(ac97, AC97_ALC650_GPIO_SETUP) | 0x01); 26661da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS, 26671da177e4SLinus Torvalds (snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x100) & ~0x10); 26681da177e4SLinus Torvalds 26691da177e4SLinus Torvalds /* full DAC volume */ 26701da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808); 26711da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808); 26721da177e4SLinus Torvalds return 0; 26731da177e4SLinus Torvalds } 26741da177e4SLinus Torvalds 2675ee42381eSTakashi Iwai static void alc655_update_jacks(struct snd_ac97 *ac97) 26761da177e4SLinus Torvalds { 2677eb8caf30STakashi Iwai int shared; 26781da177e4SLinus Torvalds 2679831466f4SRandy Cushman /* shared Line-In / Surround Out */ 2680831466f4SRandy Cushman shared = is_shared_surrout(ac97); 2681eb8caf30STakashi Iwai ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 9, 2682eb8caf30STakashi Iwai shared ? (1 << 9) : 0, 0); 2683831466f4SRandy Cushman /* update shared Mic In / Center/LFE Out */ 2684831466f4SRandy Cushman shared = is_shared_clfeout(ac97); 26851da177e4SLinus Torvalds /* misc control; vrefout disable */ 26861da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12, 2687eb8caf30STakashi Iwai shared ? (1 << 12) : 0); 2688eb8caf30STakashi Iwai ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 10, 2689eb8caf30STakashi Iwai shared ? (1 << 10) : 0, 0); 26901da177e4SLinus Torvalds } 26911da177e4SLinus Torvalds 2692ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_alc655[] = { 26931da177e4SLinus Torvalds AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0), 2694eb8caf30STakashi Iwai AC97_SURROUND_JACK_MODE_CTL, 2695eb8caf30STakashi Iwai AC97_CHANNEL_MODE_CTL, 26961da177e4SLinus Torvalds }; 26971da177e4SLinus Torvalds 2698ee42381eSTakashi Iwai static int alc655_iec958_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 26991da177e4SLinus Torvalds { 27003b7a00dcSTakashi Iwai static const char * const texts_655[3] = { 27013b7a00dcSTakashi Iwai "PCM", "Analog In", "IEC958 In" 27023b7a00dcSTakashi Iwai }; 27033b7a00dcSTakashi Iwai static const char * const texts_658[4] = { 27043b7a00dcSTakashi Iwai "PCM", "Analog1 In", "Analog2 In", "IEC958 In" 27053b7a00dcSTakashi Iwai }; 2706ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 27071da177e4SLinus Torvalds 27083b7a00dcSTakashi Iwai if (ac97->spec.dev_flags) 27093b7a00dcSTakashi Iwai return snd_ctl_enum_info(uinfo, 1, 4, texts_658); 27103b7a00dcSTakashi Iwai else 27113b7a00dcSTakashi Iwai return snd_ctl_enum_info(uinfo, 1, 3, texts_655); 27121da177e4SLinus Torvalds } 27131da177e4SLinus Torvalds 2714ee42381eSTakashi Iwai static int alc655_iec958_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 27151da177e4SLinus Torvalds { 2716ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 27171da177e4SLinus Torvalds unsigned short val; 27181da177e4SLinus Torvalds 27191da177e4SLinus Torvalds val = ac97->regs[AC97_ALC650_MULTICH]; 27201da177e4SLinus Torvalds val = (val >> 12) & 3; 27211da177e4SLinus Torvalds if (ac97->spec.dev_flags && val == 3) 27221da177e4SLinus Torvalds val = 0; 27231da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = val; 27241da177e4SLinus Torvalds return 0; 27251da177e4SLinus Torvalds } 27261da177e4SLinus Torvalds 2727ee42381eSTakashi Iwai static int alc655_iec958_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 27281da177e4SLinus Torvalds { 2729ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 27301da177e4SLinus Torvalds 27311da177e4SLinus Torvalds return ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 3 << 12, 27321da177e4SLinus Torvalds (unsigned short)ucontrol->value.enumerated.item[0] << 12, 27331da177e4SLinus Torvalds 0); 27341da177e4SLinus Torvalds } 27351da177e4SLinus Torvalds 2736ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc655[] = { 273710e8d78aSClemens Ladisch AC97_PAGE_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0, 0), 27381da177e4SLinus Torvalds /* disable this controls since it doesn't work as expected */ 27391da177e4SLinus Torvalds /* AC97_PAGE_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 14, 1, 0, 0), */ 27401da177e4SLinus Torvalds { 27411da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2742031c95d4STakashi Iwai .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source", 27431da177e4SLinus Torvalds .info = alc655_iec958_route_info, 27441da177e4SLinus Torvalds .get = alc655_iec958_route_get, 27451da177e4SLinus Torvalds .put = alc655_iec958_route_put, 27461da177e4SLinus Torvalds }, 27471da177e4SLinus Torvalds }; 27481da177e4SLinus Torvalds 2749ee42381eSTakashi Iwai static int patch_alc655_specific(struct snd_ac97 * ac97) 27501da177e4SLinus Torvalds { 27511da177e4SLinus Torvalds int err; 27521da177e4SLinus Torvalds 27531da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, snd_ac97_controls_alc655, ARRAY_SIZE(snd_ac97_controls_alc655))) < 0) 27541da177e4SLinus Torvalds return err; 27551da177e4SLinus Torvalds if (ac97->ext_id & AC97_EI_SPDIF) { 27561da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0) 27571da177e4SLinus Torvalds return err; 27581da177e4SLinus Torvalds } 27591da177e4SLinus Torvalds return 0; 27601da177e4SLinus Torvalds } 27611da177e4SLinus Torvalds 27623e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_alc655_ops = { 2763eb8caf30STakashi Iwai .build_specific = patch_alc655_specific, 2764eb8caf30STakashi Iwai .update_jacks = alc655_update_jacks 27651da177e4SLinus Torvalds }; 27661da177e4SLinus Torvalds 2767ac519028STakashi Iwai static int patch_alc655(struct snd_ac97 * ac97) 27681da177e4SLinus Torvalds { 27691da177e4SLinus Torvalds unsigned int val; 27701da177e4SLinus Torvalds 2771a5022b0dSTakashi Iwai if (ac97->id == AC97_ID_ALC658) { 2772a5022b0dSTakashi Iwai ac97->spec.dev_flags = 1; /* ALC658 */ 2773a5022b0dSTakashi Iwai if ((snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f) == 2) { 2774a5022b0dSTakashi Iwai ac97->id = AC97_ID_ALC658D; 2775a5022b0dSTakashi Iwai ac97->spec.dev_flags = 2; 2776a5022b0dSTakashi Iwai } 2777a5022b0dSTakashi Iwai } 27781da177e4SLinus Torvalds 27791da177e4SLinus Torvalds ac97->build_ops = &patch_alc655_ops; 27801da177e4SLinus Torvalds 27811da177e4SLinus Torvalds /* assume only page 0 for writing cache */ 27821da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR); 27831da177e4SLinus Torvalds 27841da177e4SLinus Torvalds /* adjust default values */ 27851da177e4SLinus Torvalds val = snd_ac97_read(ac97, 0x7a); /* misc control */ 2786a5022b0dSTakashi Iwai if (ac97->spec.dev_flags) /* ALC658 */ 27871da177e4SLinus Torvalds val &= ~(1 << 1); /* Pin 47 is spdif input pin */ 2788ee71508eSTakashi Iwai else { /* ALC655 */ 2789ee71508eSTakashi Iwai if (ac97->subsystem_vendor == 0x1462 && 2790d244bf89SMagnus Sandin (ac97->subsystem_device == 0x0131 || /* MSI S270 laptop */ 2791e7d24f0bSJaroslav Kysela ac97->subsystem_device == 0x0161 || /* LG K1 Express */ 2792cbcc2c4cSJerome Demange ac97->subsystem_device == 0x0351 || /* MSI L725 laptop */ 2793592a82e8STakashi Iwai ac97->subsystem_device == 0x0471 || /* MSI L720 laptop */ 2794cbcc2c4cSJerome Demange ac97->subsystem_device == 0x0061)) /* MSI S250 laptop */ 2795ee71508eSTakashi Iwai val &= ~(1 << 1); /* Pin 47 is EAPD (for internal speaker) */ 2796ee71508eSTakashi Iwai else 27971da177e4SLinus Torvalds val |= (1 << 1); /* Pin 47 is spdif input pin */ 2798c872e8caSTakashi Iwai /* this seems missing on some hardwares */ 2799c872e8caSTakashi Iwai ac97->ext_id |= AC97_EI_SPDIF; 2800ee71508eSTakashi Iwai } 28011da177e4SLinus Torvalds val &= ~(1 << 12); /* vref enable */ 28021da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x7a, val); 28031da177e4SLinus Torvalds /* set default: spdif-in enabled, 28041da177e4SLinus Torvalds spdif-in monitor off, spdif-in PCM off 28051da177e4SLinus Torvalds center on mic off, surround on line-in off 28061da177e4SLinus Torvalds duplicate front off 28071da177e4SLinus Torvalds */ 28081da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15); 28091da177e4SLinus Torvalds 28101da177e4SLinus Torvalds /* full DAC volume */ 28111da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808); 28121da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808); 2813a5022b0dSTakashi Iwai 2814a5022b0dSTakashi Iwai /* update undocumented bit... */ 2815a5022b0dSTakashi Iwai if (ac97->id == AC97_ID_ALC658D) 2816a5022b0dSTakashi Iwai snd_ac97_update_bits(ac97, 0x74, 0x0800, 0x0800); 2817a5022b0dSTakashi Iwai 28181da177e4SLinus Torvalds return 0; 28191da177e4SLinus Torvalds } 28201da177e4SLinus Torvalds 28211da177e4SLinus Torvalds 28221da177e4SLinus Torvalds #define AC97_ALC850_JACK_SELECT 0x76 28231da177e4SLinus Torvalds #define AC97_ALC850_MISC1 0x7a 28244235a317STakashi Iwai #define AC97_ALC850_MULTICH 0x6a 28251da177e4SLinus Torvalds 2826ee42381eSTakashi Iwai static void alc850_update_jacks(struct snd_ac97 *ac97) 28271da177e4SLinus Torvalds { 2828eb8caf30STakashi Iwai int shared; 28294235a317STakashi Iwai int aux_is_back_surround; 28301da177e4SLinus Torvalds 2831831466f4SRandy Cushman /* shared Line-In / Surround Out */ 2832831466f4SRandy Cushman shared = is_shared_surrout(ac97); 28331da177e4SLinus Torvalds /* SURR 1kOhm (bit4), Amp (bit5) */ 28341da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<4)|(1<<5), 2835eb8caf30STakashi Iwai shared ? (1<<5) : (1<<4)); 28361da177e4SLinus Torvalds /* LINE-IN = 0, SURROUND = 2 */ 2837eb8caf30STakashi Iwai snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 12, 2838eb8caf30STakashi Iwai shared ? (2<<12) : (0<<12)); 2839831466f4SRandy Cushman /* update shared Mic In / Center/LFE Out */ 2840831466f4SRandy Cushman shared = is_shared_clfeout(ac97); 28411da177e4SLinus Torvalds /* Vref disable (bit12), 1kOhm (bit13) */ 28421da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<12)|(1<<13), 2843eb8caf30STakashi Iwai shared ? (1<<12) : (1<<13)); 2844da79e44dSTakashi Iwai /* MIC-IN = 1, CENTER-LFE = 5 */ 2845eb8caf30STakashi Iwai snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 4, 2846da79e44dSTakashi Iwai shared ? (5<<4) : (1<<4)); 28474235a317STakashi Iwai 28484235a317STakashi Iwai aux_is_back_surround = alc850_is_aux_back_surround(ac97); 28494235a317STakashi Iwai /* Aux is Back Surround */ 28504235a317STakashi Iwai snd_ac97_update_bits(ac97, AC97_ALC850_MULTICH, 1 << 10, 28514235a317STakashi Iwai aux_is_back_surround ? (1<<10) : (0<<10)); 28521da177e4SLinus Torvalds } 28531da177e4SLinus Torvalds 2854ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_alc850[] = { 28551da177e4SLinus Torvalds AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0), 285667e1b51eSSergey Vlasov AC97_SINGLE("Mic Front Input Switch", AC97_ALC850_JACK_SELECT, 15, 1, 1), 2857eb8caf30STakashi Iwai AC97_SURROUND_JACK_MODE_CTL, 28584235a317STakashi Iwai AC97_CHANNEL_MODE_8CH_CTL, 28591da177e4SLinus Torvalds }; 28601da177e4SLinus Torvalds 2861ee42381eSTakashi Iwai static int patch_alc850_specific(struct snd_ac97 *ac97) 28621da177e4SLinus Torvalds { 28631da177e4SLinus Torvalds int err; 28641da177e4SLinus Torvalds 28651da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, snd_ac97_controls_alc850, ARRAY_SIZE(snd_ac97_controls_alc850))) < 0) 28661da177e4SLinus Torvalds return err; 28671da177e4SLinus Torvalds if (ac97->ext_id & AC97_EI_SPDIF) { 28681da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0) 28691da177e4SLinus Torvalds return err; 28701da177e4SLinus Torvalds } 28711da177e4SLinus Torvalds return 0; 28721da177e4SLinus Torvalds } 28731da177e4SLinus Torvalds 28743e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_alc850_ops = { 2875eb8caf30STakashi Iwai .build_specific = patch_alc850_specific, 2876eb8caf30STakashi Iwai .update_jacks = alc850_update_jacks 28771da177e4SLinus Torvalds }; 28781da177e4SLinus Torvalds 2879ac519028STakashi Iwai static int patch_alc850(struct snd_ac97 *ac97) 28801da177e4SLinus Torvalds { 28811da177e4SLinus Torvalds ac97->build_ops = &patch_alc850_ops; 28821da177e4SLinus Torvalds 28831da177e4SLinus Torvalds ac97->spec.dev_flags = 0; /* for IEC958 playback route - ALC655 compatible */ 28844235a317STakashi Iwai ac97->flags |= AC97_HAS_8CH; 28851da177e4SLinus Torvalds 28861da177e4SLinus Torvalds /* assume only page 0 for writing cache */ 28871da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR); 28881da177e4SLinus Torvalds 28891da177e4SLinus Torvalds /* adjust default values */ 28901da177e4SLinus Torvalds /* set default: spdif-in enabled, 28911da177e4SLinus Torvalds spdif-in monitor off, spdif-in PCM off 28921da177e4SLinus Torvalds center on mic off, surround on line-in off 28931da177e4SLinus Torvalds duplicate front off 28944235a317STakashi Iwai NB default bit 10=0 = Aux is Capture, not Back Surround 28951da177e4SLinus Torvalds */ 28961da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15); 28971da177e4SLinus Torvalds /* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off 28981da177e4SLinus Torvalds * Front Amp: on, Vref: enable, Center 1kOhm: on, Mix: on 28991da177e4SLinus Torvalds */ 29001da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x7a, (1<<1)|(1<<4)|(0<<5)|(1<<6)| 29011da177e4SLinus Torvalds (1<<7)|(0<<12)|(1<<13)|(0<<14)); 29021da177e4SLinus Torvalds /* detection UIO2,3: all path floating, UIO3: MIC, Vref2: disable, 29031da177e4SLinus Torvalds * UIO1: FRONT, Vref3: disable, UIO3: LINE, Front-Mic: mute 29041da177e4SLinus Torvalds */ 29051da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x76, (0<<0)|(0<<2)|(1<<4)|(1<<7)|(2<<8)| 29061da177e4SLinus Torvalds (1<<11)|(0<<12)|(1<<15)); 29071da177e4SLinus Torvalds 29081da177e4SLinus Torvalds /* full DAC volume */ 29091da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808); 29101da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808); 29111da177e4SLinus Torvalds return 0; 29121da177e4SLinus Torvalds } 29131da177e4SLinus Torvalds 29146ba9256cSAndreas Mohr static int patch_aztech_azf3328_specific(struct snd_ac97 *ac97) 29156ba9256cSAndreas Mohr { 29166ba9256cSAndreas Mohr struct snd_kcontrol *kctl_3d_center = 29176ba9256cSAndreas Mohr snd_ac97_find_mixer_ctl(ac97, "3D Control - Center"); 29186ba9256cSAndreas Mohr struct snd_kcontrol *kctl_3d_depth = 29196ba9256cSAndreas Mohr snd_ac97_find_mixer_ctl(ac97, "3D Control - Depth"); 29206ba9256cSAndreas Mohr 29216ba9256cSAndreas Mohr /* 29226ba9256cSAndreas Mohr * 3D register is different from AC97 standard layout 29236ba9256cSAndreas Mohr * (also do some renaming, to resemble Windows driver naming) 29246ba9256cSAndreas Mohr */ 29256ba9256cSAndreas Mohr if (kctl_3d_center) { 29266ba9256cSAndreas Mohr kctl_3d_center->private_value = 29276ba9256cSAndreas Mohr AC97_SINGLE_VALUE(AC97_3D_CONTROL, 1, 0x07, 0); 29286ba9256cSAndreas Mohr snd_ac97_rename_vol_ctl(ac97, 29296ba9256cSAndreas Mohr "3D Control - Center", "3D Control - Width" 29306ba9256cSAndreas Mohr ); 29316ba9256cSAndreas Mohr } 29326ba9256cSAndreas Mohr if (kctl_3d_depth) 29336ba9256cSAndreas Mohr kctl_3d_depth->private_value = 29346ba9256cSAndreas Mohr AC97_SINGLE_VALUE(AC97_3D_CONTROL, 8, 0x03, 0); 29356ba9256cSAndreas Mohr 29366ba9256cSAndreas Mohr /* Aztech Windows driver calls the 29376ba9256cSAndreas Mohr equivalent control "Modem Playback", thus rename it: */ 29386ba9256cSAndreas Mohr snd_ac97_rename_vol_ctl(ac97, 29396ba9256cSAndreas Mohr "Master Mono Playback", "Modem Playback" 29406ba9256cSAndreas Mohr ); 29416ba9256cSAndreas Mohr snd_ac97_rename_vol_ctl(ac97, 29426ba9256cSAndreas Mohr "Headphone Playback", "FM Synth Playback" 29436ba9256cSAndreas Mohr ); 29446ba9256cSAndreas Mohr 29456ba9256cSAndreas Mohr return 0; 29466ba9256cSAndreas Mohr } 29476ba9256cSAndreas Mohr 29486ba9256cSAndreas Mohr static const struct snd_ac97_build_ops patch_aztech_azf3328_ops = { 29496ba9256cSAndreas Mohr .build_specific = patch_aztech_azf3328_specific 29506ba9256cSAndreas Mohr }; 29516ba9256cSAndreas Mohr 29526ba9256cSAndreas Mohr static int patch_aztech_azf3328(struct snd_ac97 *ac97) 29536ba9256cSAndreas Mohr { 29546ba9256cSAndreas Mohr ac97->build_ops = &patch_aztech_azf3328_ops; 29556ba9256cSAndreas Mohr return 0; 29566ba9256cSAndreas Mohr } 29571da177e4SLinus Torvalds 29581da177e4SLinus Torvalds /* 29591da177e4SLinus Torvalds * C-Media CM97xx codecs 29601da177e4SLinus Torvalds */ 2961ee42381eSTakashi Iwai static void cm9738_update_jacks(struct snd_ac97 *ac97) 2962eb8caf30STakashi Iwai { 2963831466f4SRandy Cushman /* shared Line-In / Surround Out */ 2964eb8caf30STakashi Iwai snd_ac97_update_bits(ac97, AC97_CM9738_VENDOR_CTRL, 1 << 10, 2965831466f4SRandy Cushman is_shared_surrout(ac97) ? (1 << 10) : 0); 2966eb8caf30STakashi Iwai } 2967eb8caf30STakashi Iwai 2968ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_cm9738_controls[] = { 29691da177e4SLinus Torvalds AC97_SINGLE("Duplicate Front", AC97_CM9738_VENDOR_CTRL, 13, 1, 0), 2970eb8caf30STakashi Iwai AC97_SURROUND_JACK_MODE_CTL, 2971eb8caf30STakashi Iwai AC97_CHANNEL_MODE_4CH_CTL, 29721da177e4SLinus Torvalds }; 29731da177e4SLinus Torvalds 2974ee42381eSTakashi Iwai static int patch_cm9738_specific(struct snd_ac97 * ac97) 29751da177e4SLinus Torvalds { 29761da177e4SLinus Torvalds return patch_build_controls(ac97, snd_ac97_cm9738_controls, ARRAY_SIZE(snd_ac97_cm9738_controls)); 29771da177e4SLinus Torvalds } 29781da177e4SLinus Torvalds 29793e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_cm9738_ops = { 2980eb8caf30STakashi Iwai .build_specific = patch_cm9738_specific, 2981eb8caf30STakashi Iwai .update_jacks = cm9738_update_jacks 29821da177e4SLinus Torvalds }; 29831da177e4SLinus Torvalds 2984ac519028STakashi Iwai static int patch_cm9738(struct snd_ac97 * ac97) 29851da177e4SLinus Torvalds { 29861da177e4SLinus Torvalds ac97->build_ops = &patch_cm9738_ops; 29871da177e4SLinus Torvalds /* FIXME: can anyone confirm below? */ 29881da177e4SLinus Torvalds /* CM9738 has no PCM volume although the register reacts */ 29891da177e4SLinus Torvalds ac97->flags |= AC97_HAS_NO_PCM_VOL; 29901da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_PCM, 0x8000); 29911da177e4SLinus Torvalds 29921da177e4SLinus Torvalds return 0; 29931da177e4SLinus Torvalds } 29941da177e4SLinus Torvalds 2995ee42381eSTakashi Iwai static int snd_ac97_cmedia_spdif_playback_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 29961da177e4SLinus Torvalds { 29973b7a00dcSTakashi Iwai static const char * const texts[] = { "Analog", "Digital" }; 29981da177e4SLinus Torvalds 29993b7a00dcSTakashi Iwai return snd_ctl_enum_info(uinfo, 1, 2, texts); 30001da177e4SLinus Torvalds } 30011da177e4SLinus Torvalds 3002ee42381eSTakashi Iwai static int snd_ac97_cmedia_spdif_playback_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 30031da177e4SLinus Torvalds { 3004ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 30051da177e4SLinus Torvalds unsigned short val; 30061da177e4SLinus Torvalds 30071da177e4SLinus Torvalds val = ac97->regs[AC97_CM9739_SPDIF_CTRL]; 30081da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = (val >> 1) & 0x01; 30091da177e4SLinus Torvalds return 0; 30101da177e4SLinus Torvalds } 30111da177e4SLinus Torvalds 3012ee42381eSTakashi Iwai static int snd_ac97_cmedia_spdif_playback_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 30131da177e4SLinus Torvalds { 3014ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 30151da177e4SLinus Torvalds 30161da177e4SLinus Torvalds return snd_ac97_update_bits(ac97, AC97_CM9739_SPDIF_CTRL, 30171da177e4SLinus Torvalds 0x01 << 1, 30181da177e4SLinus Torvalds (ucontrol->value.enumerated.item[0] & 0x01) << 1); 30191da177e4SLinus Torvalds } 30201da177e4SLinus Torvalds 3021ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_cm9739_controls_spdif[] = { 30221da177e4SLinus Torvalds /* BIT 0: SPDI_EN - always true */ 30231da177e4SLinus Torvalds { /* BIT 1: SPDIFS */ 30241da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 30251da177e4SLinus Torvalds .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source", 30261da177e4SLinus Torvalds .info = snd_ac97_cmedia_spdif_playback_source_info, 30271da177e4SLinus Torvalds .get = snd_ac97_cmedia_spdif_playback_source_get, 30281da177e4SLinus Torvalds .put = snd_ac97_cmedia_spdif_playback_source_put, 30291da177e4SLinus Torvalds }, 30301da177e4SLinus Torvalds /* BIT 2: IG_SPIV */ 30311da177e4SLinus Torvalds AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9739_SPDIF_CTRL, 2, 1, 0), 30321da177e4SLinus Torvalds /* BIT 3: SPI2F */ 30331da177e4SLinus Torvalds AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9739_SPDIF_CTRL, 3, 1, 0), 30341da177e4SLinus Torvalds /* BIT 4: SPI2SDI */ 30351da177e4SLinus Torvalds AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9739_SPDIF_CTRL, 4, 1, 0), 30361da177e4SLinus Torvalds /* BIT 8: SPD32 - 32bit SPDIF - not supported yet */ 30371da177e4SLinus Torvalds }; 30381da177e4SLinus Torvalds 3039ee42381eSTakashi Iwai static void cm9739_update_jacks(struct snd_ac97 *ac97) 30401da177e4SLinus Torvalds { 3041831466f4SRandy Cushman /* shared Line-In / Surround Out */ 3042eb8caf30STakashi Iwai snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 1 << 10, 3043831466f4SRandy Cushman is_shared_surrout(ac97) ? (1 << 10) : 0); 3044831466f4SRandy Cushman /* shared Mic In / Center/LFE Out **/ 3045eb8caf30STakashi Iwai snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 0x3000, 3046831466f4SRandy Cushman is_shared_clfeout(ac97) ? 0x1000 : 0x2000); 30471da177e4SLinus Torvalds } 30481da177e4SLinus Torvalds 3049ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_cm9739_controls[] = { 3050eb8caf30STakashi Iwai AC97_SURROUND_JACK_MODE_CTL, 3051eb8caf30STakashi Iwai AC97_CHANNEL_MODE_CTL, 30521da177e4SLinus Torvalds }; 30531da177e4SLinus Torvalds 3054ee42381eSTakashi Iwai static int patch_cm9739_specific(struct snd_ac97 * ac97) 30551da177e4SLinus Torvalds { 30561da177e4SLinus Torvalds return patch_build_controls(ac97, snd_ac97_cm9739_controls, ARRAY_SIZE(snd_ac97_cm9739_controls)); 30571da177e4SLinus Torvalds } 30581da177e4SLinus Torvalds 3059ee42381eSTakashi Iwai static int patch_cm9739_post_spdif(struct snd_ac97 * ac97) 30601da177e4SLinus Torvalds { 30611da177e4SLinus Torvalds return patch_build_controls(ac97, snd_ac97_cm9739_controls_spdif, ARRAY_SIZE(snd_ac97_cm9739_controls_spdif)); 30621da177e4SLinus Torvalds } 30631da177e4SLinus Torvalds 30643e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_cm9739_ops = { 30651da177e4SLinus Torvalds .build_specific = patch_cm9739_specific, 3066eb8caf30STakashi Iwai .build_post_spdif = patch_cm9739_post_spdif, 3067eb8caf30STakashi Iwai .update_jacks = cm9739_update_jacks 30681da177e4SLinus Torvalds }; 30691da177e4SLinus Torvalds 3070ac519028STakashi Iwai static int patch_cm9739(struct snd_ac97 * ac97) 30711da177e4SLinus Torvalds { 30721da177e4SLinus Torvalds unsigned short val; 30731da177e4SLinus Torvalds 30741da177e4SLinus Torvalds ac97->build_ops = &patch_cm9739_ops; 30751da177e4SLinus Torvalds 30761da177e4SLinus Torvalds /* CM9739/A has no Master and PCM volume although the register reacts */ 30771da177e4SLinus Torvalds ac97->flags |= AC97_HAS_NO_MASTER_VOL | AC97_HAS_NO_PCM_VOL; 30781da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_MASTER, 0x8000); 30791da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_PCM, 0x8000); 30801da177e4SLinus Torvalds 30811da177e4SLinus Torvalds /* check spdif */ 30821da177e4SLinus Torvalds val = snd_ac97_read(ac97, AC97_EXTENDED_STATUS); 30831da177e4SLinus Torvalds if (val & AC97_EA_SPCV) { 30841da177e4SLinus Torvalds /* enable spdif in */ 30851da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL, 30861da177e4SLinus Torvalds snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) | 0x01); 30871da177e4SLinus Torvalds ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */ 30881da177e4SLinus Torvalds } else { 30891da177e4SLinus Torvalds ac97->ext_id &= ~AC97_EI_SPDIF; /* disable extended-id */ 30901da177e4SLinus Torvalds ac97->rates[AC97_RATES_SPDIF] = 0; 30911da177e4SLinus Torvalds } 30921da177e4SLinus Torvalds 30931da177e4SLinus Torvalds /* set-up multi channel */ 30941da177e4SLinus Torvalds /* bit 14: 0 = SPDIF, 1 = EAPD */ 30951da177e4SLinus Torvalds /* bit 13: enable internal vref output for mic */ 309608a7e621SMasahiro Yamada /* bit 12: disable center/lfe (switchable) */ 30971da177e4SLinus Torvalds /* bit 10: disable surround/line (switchable) */ 30981da177e4SLinus Torvalds /* bit 9: mix 2 surround off */ 30991da177e4SLinus Torvalds /* bit 4: undocumented; 0 mutes the CM9739A, which defaults to 1 */ 31001da177e4SLinus Torvalds /* bit 3: undocumented; surround? */ 31011da177e4SLinus Torvalds /* bit 0: dB */ 31021da177e4SLinus Torvalds val = snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) & (1 << 4); 31031da177e4SLinus Torvalds val |= (1 << 3); 31041da177e4SLinus Torvalds val |= (1 << 13); 31051da177e4SLinus Torvalds if (! (ac97->ext_id & AC97_EI_SPDIF)) 31061da177e4SLinus Torvalds val |= (1 << 14); 31071da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, val); 31081da177e4SLinus Torvalds 31091da177e4SLinus Torvalds /* FIXME: set up GPIO */ 31101da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x70, 0x0100); 31111da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x72, 0x0020); 31121da177e4SLinus Torvalds /* Special exception for ASUS W1000/CMI9739. It does not have an SPDIF in. */ 31131da177e4SLinus Torvalds if (ac97->pci && 31141da177e4SLinus Torvalds ac97->subsystem_vendor == 0x1043 && 31151da177e4SLinus Torvalds ac97->subsystem_device == 0x1843) { 31161da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL, 31171da177e4SLinus Torvalds snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) & ~0x01); 31181da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, 31191da177e4SLinus Torvalds snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) | (1 << 14)); 31201da177e4SLinus Torvalds } 31211da177e4SLinus Torvalds 31221da177e4SLinus Torvalds return 0; 31231da177e4SLinus Torvalds } 31241da177e4SLinus Torvalds 31251da177e4SLinus Torvalds #define AC97_CM9761_MULTI_CHAN 0x64 31265f0dccf8STakashi Iwai #define AC97_CM9761_FUNC 0x66 31271da177e4SLinus Torvalds #define AC97_CM9761_SPDIF_CTRL 0x6c 31281da177e4SLinus Torvalds 3129ee42381eSTakashi Iwai static void cm9761_update_jacks(struct snd_ac97 *ac97) 31301da177e4SLinus Torvalds { 31314525c9f3STakashi Iwai /* FIXME: check the bits for each model 31324525c9f3STakashi Iwai * model 83 is confirmed to work 31334525c9f3STakashi Iwai */ 31344525c9f3STakashi Iwai static unsigned short surr_on[3][2] = { 31354525c9f3STakashi Iwai { 0x0008, 0x0000 }, /* 9761-78 & 82 */ 31364525c9f3STakashi Iwai { 0x0000, 0x0008 }, /* 9761-82 rev.B */ 31374525c9f3STakashi Iwai { 0x0000, 0x0008 }, /* 9761-83 */ 31381da177e4SLinus Torvalds }; 31394525c9f3STakashi Iwai static unsigned short clfe_on[3][2] = { 31404525c9f3STakashi Iwai { 0x0000, 0x1000 }, /* 9761-78 & 82 */ 31414525c9f3STakashi Iwai { 0x1000, 0x0000 }, /* 9761-82 rev.B */ 31424525c9f3STakashi Iwai { 0x0000, 0x1000 }, /* 9761-83 */ 31431da177e4SLinus Torvalds }; 31444525c9f3STakashi Iwai static unsigned short surr_shared[3][2] = { 31454525c9f3STakashi Iwai { 0x0000, 0x0400 }, /* 9761-78 & 82 */ 31464525c9f3STakashi Iwai { 0x0000, 0x0400 }, /* 9761-82 rev.B */ 31474525c9f3STakashi Iwai { 0x0000, 0x0400 }, /* 9761-83 */ 31484525c9f3STakashi Iwai }; 31494525c9f3STakashi Iwai static unsigned short clfe_shared[3][2] = { 31504525c9f3STakashi Iwai { 0x2000, 0x0880 }, /* 9761-78 & 82 */ 31514525c9f3STakashi Iwai { 0x0000, 0x2880 }, /* 9761-82 rev.B */ 31524525c9f3STakashi Iwai { 0x2000, 0x0800 }, /* 9761-83 */ 31534525c9f3STakashi Iwai }; 31544525c9f3STakashi Iwai unsigned short val = 0; 3155eb8caf30STakashi Iwai 31564525c9f3STakashi Iwai val |= surr_on[ac97->spec.dev_flags][is_surround_on(ac97)]; 31574525c9f3STakashi Iwai val |= clfe_on[ac97->spec.dev_flags][is_clfe_on(ac97)]; 3158831466f4SRandy Cushman val |= surr_shared[ac97->spec.dev_flags][is_shared_surrout(ac97)]; 3159831466f4SRandy Cushman val |= clfe_shared[ac97->spec.dev_flags][is_shared_clfeout(ac97)]; 31604525c9f3STakashi Iwai 31614525c9f3STakashi Iwai snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x3c88, val); 31621da177e4SLinus Torvalds } 31631da177e4SLinus Torvalds 3164ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_cm9761_controls[] = { 3165eb8caf30STakashi Iwai AC97_SURROUND_JACK_MODE_CTL, 3166eb8caf30STakashi Iwai AC97_CHANNEL_MODE_CTL, 31671da177e4SLinus Torvalds }; 31681da177e4SLinus Torvalds 3169ee42381eSTakashi Iwai static int cm9761_spdif_out_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 31705f0dccf8STakashi Iwai { 31713b7a00dcSTakashi Iwai static const char * const texts[] = { "AC-Link", "ADC", "SPDIF-In" }; 31725f0dccf8STakashi Iwai 31733b7a00dcSTakashi Iwai return snd_ctl_enum_info(uinfo, 1, 3, texts); 31745f0dccf8STakashi Iwai } 31755f0dccf8STakashi Iwai 3176ee42381eSTakashi Iwai static int cm9761_spdif_out_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 31775f0dccf8STakashi Iwai { 3178ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 31795f0dccf8STakashi Iwai 31805f0dccf8STakashi Iwai if (ac97->regs[AC97_CM9761_FUNC] & 0x1) 31815f0dccf8STakashi Iwai ucontrol->value.enumerated.item[0] = 2; /* SPDIF-loopback */ 31825f0dccf8STakashi Iwai else if (ac97->regs[AC97_CM9761_SPDIF_CTRL] & 0x2) 31835f0dccf8STakashi Iwai ucontrol->value.enumerated.item[0] = 1; /* ADC loopback */ 31845f0dccf8STakashi Iwai else 31855f0dccf8STakashi Iwai ucontrol->value.enumerated.item[0] = 0; /* AC-link */ 31865f0dccf8STakashi Iwai return 0; 31875f0dccf8STakashi Iwai } 31885f0dccf8STakashi Iwai 3189ee42381eSTakashi Iwai static int cm9761_spdif_out_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 31905f0dccf8STakashi Iwai { 3191ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 31925f0dccf8STakashi Iwai 31935f0dccf8STakashi Iwai if (ucontrol->value.enumerated.item[0] == 2) 31945f0dccf8STakashi Iwai return snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0x1); 31955f0dccf8STakashi Iwai snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0); 31965f0dccf8STakashi Iwai return snd_ac97_update_bits(ac97, AC97_CM9761_SPDIF_CTRL, 0x2, 31975f0dccf8STakashi Iwai ucontrol->value.enumerated.item[0] == 1 ? 0x2 : 0); 31985f0dccf8STakashi Iwai } 31995f0dccf8STakashi Iwai 32001bc10bb6STakashi Iwai static const char * const cm9761_dac_clock[] = { 32011bc10bb6STakashi Iwai "AC-Link", "SPDIF-In", "Both" 32021bc10bb6STakashi Iwai }; 32035f0dccf8STakashi Iwai static const struct ac97_enum cm9761_dac_clock_enum = 32045f0dccf8STakashi Iwai AC97_ENUM_SINGLE(AC97_CM9761_SPDIF_CTRL, 9, 3, cm9761_dac_clock); 32055f0dccf8STakashi Iwai 3206ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_cm9761_controls_spdif[] = { 32075f0dccf8STakashi Iwai { /* BIT 1: SPDIFS */ 32085f0dccf8STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 32095f0dccf8STakashi Iwai .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source", 32105f0dccf8STakashi Iwai .info = cm9761_spdif_out_source_info, 32115f0dccf8STakashi Iwai .get = cm9761_spdif_out_source_get, 32125f0dccf8STakashi Iwai .put = cm9761_spdif_out_source_put, 32135f0dccf8STakashi Iwai }, 32145f0dccf8STakashi Iwai /* BIT 2: IG_SPIV */ 32155f0dccf8STakashi Iwai AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9761_SPDIF_CTRL, 2, 1, 0), 32165f0dccf8STakashi Iwai /* BIT 3: SPI2F */ 32175f0dccf8STakashi Iwai AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9761_SPDIF_CTRL, 3, 1, 0), 32185f0dccf8STakashi Iwai /* BIT 4: SPI2SDI */ 32195f0dccf8STakashi Iwai AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9761_SPDIF_CTRL, 4, 1, 0), 32205f0dccf8STakashi Iwai /* BIT 9-10: DAC_CTL */ 32215f0dccf8STakashi Iwai AC97_ENUM("DAC Clock Source", cm9761_dac_clock_enum), 32225f0dccf8STakashi Iwai }; 32235f0dccf8STakashi Iwai 3224ee42381eSTakashi Iwai static int patch_cm9761_post_spdif(struct snd_ac97 * ac97) 32255f0dccf8STakashi Iwai { 32265f0dccf8STakashi Iwai return patch_build_controls(ac97, snd_ac97_cm9761_controls_spdif, ARRAY_SIZE(snd_ac97_cm9761_controls_spdif)); 32275f0dccf8STakashi Iwai } 32285f0dccf8STakashi Iwai 3229ee42381eSTakashi Iwai static int patch_cm9761_specific(struct snd_ac97 * ac97) 32301da177e4SLinus Torvalds { 32311da177e4SLinus Torvalds return patch_build_controls(ac97, snd_ac97_cm9761_controls, ARRAY_SIZE(snd_ac97_cm9761_controls)); 32321da177e4SLinus Torvalds } 32331da177e4SLinus Torvalds 32343e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_cm9761_ops = { 32351da177e4SLinus Torvalds .build_specific = patch_cm9761_specific, 3236eb8caf30STakashi Iwai .build_post_spdif = patch_cm9761_post_spdif, 3237eb8caf30STakashi Iwai .update_jacks = cm9761_update_jacks 32381da177e4SLinus Torvalds }; 32391da177e4SLinus Torvalds 3240ac519028STakashi Iwai static int patch_cm9761(struct snd_ac97 *ac97) 32411da177e4SLinus Torvalds { 32421da177e4SLinus Torvalds unsigned short val; 32431da177e4SLinus Torvalds 32441da177e4SLinus Torvalds /* CM9761 has no PCM volume although the register reacts */ 32451da177e4SLinus Torvalds /* Master volume seems to have _some_ influence on the analog 32461da177e4SLinus Torvalds * input sounds 32471da177e4SLinus Torvalds */ 32481da177e4SLinus Torvalds ac97->flags |= /*AC97_HAS_NO_MASTER_VOL |*/ AC97_HAS_NO_PCM_VOL; 32491da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_MASTER, 0x8808); 32501da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_PCM, 0x8808); 32511da177e4SLinus Torvalds 32524525c9f3STakashi Iwai ac97->spec.dev_flags = 0; /* 1 = model 82 revision B, 2 = model 83 */ 32531da177e4SLinus Torvalds if (ac97->id == AC97_ID_CM9761_82) { 32541da177e4SLinus Torvalds unsigned short tmp; 32551da177e4SLinus Torvalds /* check page 1, reg 0x60 */ 32561da177e4SLinus Torvalds val = snd_ac97_read(ac97, AC97_INT_PAGING); 32571da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_INT_PAGING, (val & ~0x0f) | 0x01); 32581da177e4SLinus Torvalds tmp = snd_ac97_read(ac97, 0x60); 32591da177e4SLinus Torvalds ac97->spec.dev_flags = tmp & 1; /* revision B? */ 32601da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_INT_PAGING, val); 32614525c9f3STakashi Iwai } else if (ac97->id == AC97_ID_CM9761_83) 32624525c9f3STakashi Iwai ac97->spec.dev_flags = 2; 32631da177e4SLinus Torvalds 32641da177e4SLinus Torvalds ac97->build_ops = &patch_cm9761_ops; 32651da177e4SLinus Torvalds 32661da177e4SLinus Torvalds /* enable spdif */ 32671da177e4SLinus Torvalds /* force the SPDIF bit in ext_id - codec doesn't set this bit! */ 32681da177e4SLinus Torvalds ac97->ext_id |= AC97_EI_SPDIF; 32691da177e4SLinus Torvalds /* to be sure: we overwrite the ext status bits */ 32701da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, 0x05c0); 32711da177e4SLinus Torvalds /* Don't set 0x0200 here. This results in the silent analog output */ 32725f0dccf8STakashi Iwai snd_ac97_write_cache(ac97, AC97_CM9761_SPDIF_CTRL, 0x0001); /* enable spdif-in */ 32731da177e4SLinus Torvalds ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */ 32741da177e4SLinus Torvalds 32751da177e4SLinus Torvalds /* set-up multi channel */ 32761da177e4SLinus Torvalds /* bit 15: pc master beep off 32775f0dccf8STakashi Iwai * bit 14: pin47 = EAPD/SPDIF 32781da177e4SLinus Torvalds * bit 13: vref ctl [= cm9739] 32795f0dccf8STakashi Iwai * bit 12: CLFE control (reverted on rev B) 32805f0dccf8STakashi Iwai * bit 11: Mic/center share (reverted on rev B) 32815f0dccf8STakashi Iwai * bit 10: suddound/line share 32825f0dccf8STakashi Iwai * bit 9: Analog-in mix -> surround 32835f0dccf8STakashi Iwai * bit 8: Analog-in mix -> CLFE 32845f0dccf8STakashi Iwai * bit 7: Mic/LFE share (mic/center/lfe) 32855f0dccf8STakashi Iwai * bit 5: vref select (9761A) 32865f0dccf8STakashi Iwai * bit 4: front control 32875f0dccf8STakashi Iwai * bit 3: surround control (revereted with rev B) 32885f0dccf8STakashi Iwai * bit 2: front mic 32895f0dccf8STakashi Iwai * bit 1: stereo mic 32905f0dccf8STakashi Iwai * bit 0: mic boost level (0=20dB, 1=30dB) 32911da177e4SLinus Torvalds */ 32921da177e4SLinus Torvalds 32931da177e4SLinus Torvalds #if 0 32941da177e4SLinus Torvalds if (ac97->spec.dev_flags) 32951da177e4SLinus Torvalds val = 0x0214; 32961da177e4SLinus Torvalds else 32971da177e4SLinus Torvalds val = 0x321c; 32981da177e4SLinus Torvalds #endif 32991da177e4SLinus Torvalds val = snd_ac97_read(ac97, AC97_CM9761_MULTI_CHAN); 33001da177e4SLinus Torvalds val |= (1 << 4); /* front on */ 33011da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_CM9761_MULTI_CHAN, val); 33021da177e4SLinus Torvalds 33031da177e4SLinus Torvalds /* FIXME: set up GPIO */ 33041da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x70, 0x0100); 33051da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x72, 0x0020); 33061da177e4SLinus Torvalds 33071da177e4SLinus Torvalds return 0; 33081da177e4SLinus Torvalds } 33091da177e4SLinus Torvalds 33105f0dccf8STakashi Iwai #define AC97_CM9780_SIDE 0x60 33115f0dccf8STakashi Iwai #define AC97_CM9780_JACK 0x62 33125f0dccf8STakashi Iwai #define AC97_CM9780_MIXER 0x64 33135f0dccf8STakashi Iwai #define AC97_CM9780_MULTI_CHAN 0x66 33145f0dccf8STakashi Iwai #define AC97_CM9780_SPDIF 0x6c 33155f0dccf8STakashi Iwai 33161bc10bb6STakashi Iwai static const char * const cm9780_ch_select[] = { 33171bc10bb6STakashi Iwai "Front", "Side", "Center/LFE", "Rear" 33181bc10bb6STakashi Iwai }; 33195f0dccf8STakashi Iwai static const struct ac97_enum cm9780_ch_select_enum = 33205f0dccf8STakashi Iwai AC97_ENUM_SINGLE(AC97_CM9780_MULTI_CHAN, 6, 4, cm9780_ch_select); 3321ee42381eSTakashi Iwai static const struct snd_kcontrol_new cm9780_controls[] = { 33225f0dccf8STakashi Iwai AC97_DOUBLE("Side Playback Switch", AC97_CM9780_SIDE, 15, 7, 1, 1), 33235f0dccf8STakashi Iwai AC97_DOUBLE("Side Playback Volume", AC97_CM9780_SIDE, 8, 0, 31, 0), 33245f0dccf8STakashi Iwai AC97_ENUM("Side Playback Route", cm9780_ch_select_enum), 33255f0dccf8STakashi Iwai }; 33265f0dccf8STakashi Iwai 3327ee42381eSTakashi Iwai static int patch_cm9780_specific(struct snd_ac97 *ac97) 33285f0dccf8STakashi Iwai { 33295f0dccf8STakashi Iwai return patch_build_controls(ac97, cm9780_controls, ARRAY_SIZE(cm9780_controls)); 33305f0dccf8STakashi Iwai } 33315f0dccf8STakashi Iwai 33323e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_cm9780_ops = { 33335f0dccf8STakashi Iwai .build_specific = patch_cm9780_specific, 33345f0dccf8STakashi Iwai .build_post_spdif = patch_cm9761_post_spdif /* identical with CM9761 */ 33355f0dccf8STakashi Iwai }; 33365f0dccf8STakashi Iwai 3337ac519028STakashi Iwai static int patch_cm9780(struct snd_ac97 *ac97) 33385f0dccf8STakashi Iwai { 33395f0dccf8STakashi Iwai unsigned short val; 33405f0dccf8STakashi Iwai 33415f0dccf8STakashi Iwai ac97->build_ops = &patch_cm9780_ops; 33425f0dccf8STakashi Iwai 33435f0dccf8STakashi Iwai /* enable spdif */ 33445f0dccf8STakashi Iwai if (ac97->ext_id & AC97_EI_SPDIF) { 33455f0dccf8STakashi Iwai ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */ 33465f0dccf8STakashi Iwai val = snd_ac97_read(ac97, AC97_CM9780_SPDIF); 33475f0dccf8STakashi Iwai val |= 0x1; /* SPDI_EN */ 33485f0dccf8STakashi Iwai snd_ac97_write_cache(ac97, AC97_CM9780_SPDIF, val); 33495f0dccf8STakashi Iwai } 33505f0dccf8STakashi Iwai 33515f0dccf8STakashi Iwai return 0; 33525f0dccf8STakashi Iwai } 33531da177e4SLinus Torvalds 33541da177e4SLinus Torvalds /* 3355d6482288SMaciej S. Szmigiero * VIA VT1613 codec 3356d6482288SMaciej S. Szmigiero */ 3357d6482288SMaciej S. Szmigiero static const struct snd_kcontrol_new snd_ac97_controls_vt1613[] = { 3358d6482288SMaciej S. Szmigiero AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0), 3359d6482288SMaciej S. Szmigiero }; 3360d6482288SMaciej S. Szmigiero 3361d6482288SMaciej S. Szmigiero static int patch_vt1613_specific(struct snd_ac97 *ac97) 3362d6482288SMaciej S. Szmigiero { 33635371fc0eSFabio Estevam return patch_build_controls(ac97, &snd_ac97_controls_vt1613[0], 3364d6482288SMaciej S. Szmigiero ARRAY_SIZE(snd_ac97_controls_vt1613)); 3365d6482288SMaciej S. Szmigiero }; 3366d6482288SMaciej S. Szmigiero 3367d6482288SMaciej S. Szmigiero static const struct snd_ac97_build_ops patch_vt1613_ops = { 3368d6482288SMaciej S. Szmigiero .build_specific = patch_vt1613_specific 3369d6482288SMaciej S. Szmigiero }; 3370d6482288SMaciej S. Szmigiero 3371d6482288SMaciej S. Szmigiero static int patch_vt1613(struct snd_ac97 *ac97) 3372d6482288SMaciej S. Szmigiero { 3373d6482288SMaciej S. Szmigiero ac97->build_ops = &patch_vt1613_ops; 3374d6482288SMaciej S. Szmigiero 3375d6482288SMaciej S. Szmigiero ac97->flags |= AC97_HAS_NO_VIDEO; 3376d6482288SMaciej S. Szmigiero ac97->caps |= AC97_BC_HEADPHONE; 3377d6482288SMaciej S. Szmigiero 3378d6482288SMaciej S. Szmigiero return 0; 3379d6482288SMaciej S. Szmigiero } 3380d6482288SMaciej S. Szmigiero 3381d6482288SMaciej S. Szmigiero /* 33821da177e4SLinus Torvalds * VIA VT1616 codec 33831da177e4SLinus Torvalds */ 3384ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_vt1616[] = { 33851da177e4SLinus Torvalds AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0), 33861da177e4SLinus Torvalds AC97_SINGLE("Alternate Level to Surround Out", 0x5a, 15, 1, 0), 33871da177e4SLinus Torvalds AC97_SINGLE("Downmix LFE and Center to Front", 0x5a, 12, 1, 0), 33881da177e4SLinus Torvalds AC97_SINGLE("Downmix Surround to Front", 0x5a, 11, 1, 0), 33891da177e4SLinus Torvalds }; 33901da177e4SLinus Torvalds 33911bc10bb6STakashi Iwai static const char * const slave_vols_vt1616[] = { 339287af38daSDaniel Jacobowitz "Front Playback Volume", 339387af38daSDaniel Jacobowitz "Surround Playback Volume", 339487af38daSDaniel Jacobowitz "Center Playback Volume", 339587af38daSDaniel Jacobowitz "LFE Playback Volume", 339687af38daSDaniel Jacobowitz NULL 339787af38daSDaniel Jacobowitz }; 339887af38daSDaniel Jacobowitz 33991bc10bb6STakashi Iwai static const char * const slave_sws_vt1616[] = { 340087af38daSDaniel Jacobowitz "Front Playback Switch", 340187af38daSDaniel Jacobowitz "Surround Playback Switch", 340287af38daSDaniel Jacobowitz "Center Playback Switch", 340387af38daSDaniel Jacobowitz "LFE Playback Switch", 340487af38daSDaniel Jacobowitz NULL 340587af38daSDaniel Jacobowitz }; 340687af38daSDaniel Jacobowitz 340787af38daSDaniel Jacobowitz /* find a mixer control element with the given name */ 340887af38daSDaniel Jacobowitz static struct snd_kcontrol *snd_ac97_find_mixer_ctl(struct snd_ac97 *ac97, 340987af38daSDaniel Jacobowitz const char *name) 341087af38daSDaniel Jacobowitz { 341187af38daSDaniel Jacobowitz struct snd_ctl_elem_id id; 341287af38daSDaniel Jacobowitz memset(&id, 0, sizeof(id)); 341387af38daSDaniel Jacobowitz id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 341487af38daSDaniel Jacobowitz strcpy(id.name, name); 341587af38daSDaniel Jacobowitz return snd_ctl_find_id(ac97->bus->card, &id); 341687af38daSDaniel Jacobowitz } 341787af38daSDaniel Jacobowitz 341887af38daSDaniel Jacobowitz /* create a virtual master control and add slaves */ 341913c2108dSAdrian Bunk static int snd_ac97_add_vmaster(struct snd_ac97 *ac97, char *name, 34201bc10bb6STakashi Iwai const unsigned int *tlv, 34211bc10bb6STakashi Iwai const char * const *slaves) 342287af38daSDaniel Jacobowitz { 342387af38daSDaniel Jacobowitz struct snd_kcontrol *kctl; 34241bc10bb6STakashi Iwai const char * const *s; 342587af38daSDaniel Jacobowitz int err; 342687af38daSDaniel Jacobowitz 342787af38daSDaniel Jacobowitz kctl = snd_ctl_make_virtual_master(name, tlv); 342887af38daSDaniel Jacobowitz if (!kctl) 342987af38daSDaniel Jacobowitz return -ENOMEM; 343087af38daSDaniel Jacobowitz err = snd_ctl_add(ac97->bus->card, kctl); 343187af38daSDaniel Jacobowitz if (err < 0) 343287af38daSDaniel Jacobowitz return err; 343387af38daSDaniel Jacobowitz 343487af38daSDaniel Jacobowitz for (s = slaves; *s; s++) { 343587af38daSDaniel Jacobowitz struct snd_kcontrol *sctl; 343687af38daSDaniel Jacobowitz 343787af38daSDaniel Jacobowitz sctl = snd_ac97_find_mixer_ctl(ac97, *s); 343887af38daSDaniel Jacobowitz if (!sctl) { 343938c16e34STakashi Iwai dev_dbg(ac97->bus->card->dev, 344038c16e34STakashi Iwai "Cannot find slave %s, skipped\n", *s); 344187af38daSDaniel Jacobowitz continue; 344287af38daSDaniel Jacobowitz } 344387af38daSDaniel Jacobowitz err = snd_ctl_add_slave(kctl, sctl); 344487af38daSDaniel Jacobowitz if (err < 0) 344587af38daSDaniel Jacobowitz return err; 344687af38daSDaniel Jacobowitz } 344787af38daSDaniel Jacobowitz return 0; 344887af38daSDaniel Jacobowitz } 344987af38daSDaniel Jacobowitz 3450ee42381eSTakashi Iwai static int patch_vt1616_specific(struct snd_ac97 * ac97) 34511da177e4SLinus Torvalds { 345287af38daSDaniel Jacobowitz struct snd_kcontrol *kctl; 34531da177e4SLinus Torvalds int err; 34541da177e4SLinus Torvalds 34551da177e4SLinus Torvalds if (snd_ac97_try_bit(ac97, 0x5a, 9)) 34561da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[0], 1)) < 0) 34571da177e4SLinus Torvalds return err; 34581da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[1], ARRAY_SIZE(snd_ac97_controls_vt1616) - 1)) < 0) 34591da177e4SLinus Torvalds return err; 346087af38daSDaniel Jacobowitz 346187af38daSDaniel Jacobowitz /* There is already a misnamed master switch. Rename it. */ 346287af38daSDaniel Jacobowitz kctl = snd_ac97_find_mixer_ctl(ac97, "Master Playback Volume"); 346387af38daSDaniel Jacobowitz if (!kctl) 346487af38daSDaniel Jacobowitz return -EINVAL; 346587af38daSDaniel Jacobowitz 346687af38daSDaniel Jacobowitz snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Front Playback"); 346787af38daSDaniel Jacobowitz 346887af38daSDaniel Jacobowitz err = snd_ac97_add_vmaster(ac97, "Master Playback Volume", 346987af38daSDaniel Jacobowitz kctl->tlv.p, slave_vols_vt1616); 347087af38daSDaniel Jacobowitz if (err < 0) 347187af38daSDaniel Jacobowitz return err; 347287af38daSDaniel Jacobowitz 347387af38daSDaniel Jacobowitz err = snd_ac97_add_vmaster(ac97, "Master Playback Switch", 347487af38daSDaniel Jacobowitz NULL, slave_sws_vt1616); 347587af38daSDaniel Jacobowitz if (err < 0) 347687af38daSDaniel Jacobowitz return err; 347787af38daSDaniel Jacobowitz 34781da177e4SLinus Torvalds return 0; 34791da177e4SLinus Torvalds } 34801da177e4SLinus Torvalds 34813e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_vt1616_ops = { 34821da177e4SLinus Torvalds .build_specific = patch_vt1616_specific 34831da177e4SLinus Torvalds }; 34841da177e4SLinus Torvalds 3485ac519028STakashi Iwai static int patch_vt1616(struct snd_ac97 * ac97) 34861da177e4SLinus Torvalds { 34871da177e4SLinus Torvalds ac97->build_ops = &patch_vt1616_ops; 34881da177e4SLinus Torvalds return 0; 34891da177e4SLinus Torvalds } 34901da177e4SLinus Torvalds 3491eb8caf30STakashi Iwai /* 34924b499486SPhilip Prindeville * VT1617A codec 34934b499486SPhilip Prindeville */ 3494e9024cccSJohn Utz 3495e9024cccSJohn Utz /* 3496e9024cccSJohn Utz * unfortunately, the vt1617a stashes the twiddlers required for 34979e285e1aSJohn L. Utz III * noodling the i/o jacks on 2 different regs. that means that we can't 3498e9024cccSJohn Utz * use the easy way provided by AC97_ENUM_DOUBLE() we have to write 3499e9024cccSJohn Utz * are own funcs. 3500e9024cccSJohn Utz * 3501e9024cccSJohn Utz * NB: this is absolutely and utterly different from the vt1618. dunno 3502e9024cccSJohn Utz * about the 1616. 3503e9024cccSJohn Utz */ 3504e9024cccSJohn Utz 3505e9024cccSJohn Utz /* copied from ac97_surround_jack_mode_info() */ 3506e9024cccSJohn Utz static int snd_ac97_vt1617a_smart51_info(struct snd_kcontrol *kcontrol, 3507e9024cccSJohn Utz struct snd_ctl_elem_info *uinfo) 35084b499486SPhilip Prindeville { 3509e9024cccSJohn Utz /* ordering in this list reflects vt1617a docs for Reg 20 and 3510e9024cccSJohn Utz * 7a and Table 6 that lays out the matrix NB WRT Table6: SM51 3511e9024cccSJohn Utz * is SM51EN *AND* it's Bit14, not Bit15 so the table is very 3512e9024cccSJohn Utz * counter-intuitive */ 3513e9024cccSJohn Utz 35143b7a00dcSTakashi Iwai static const char * const texts[] = {"LineIn Mic1", "LineIn Mic1 Mic3", 3515e9024cccSJohn Utz "Surr LFE/C Mic3", "LineIn LFE/C Mic3", 3516e9024cccSJohn Utz "LineIn Mic2", "LineIn Mic2 Mic1", 3517e9024cccSJohn Utz "Surr LFE Mic1", "Surr LFE Mic1 Mic2"}; 35183b7a00dcSTakashi Iwai 35193b7a00dcSTakashi Iwai return snd_ctl_enum_info(uinfo, 1, 8, texts); 3520e9024cccSJohn Utz } 3521e9024cccSJohn Utz 3522e9024cccSJohn Utz static int snd_ac97_vt1617a_smart51_get(struct snd_kcontrol *kcontrol, 3523e9024cccSJohn Utz struct snd_ctl_elem_value *ucontrol) 3524e9024cccSJohn Utz { 3525e9024cccSJohn Utz ushort usSM51, usMS; 3526e9024cccSJohn Utz 3527e9024cccSJohn Utz struct snd_ac97 *pac97; 3528e9024cccSJohn Utz 3529e9024cccSJohn Utz pac97 = snd_kcontrol_chip(kcontrol); /* grab codec handle */ 3530e9024cccSJohn Utz 35319e285e1aSJohn L. Utz III /* grab our desired bits, then mash them together in a manner 3532e9024cccSJohn Utz * consistent with Table 6 on page 17 in the 1617a docs */ 3533e9024cccSJohn Utz 3534e9024cccSJohn Utz usSM51 = snd_ac97_read(pac97, 0x7a) >> 14; 3535e9024cccSJohn Utz usMS = snd_ac97_read(pac97, 0x20) >> 8; 3536e9024cccSJohn Utz 3537e9024cccSJohn Utz ucontrol->value.enumerated.item[0] = (usSM51 << 1) + usMS; 3538e9024cccSJohn Utz 3539e9024cccSJohn Utz return 0; 3540e9024cccSJohn Utz } 3541e9024cccSJohn Utz 3542e9024cccSJohn Utz static int snd_ac97_vt1617a_smart51_put(struct snd_kcontrol *kcontrol, 3543e9024cccSJohn Utz struct snd_ctl_elem_value *ucontrol) 3544e9024cccSJohn Utz { 3545e9024cccSJohn Utz ushort usSM51, usMS, usReg; 3546e9024cccSJohn Utz 3547e9024cccSJohn Utz struct snd_ac97 *pac97; 3548e9024cccSJohn Utz 3549e9024cccSJohn Utz pac97 = snd_kcontrol_chip(kcontrol); /* grab codec handle */ 3550e9024cccSJohn Utz 3551e9024cccSJohn Utz usSM51 = ucontrol->value.enumerated.item[0] >> 1; 3552e9024cccSJohn Utz usMS = ucontrol->value.enumerated.item[0] & 1; 3553e9024cccSJohn Utz 3554e9024cccSJohn Utz /* push our values into the register - consider that things will be left 3555e9024cccSJohn Utz * in a funky state if the write fails */ 3556e9024cccSJohn Utz 3557e9024cccSJohn Utz usReg = snd_ac97_read(pac97, 0x7a); 3558e9024cccSJohn Utz snd_ac97_write_cache(pac97, 0x7a, (usReg & 0x3FFF) + (usSM51 << 14)); 3559e9024cccSJohn Utz usReg = snd_ac97_read(pac97, 0x20); 3560e9024cccSJohn Utz snd_ac97_write_cache(pac97, 0x20, (usReg & 0xFEFF) + (usMS << 8)); 3561e9024cccSJohn Utz 3562e9024cccSJohn Utz return 0; 3563e9024cccSJohn Utz } 3564e9024cccSJohn Utz 3565e9024cccSJohn Utz static const struct snd_kcontrol_new snd_ac97_controls_vt1617a[] = { 3566e9024cccSJohn Utz 3567e9024cccSJohn Utz AC97_SINGLE("Center/LFE Exchange", 0x5a, 8, 1, 0), 3568e9024cccSJohn Utz /* 3569e9024cccSJohn Utz * These are used to enable/disable surround sound on motherboards 3570e9024cccSJohn Utz * that have 3 bidirectional analog jacks 3571e9024cccSJohn Utz */ 3572e9024cccSJohn Utz { 3573e9024cccSJohn Utz .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 3574e9024cccSJohn Utz .name = "Smart 5.1 Select", 3575e9024cccSJohn Utz .info = snd_ac97_vt1617a_smart51_info, 3576e9024cccSJohn Utz .get = snd_ac97_vt1617a_smart51_get, 3577e9024cccSJohn Utz .put = snd_ac97_vt1617a_smart51_put, 3578e9024cccSJohn Utz }, 3579e9024cccSJohn Utz }; 3580e9024cccSJohn Utz 3581b03671a8SHarvey Harrison static int patch_vt1617a(struct snd_ac97 * ac97) 3582e9024cccSJohn Utz { 3583e9024cccSJohn Utz int err = 0; 35842e75d050STakashi Iwai int val; 3585e9024cccSJohn Utz 3586e9024cccSJohn Utz /* we choose to not fail out at this point, but we tell the 3587e9024cccSJohn Utz caller when we return */ 3588e9024cccSJohn Utz 3589e9024cccSJohn Utz err = patch_build_controls(ac97, &snd_ac97_controls_vt1617a[0], 3590e9024cccSJohn Utz ARRAY_SIZE(snd_ac97_controls_vt1617a)); 3591e9024cccSJohn Utz 3592e9024cccSJohn Utz /* bring analog power consumption to normal by turning off the 3593e9024cccSJohn Utz * headphone amplifier, like WinXP driver for EPIA SP 35949f458e7fSAndrey Liakhovets */ 35952e75d050STakashi Iwai /* We need to check the bit before writing it. 35962e75d050STakashi Iwai * On some (many?) hardwares, setting bit actually clears it! 35972e75d050STakashi Iwai */ 35982e75d050STakashi Iwai val = snd_ac97_read(ac97, 0x5c); 35992e75d050STakashi Iwai if (!(val & 0x20)) 36009f458e7fSAndrey Liakhovets snd_ac97_write_cache(ac97, 0x5c, 0x20); 36012e75d050STakashi Iwai 36024b499486SPhilip Prindeville ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */ 36034b499486SPhilip Prindeville ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000; 36049f428175SDaniel Jacobowitz ac97->build_ops = &patch_vt1616_ops; 3605e9024cccSJohn Utz 3606e9024cccSJohn Utz return err; 36074b499486SPhilip Prindeville } 36084b499486SPhilip Prindeville 36099e285e1aSJohn L. Utz III /* VIA VT1618 8 CHANNEL AC97 CODEC 36109e285e1aSJohn L. Utz III * 36119e285e1aSJohn L. Utz III * VIA implements 'Smart 5.1' completely differently on the 1618 than 36129e285e1aSJohn L. Utz III * it does on the 1617a. awesome! They seem to have sourced this 36139e285e1aSJohn L. Utz III * particular revision of the technology from somebody else, it's 36149e285e1aSJohn L. Utz III * called Universal Audio Jack and it shows up on some other folk's chips 36159e285e1aSJohn L. Utz III * as well. 36169e285e1aSJohn L. Utz III * 36179e285e1aSJohn L. Utz III * ordering in this list reflects vt1618 docs for Reg 60h and 36189e285e1aSJohn L. Utz III * the block diagram, DACs are as follows: 36199e285e1aSJohn L. Utz III * 36209e285e1aSJohn L. Utz III * OUT_O -> Front, 36219e285e1aSJohn L. Utz III * OUT_1 -> Surround, 36229e285e1aSJohn L. Utz III * OUT_2 -> C/LFE 36239e285e1aSJohn L. Utz III * 36249e285e1aSJohn L. Utz III * Unlike the 1617a, each OUT has a consistent set of mappings 36259e285e1aSJohn L. Utz III * for all bitpatterns other than 00: 36269e285e1aSJohn L. Utz III * 36279e285e1aSJohn L. Utz III * 01 Unmixed Output 36289e285e1aSJohn L. Utz III * 10 Line In 36299e285e1aSJohn L. Utz III * 11 Mic In 36309e285e1aSJohn L. Utz III * 36319e285e1aSJohn L. Utz III * Special Case of 00: 36329e285e1aSJohn L. Utz III * 36339e285e1aSJohn L. Utz III * OUT_0 Mixed Output 36349e285e1aSJohn L. Utz III * OUT_1 Reserved 36359e285e1aSJohn L. Utz III * OUT_2 Reserved 36369e285e1aSJohn L. Utz III * 36379e285e1aSJohn L. Utz III * I have no idea what the hell Reserved does, but on an MSI 36389e285e1aSJohn L. Utz III * CN700T, i have to set it to get 5.1 output - YMMV, bad 36399e285e1aSJohn L. Utz III * shit may happen. 36409e285e1aSJohn L. Utz III * 36419e285e1aSJohn L. Utz III * If other chips use Universal Audio Jack, then this code might be applicable 36429e285e1aSJohn L. Utz III * to them. 36439e285e1aSJohn L. Utz III */ 36449e285e1aSJohn L. Utz III 36459e285e1aSJohn L. Utz III struct vt1618_uaj_item { 36469e285e1aSJohn L. Utz III unsigned short mask; 36479e285e1aSJohn L. Utz III unsigned short shift; 36481bc10bb6STakashi Iwai const char * const items[4]; 36499e285e1aSJohn L. Utz III }; 36509e285e1aSJohn L. Utz III 36519e285e1aSJohn L. Utz III /* This list reflects the vt1618 docs for Vendor Defined Register 0x60. */ 36529e285e1aSJohn L. Utz III 36539e285e1aSJohn L. Utz III static struct vt1618_uaj_item vt1618_uaj[3] = { 36549e285e1aSJohn L. Utz III { 36559e285e1aSJohn L. Utz III /* speaker jack */ 36569e285e1aSJohn L. Utz III .mask = 0x03, 36579e285e1aSJohn L. Utz III .shift = 0, 36589e285e1aSJohn L. Utz III .items = { 36599e285e1aSJohn L. Utz III "Speaker Out", "DAC Unmixed Out", "Line In", "Mic In" 36609e285e1aSJohn L. Utz III } 36619e285e1aSJohn L. Utz III }, 36629e285e1aSJohn L. Utz III { 36639e285e1aSJohn L. Utz III /* line jack */ 36649e285e1aSJohn L. Utz III .mask = 0x0c, 36659e285e1aSJohn L. Utz III .shift = 2, 36669e285e1aSJohn L. Utz III .items = { 36679e285e1aSJohn L. Utz III "Surround Out", "DAC Unmixed Out", "Line In", "Mic In" 36689e285e1aSJohn L. Utz III } 36699e285e1aSJohn L. Utz III }, 36709e285e1aSJohn L. Utz III { 36719e285e1aSJohn L. Utz III /* mic jack */ 36729e285e1aSJohn L. Utz III .mask = 0x30, 36739e285e1aSJohn L. Utz III .shift = 4, 36749e285e1aSJohn L. Utz III .items = { 36759e285e1aSJohn L. Utz III "Center LFE Out", "DAC Unmixed Out", "Line In", "Mic In" 36769e285e1aSJohn L. Utz III }, 36779e285e1aSJohn L. Utz III }, 36789e285e1aSJohn L. Utz III }; 36799e285e1aSJohn L. Utz III 36809e285e1aSJohn L. Utz III static int snd_ac97_vt1618_UAJ_info(struct snd_kcontrol *kcontrol, 36819e285e1aSJohn L. Utz III struct snd_ctl_elem_info *uinfo) 36829e285e1aSJohn L. Utz III { 36833b7a00dcSTakashi Iwai return snd_ctl_enum_info(uinfo, 1, 4, 36843b7a00dcSTakashi Iwai vt1618_uaj[kcontrol->private_value].items); 36859e285e1aSJohn L. Utz III } 36869e285e1aSJohn L. Utz III 36879e285e1aSJohn L. Utz III /* All of the vt1618 Universal Audio Jack twiddlers are on 36889e285e1aSJohn L. Utz III * Vendor Defined Register 0x60, page 0. The bits, and thus 36899e285e1aSJohn L. Utz III * the mask, are the only thing that changes 36909e285e1aSJohn L. Utz III */ 36919e285e1aSJohn L. Utz III static int snd_ac97_vt1618_UAJ_get(struct snd_kcontrol *kcontrol, 36929e285e1aSJohn L. Utz III struct snd_ctl_elem_value *ucontrol) 36939e285e1aSJohn L. Utz III { 36949e285e1aSJohn L. Utz III unsigned short datpag, uaj; 36959e285e1aSJohn L. Utz III struct snd_ac97 *pac97 = snd_kcontrol_chip(kcontrol); 36969e285e1aSJohn L. Utz III 36979e285e1aSJohn L. Utz III mutex_lock(&pac97->page_mutex); 36989e285e1aSJohn L. Utz III 36999e285e1aSJohn L. Utz III datpag = snd_ac97_read(pac97, AC97_INT_PAGING) & AC97_PAGE_MASK; 37009e285e1aSJohn L. Utz III snd_ac97_update_bits(pac97, AC97_INT_PAGING, AC97_PAGE_MASK, 0); 37019e285e1aSJohn L. Utz III 37029e285e1aSJohn L. Utz III uaj = snd_ac97_read(pac97, 0x60) & 37039e285e1aSJohn L. Utz III vt1618_uaj[kcontrol->private_value].mask; 37049e285e1aSJohn L. Utz III 37059e285e1aSJohn L. Utz III snd_ac97_update_bits(pac97, AC97_INT_PAGING, AC97_PAGE_MASK, datpag); 37069e285e1aSJohn L. Utz III mutex_unlock(&pac97->page_mutex); 37079e285e1aSJohn L. Utz III 37089e285e1aSJohn L. Utz III ucontrol->value.enumerated.item[0] = uaj >> 37099e285e1aSJohn L. Utz III vt1618_uaj[kcontrol->private_value].shift; 37109e285e1aSJohn L. Utz III 37119e285e1aSJohn L. Utz III return 0; 37129e285e1aSJohn L. Utz III } 37139e285e1aSJohn L. Utz III 37149e285e1aSJohn L. Utz III static int snd_ac97_vt1618_UAJ_put(struct snd_kcontrol *kcontrol, 37159e285e1aSJohn L. Utz III struct snd_ctl_elem_value *ucontrol) 37169e285e1aSJohn L. Utz III { 37179e285e1aSJohn L. Utz III return ac97_update_bits_page(snd_kcontrol_chip(kcontrol), 0x60, 37189e285e1aSJohn L. Utz III vt1618_uaj[kcontrol->private_value].mask, 37199e285e1aSJohn L. Utz III ucontrol->value.enumerated.item[0]<< 37209e285e1aSJohn L. Utz III vt1618_uaj[kcontrol->private_value].shift, 37219e285e1aSJohn L. Utz III 0); 37229e285e1aSJohn L. Utz III } 37239e285e1aSJohn L. Utz III 37249e285e1aSJohn L. Utz III /* config aux in jack - not found on 3 jack motherboards or soundcards */ 37259e285e1aSJohn L. Utz III 37269e285e1aSJohn L. Utz III static int snd_ac97_vt1618_aux_info(struct snd_kcontrol *kcontrol, 37279e285e1aSJohn L. Utz III struct snd_ctl_elem_info *uinfo) 37289e285e1aSJohn L. Utz III { 37293b7a00dcSTakashi Iwai static const char * const txt_aux[] = {"Aux In", "Back Surr Out"}; 37309e285e1aSJohn L. Utz III 37313b7a00dcSTakashi Iwai return snd_ctl_enum_info(uinfo, 1, 2, txt_aux); 37329e285e1aSJohn L. Utz III } 37339e285e1aSJohn L. Utz III 37349e285e1aSJohn L. Utz III static int snd_ac97_vt1618_aux_get(struct snd_kcontrol *kcontrol, 37359e285e1aSJohn L. Utz III struct snd_ctl_elem_value *ucontrol) 37369e285e1aSJohn L. Utz III { 37379e285e1aSJohn L. Utz III ucontrol->value.enumerated.item[0] = 37389e285e1aSJohn L. Utz III (snd_ac97_read(snd_kcontrol_chip(kcontrol), 0x5c) & 0x0008)>>3; 37399e285e1aSJohn L. Utz III return 0; 37409e285e1aSJohn L. Utz III } 37419e285e1aSJohn L. Utz III 37429e285e1aSJohn L. Utz III static int snd_ac97_vt1618_aux_put(struct snd_kcontrol *kcontrol, 37439e285e1aSJohn L. Utz III struct snd_ctl_elem_value *ucontrol) 37449e285e1aSJohn L. Utz III { 37459e285e1aSJohn L. Utz III /* toggle surround rear dac power */ 37469e285e1aSJohn L. Utz III 37479e285e1aSJohn L. Utz III snd_ac97_update_bits(snd_kcontrol_chip(kcontrol), 0x5c, 0x0008, 37489e285e1aSJohn L. Utz III ucontrol->value.enumerated.item[0] << 3); 37499e285e1aSJohn L. Utz III 37509e285e1aSJohn L. Utz III /* toggle aux in surround rear out jack */ 37519e285e1aSJohn L. Utz III 37529e285e1aSJohn L. Utz III return snd_ac97_update_bits(snd_kcontrol_chip(kcontrol), 0x76, 0x0008, 37539e285e1aSJohn L. Utz III ucontrol->value.enumerated.item[0] << 3); 37549e285e1aSJohn L. Utz III } 37559e285e1aSJohn L. Utz III 37569e285e1aSJohn L. Utz III static const struct snd_kcontrol_new snd_ac97_controls_vt1618[] = { 37579e285e1aSJohn L. Utz III AC97_SINGLE("Exchange Center/LFE", 0x5a, 8, 1, 0), 37589e285e1aSJohn L. Utz III AC97_SINGLE("DC Offset", 0x5a, 10, 1, 0), 37599e285e1aSJohn L. Utz III AC97_SINGLE("Soft Mute", 0x5c, 0, 1, 1), 37609e285e1aSJohn L. Utz III AC97_SINGLE("Headphone Amp", 0x5c, 5, 1, 1), 37619e285e1aSJohn L. Utz III AC97_DOUBLE("Back Surr Volume", 0x5e, 8, 0, 31, 1), 37629e285e1aSJohn L. Utz III AC97_SINGLE("Back Surr Switch", 0x5e, 15, 1, 1), 37639e285e1aSJohn L. Utz III { 37649e285e1aSJohn L. Utz III .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 37659e285e1aSJohn L. Utz III .name = "Speaker Jack Mode", 37669e285e1aSJohn L. Utz III .info = snd_ac97_vt1618_UAJ_info, 37679e285e1aSJohn L. Utz III .get = snd_ac97_vt1618_UAJ_get, 37689e285e1aSJohn L. Utz III .put = snd_ac97_vt1618_UAJ_put, 37699e285e1aSJohn L. Utz III .private_value = 0 37709e285e1aSJohn L. Utz III }, 37719e285e1aSJohn L. Utz III { 37729e285e1aSJohn L. Utz III .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 37739e285e1aSJohn L. Utz III .name = "Line Jack Mode", 37749e285e1aSJohn L. Utz III .info = snd_ac97_vt1618_UAJ_info, 37759e285e1aSJohn L. Utz III .get = snd_ac97_vt1618_UAJ_get, 37769e285e1aSJohn L. Utz III .put = snd_ac97_vt1618_UAJ_put, 37779e285e1aSJohn L. Utz III .private_value = 1 37789e285e1aSJohn L. Utz III }, 37799e285e1aSJohn L. Utz III { 37809e285e1aSJohn L. Utz III .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 37819e285e1aSJohn L. Utz III .name = "Mic Jack Mode", 37829e285e1aSJohn L. Utz III .info = snd_ac97_vt1618_UAJ_info, 37839e285e1aSJohn L. Utz III .get = snd_ac97_vt1618_UAJ_get, 37849e285e1aSJohn L. Utz III .put = snd_ac97_vt1618_UAJ_put, 37859e285e1aSJohn L. Utz III .private_value = 2 37869e285e1aSJohn L. Utz III }, 37879e285e1aSJohn L. Utz III { 37889e285e1aSJohn L. Utz III .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 37899e285e1aSJohn L. Utz III .name = "Aux Jack Mode", 37909e285e1aSJohn L. Utz III .info = snd_ac97_vt1618_aux_info, 37919e285e1aSJohn L. Utz III .get = snd_ac97_vt1618_aux_get, 37929e285e1aSJohn L. Utz III .put = snd_ac97_vt1618_aux_put, 37939e285e1aSJohn L. Utz III } 37949e285e1aSJohn L. Utz III }; 37959e285e1aSJohn L. Utz III 3796b03671a8SHarvey Harrison static int patch_vt1618(struct snd_ac97 *ac97) 37979e285e1aSJohn L. Utz III { 37989e285e1aSJohn L. Utz III return patch_build_controls(ac97, snd_ac97_controls_vt1618, 37999e285e1aSJohn L. Utz III ARRAY_SIZE(snd_ac97_controls_vt1618)); 38009e285e1aSJohn L. Utz III } 38019e285e1aSJohn L. Utz III 38024b499486SPhilip Prindeville /* 3803eb8caf30STakashi Iwai */ 3804ee42381eSTakashi Iwai static void it2646_update_jacks(struct snd_ac97 *ac97) 3805eb8caf30STakashi Iwai { 3806831466f4SRandy Cushman /* shared Line-In / Surround Out */ 3807eb8caf30STakashi Iwai snd_ac97_update_bits(ac97, 0x76, 1 << 9, 3808831466f4SRandy Cushman is_shared_surrout(ac97) ? (1<<9) : 0); 3809831466f4SRandy Cushman /* shared Mic / Center/LFE Out */ 3810eb8caf30STakashi Iwai snd_ac97_update_bits(ac97, 0x76, 1 << 10, 3811831466f4SRandy Cushman is_shared_clfeout(ac97) ? (1<<10) : 0); 3812eb8caf30STakashi Iwai } 3813eb8caf30STakashi Iwai 3814ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_it2646[] = { 3815eb8caf30STakashi Iwai AC97_SURROUND_JACK_MODE_CTL, 3816eb8caf30STakashi Iwai AC97_CHANNEL_MODE_CTL, 38171da177e4SLinus Torvalds }; 38181da177e4SLinus Torvalds 3819ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_spdif_controls_it2646[] = { 382010e8d78aSClemens Ladisch AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 0x76, 11, 1, 0), 38211da177e4SLinus Torvalds AC97_SINGLE("Analog to IEC958 Output", 0x76, 12, 1, 0), 38221da177e4SLinus Torvalds AC97_SINGLE("IEC958 Input Monitor", 0x76, 13, 1, 0), 38231da177e4SLinus Torvalds }; 38241da177e4SLinus Torvalds 3825ee42381eSTakashi Iwai static int patch_it2646_specific(struct snd_ac97 * ac97) 38261da177e4SLinus Torvalds { 38271da177e4SLinus Torvalds int err; 38281da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, snd_ac97_controls_it2646, ARRAY_SIZE(snd_ac97_controls_it2646))) < 0) 38291da177e4SLinus Torvalds return err; 38301da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_it2646, ARRAY_SIZE(snd_ac97_spdif_controls_it2646))) < 0) 38311da177e4SLinus Torvalds return err; 38321da177e4SLinus Torvalds return 0; 38331da177e4SLinus Torvalds } 38341da177e4SLinus Torvalds 38353e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_it2646_ops = { 3836eb8caf30STakashi Iwai .build_specific = patch_it2646_specific, 3837eb8caf30STakashi Iwai .update_jacks = it2646_update_jacks 38381da177e4SLinus Torvalds }; 38391da177e4SLinus Torvalds 3840ac519028STakashi Iwai static int patch_it2646(struct snd_ac97 * ac97) 38411da177e4SLinus Torvalds { 38421da177e4SLinus Torvalds ac97->build_ops = &patch_it2646_ops; 38431da177e4SLinus Torvalds /* full DAC volume */ 38441da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x5E, 0x0808); 38451da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x7A, 0x0808); 38461da177e4SLinus Torvalds return 0; 38471da177e4SLinus Torvalds } 38481da177e4SLinus Torvalds 384987d61c29SSasha Khapyorsky /* 385087d61c29SSasha Khapyorsky * Si3036 codec 385187d61c29SSasha Khapyorsky */ 385287d61c29SSasha Khapyorsky 38531da177e4SLinus Torvalds #define AC97_SI3036_CHIP_ID 0x5a 385487d61c29SSasha Khapyorsky #define AC97_SI3036_LINE_CFG 0x5c 385587d61c29SSasha Khapyorsky 3856ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_si3036[] = { 385787d61c29SSasha Khapyorsky AC97_DOUBLE("Modem Speaker Volume", 0x5c, 14, 12, 3, 1) 385887d61c29SSasha Khapyorsky }; 385987d61c29SSasha Khapyorsky 3860ee42381eSTakashi Iwai static int patch_si3036_specific(struct snd_ac97 * ac97) 386187d61c29SSasha Khapyorsky { 386227bcaa69SSasha Khapyorsky int idx, err; 386327bcaa69SSasha Khapyorsky for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_si3036); idx++) 386427bcaa69SSasha Khapyorsky if ((err = snd_ctl_add(ac97->bus->card, snd_ctl_new1(&snd_ac97_controls_si3036[idx], ac97))) < 0) 386527bcaa69SSasha Khapyorsky return err; 386627bcaa69SSasha Khapyorsky return 0; 386787d61c29SSasha Khapyorsky } 386887d61c29SSasha Khapyorsky 38693e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_si3036_ops = { 387087d61c29SSasha Khapyorsky .build_specific = patch_si3036_specific, 387187d61c29SSasha Khapyorsky }; 38721da177e4SLinus Torvalds 3873ac519028STakashi Iwai static int mpatch_si3036(struct snd_ac97 * ac97) 38741da177e4SLinus Torvalds { 387587d61c29SSasha Khapyorsky ac97->build_ops = &patch_si3036_ops; 38761da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x5c, 0xf210 ); 38771da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x68, 0); 38781da177e4SLinus Torvalds return 0; 38791da177e4SLinus Torvalds } 3880ba22429dSCharl Coetzee 3881ba22429dSCharl Coetzee /* 3882ba22429dSCharl Coetzee * LM 4550 Codec 3883ba22429dSCharl Coetzee * 3884ba22429dSCharl Coetzee * We use a static resolution table since LM4550 codec cannot be 3885ba22429dSCharl Coetzee * properly autoprobed to determine the resolution via 3886ba22429dSCharl Coetzee * check_volume_resolution(). 3887ba22429dSCharl Coetzee */ 3888ba22429dSCharl Coetzee 3889ba22429dSCharl Coetzee static struct snd_ac97_res_table lm4550_restbl[] = { 3890ba22429dSCharl Coetzee { AC97_MASTER, 0x1f1f }, 3891ba22429dSCharl Coetzee { AC97_HEADPHONE, 0x1f1f }, 3892ba22429dSCharl Coetzee { AC97_MASTER_MONO, 0x001f }, 3893ba22429dSCharl Coetzee { AC97_PC_BEEP, 0x001f }, /* LSB is ignored */ 3894ba22429dSCharl Coetzee { AC97_PHONE, 0x001f }, 3895ba22429dSCharl Coetzee { AC97_MIC, 0x001f }, 3896ba22429dSCharl Coetzee { AC97_LINE, 0x1f1f }, 3897ba22429dSCharl Coetzee { AC97_CD, 0x1f1f }, 3898ba22429dSCharl Coetzee { AC97_VIDEO, 0x1f1f }, 3899ba22429dSCharl Coetzee { AC97_AUX, 0x1f1f }, 3900ba22429dSCharl Coetzee { AC97_PCM, 0x1f1f }, 3901ba22429dSCharl Coetzee { AC97_REC_GAIN, 0x0f0f }, 3902ba22429dSCharl Coetzee { } /* terminator */ 3903ba22429dSCharl Coetzee }; 3904ba22429dSCharl Coetzee 3905ac519028STakashi Iwai static int patch_lm4550(struct snd_ac97 *ac97) 3906ba22429dSCharl Coetzee { 3907ba22429dSCharl Coetzee ac97->res_table = lm4550_restbl; 3908ba22429dSCharl Coetzee return 0; 3909ba22429dSCharl Coetzee } 391082466ad7SMike Rapoport 391182466ad7SMike Rapoport /* 391282466ad7SMike Rapoport * UCB1400 codec (http://www.semiconductors.philips.com/acrobat_download/datasheets/UCB1400-02.pdf) 391382466ad7SMike Rapoport */ 391482466ad7SMike Rapoport static const struct snd_kcontrol_new snd_ac97_controls_ucb1400[] = { 391582466ad7SMike Rapoport /* enable/disable headphone driver which allows direct connection to 391682466ad7SMike Rapoport stereo headphone without the use of external DC blocking 391782466ad7SMike Rapoport capacitors */ 391882466ad7SMike Rapoport AC97_SINGLE("Headphone Driver", 0x6a, 6, 1, 0), 391982466ad7SMike Rapoport /* Filter used to compensate the DC offset is added in the ADC to remove idle 392082466ad7SMike Rapoport tones from the audio band. */ 392182466ad7SMike Rapoport AC97_SINGLE("DC Filter", 0x6a, 4, 1, 0), 392282466ad7SMike Rapoport /* Control smart-low-power mode feature. Allows automatic power down 392382466ad7SMike Rapoport of unused blocks in the ADC analog front end and the PLL. */ 392482466ad7SMike Rapoport AC97_SINGLE("Smart Low Power Mode", 0x6c, 4, 3, 0), 392582466ad7SMike Rapoport }; 392682466ad7SMike Rapoport 392782466ad7SMike Rapoport static int patch_ucb1400_specific(struct snd_ac97 * ac97) 392882466ad7SMike Rapoport { 392982466ad7SMike Rapoport int idx, err; 393082466ad7SMike Rapoport for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_ucb1400); idx++) 393182466ad7SMike Rapoport if ((err = snd_ctl_add(ac97->bus->card, snd_ctl_new1(&snd_ac97_controls_ucb1400[idx], ac97))) < 0) 393282466ad7SMike Rapoport return err; 393382466ad7SMike Rapoport return 0; 393482466ad7SMike Rapoport } 393582466ad7SMike Rapoport 39363e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ucb1400_ops = { 393782466ad7SMike Rapoport .build_specific = patch_ucb1400_specific, 393882466ad7SMike Rapoport }; 393982466ad7SMike Rapoport 3940ac519028STakashi Iwai static int patch_ucb1400(struct snd_ac97 * ac97) 394182466ad7SMike Rapoport { 394282466ad7SMike Rapoport ac97->build_ops = &patch_ucb1400_ops; 394382466ad7SMike Rapoport /* enable headphone driver and smart low power mode by default */ 394425552e87SMike Rapoport snd_ac97_write_cache(ac97, 0x6a, 0x0050); 394525552e87SMike Rapoport snd_ac97_write_cache(ac97, 0x6c, 0x0030); 394682466ad7SMike Rapoport return 0; 394782466ad7SMike Rapoport } 3948