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 /* 301da177e4SLinus Torvalds * Chip specific initialization 311da177e4SLinus Torvalds */ 321da177e4SLinus Torvalds 33ee42381eSTakashi Iwai static int patch_build_controls(struct snd_ac97 * ac97, const struct snd_kcontrol_new *controls, int count) 341da177e4SLinus Torvalds { 351da177e4SLinus Torvalds int idx, err; 361da177e4SLinus Torvalds 371da177e4SLinus Torvalds for (idx = 0; idx < count; idx++) 381da177e4SLinus Torvalds if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&controls[idx], ac97))) < 0) 391da177e4SLinus Torvalds return err; 401da177e4SLinus Torvalds return 0; 411da177e4SLinus Torvalds } 421da177e4SLinus Torvalds 432f3482fbSTakashi Iwai /* replace with a new TLV */ 442f3482fbSTakashi Iwai static void reset_tlv(struct snd_ac97 *ac97, const char *name, 450cb29ea0STakashi Iwai const unsigned int *tlv) 462f3482fbSTakashi Iwai { 472f3482fbSTakashi Iwai struct snd_ctl_elem_id sid; 482f3482fbSTakashi Iwai struct snd_kcontrol *kctl; 492f3482fbSTakashi Iwai memset(&sid, 0, sizeof(sid)); 502f3482fbSTakashi Iwai strcpy(sid.name, name); 512f3482fbSTakashi Iwai sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 522f3482fbSTakashi Iwai kctl = snd_ctl_find_id(ac97->bus->card, &sid); 532f3482fbSTakashi Iwai if (kctl && kctl->tlv.p) 542f3482fbSTakashi Iwai kctl->tlv.p = tlv; 552f3482fbSTakashi Iwai } 562f3482fbSTakashi Iwai 571da177e4SLinus Torvalds /* set to the page, update bits and restore the page */ 58ee42381eSTakashi Iwai static int ac97_update_bits_page(struct snd_ac97 *ac97, unsigned short reg, unsigned short mask, unsigned short value, unsigned short page) 591da177e4SLinus Torvalds { 601da177e4SLinus Torvalds unsigned short page_save; 611da177e4SLinus Torvalds int ret; 621da177e4SLinus Torvalds 6362932df8SIngo Molnar mutex_lock(&ac97->page_mutex); 641da177e4SLinus Torvalds page_save = snd_ac97_read(ac97, AC97_INT_PAGING) & AC97_PAGE_MASK; 651da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page); 661da177e4SLinus Torvalds ret = snd_ac97_update_bits(ac97, reg, mask, value); 671da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page_save); 6862932df8SIngo Molnar mutex_unlock(&ac97->page_mutex); /* unlock paging */ 691da177e4SLinus Torvalds return ret; 701da177e4SLinus Torvalds } 711da177e4SLinus Torvalds 72eb8caf30STakashi Iwai /* 73eb8caf30STakashi Iwai * shared line-in/mic controls 74eb8caf30STakashi Iwai */ 75ee42381eSTakashi Iwai static int ac97_enum_text_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo, 76eb8caf30STakashi Iwai const char **texts, unsigned int nums) 77eb8caf30STakashi Iwai { 78eb8caf30STakashi Iwai uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 79eb8caf30STakashi Iwai uinfo->count = 1; 80eb8caf30STakashi Iwai uinfo->value.enumerated.items = nums; 81eb8caf30STakashi Iwai if (uinfo->value.enumerated.item > nums - 1) 82eb8caf30STakashi Iwai uinfo->value.enumerated.item = nums - 1; 83eb8caf30STakashi Iwai strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 84eb8caf30STakashi Iwai return 0; 85eb8caf30STakashi Iwai } 86eb8caf30STakashi Iwai 87ee42381eSTakashi Iwai static int ac97_surround_jack_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 88eb8caf30STakashi Iwai { 89eb8caf30STakashi Iwai static const char *texts[] = { "Shared", "Independent" }; 90eb8caf30STakashi Iwai return ac97_enum_text_info(kcontrol, uinfo, texts, 2); 91eb8caf30STakashi Iwai } 92eb8caf30STakashi Iwai 93ee42381eSTakashi Iwai static int ac97_surround_jack_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 94eb8caf30STakashi Iwai { 95ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 96eb8caf30STakashi Iwai 97eb8caf30STakashi Iwai ucontrol->value.enumerated.item[0] = ac97->indep_surround; 98eb8caf30STakashi Iwai return 0; 99eb8caf30STakashi Iwai } 100eb8caf30STakashi Iwai 101ee42381eSTakashi Iwai static int ac97_surround_jack_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 102eb8caf30STakashi Iwai { 103ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 104eb8caf30STakashi Iwai unsigned char indep = !!ucontrol->value.enumerated.item[0]; 105eb8caf30STakashi Iwai 106eb8caf30STakashi Iwai if (indep != ac97->indep_surround) { 107eb8caf30STakashi Iwai ac97->indep_surround = indep; 108eb8caf30STakashi Iwai if (ac97->build_ops->update_jacks) 109eb8caf30STakashi Iwai ac97->build_ops->update_jacks(ac97); 110eb8caf30STakashi Iwai return 1; 111eb8caf30STakashi Iwai } 112eb8caf30STakashi Iwai return 0; 113eb8caf30STakashi Iwai } 114eb8caf30STakashi Iwai 115ee42381eSTakashi Iwai static int ac97_channel_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 116eb8caf30STakashi Iwai { 1174235a317STakashi Iwai static const char *texts[] = { "2ch", "4ch", "6ch", "8ch" }; 1184235a317STakashi Iwai return ac97_enum_text_info(kcontrol, uinfo, texts, 1194235a317STakashi Iwai kcontrol->private_value); 120eb8caf30STakashi Iwai } 121eb8caf30STakashi Iwai 122ee42381eSTakashi Iwai static int ac97_channel_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 123eb8caf30STakashi Iwai { 124ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 125eb8caf30STakashi Iwai 126eb8caf30STakashi Iwai ucontrol->value.enumerated.item[0] = ac97->channel_mode; 127eb8caf30STakashi Iwai return 0; 128eb8caf30STakashi Iwai } 129eb8caf30STakashi Iwai 130ee42381eSTakashi Iwai static int ac97_channel_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 131eb8caf30STakashi Iwai { 132ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 133eb8caf30STakashi Iwai unsigned char mode = ucontrol->value.enumerated.item[0]; 134eb8caf30STakashi Iwai 1354235a317STakashi Iwai if (mode >= kcontrol->private_value) 1364e98d6a7STakashi Iwai return -EINVAL; 1374e98d6a7STakashi Iwai 138eb8caf30STakashi Iwai if (mode != ac97->channel_mode) { 139eb8caf30STakashi Iwai ac97->channel_mode = mode; 140eb8caf30STakashi Iwai if (ac97->build_ops->update_jacks) 141eb8caf30STakashi Iwai ac97->build_ops->update_jacks(ac97); 142eb8caf30STakashi Iwai return 1; 143eb8caf30STakashi Iwai } 144eb8caf30STakashi Iwai return 0; 145eb8caf30STakashi Iwai } 146eb8caf30STakashi Iwai 147eb8caf30STakashi Iwai #define AC97_SURROUND_JACK_MODE_CTL \ 148eb8caf30STakashi Iwai { \ 149eb8caf30STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 150eb8caf30STakashi Iwai .name = "Surround Jack Mode", \ 151eb8caf30STakashi Iwai .info = ac97_surround_jack_mode_info, \ 152eb8caf30STakashi Iwai .get = ac97_surround_jack_mode_get, \ 153eb8caf30STakashi Iwai .put = ac97_surround_jack_mode_put, \ 154eb8caf30STakashi Iwai } 1554235a317STakashi Iwai /* 6ch */ 156eb8caf30STakashi Iwai #define AC97_CHANNEL_MODE_CTL \ 157eb8caf30STakashi Iwai { \ 158eb8caf30STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 159eb8caf30STakashi Iwai .name = "Channel Mode", \ 160eb8caf30STakashi Iwai .info = ac97_channel_mode_info, \ 161eb8caf30STakashi Iwai .get = ac97_channel_mode_get, \ 162eb8caf30STakashi Iwai .put = ac97_channel_mode_put, \ 1634235a317STakashi Iwai .private_value = 3, \ 164eb8caf30STakashi Iwai } 1654235a317STakashi Iwai /* 4ch */ 166eb8caf30STakashi Iwai #define AC97_CHANNEL_MODE_4CH_CTL \ 167eb8caf30STakashi Iwai { \ 168eb8caf30STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 169eb8caf30STakashi Iwai .name = "Channel Mode", \ 170eb8caf30STakashi Iwai .info = ac97_channel_mode_info, \ 171eb8caf30STakashi Iwai .get = ac97_channel_mode_get, \ 172eb8caf30STakashi Iwai .put = ac97_channel_mode_put, \ 1734235a317STakashi Iwai .private_value = 2, \ 1744235a317STakashi Iwai } 1754235a317STakashi Iwai /* 8ch */ 1764235a317STakashi Iwai #define AC97_CHANNEL_MODE_8CH_CTL \ 1774235a317STakashi Iwai { \ 1784235a317STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 1794235a317STakashi Iwai .name = "Channel Mode", \ 1804235a317STakashi Iwai .info = ac97_channel_mode_info, \ 1814235a317STakashi Iwai .get = ac97_channel_mode_get, \ 1824235a317STakashi Iwai .put = ac97_channel_mode_put, \ 1834235a317STakashi Iwai .private_value = 4, \ 184eb8caf30STakashi Iwai } 185eb8caf30STakashi Iwai 186ee42381eSTakashi Iwai static inline int is_surround_on(struct snd_ac97 *ac97) 1874525c9f3STakashi Iwai { 1884525c9f3STakashi Iwai return ac97->channel_mode >= 1; 1894525c9f3STakashi Iwai } 1904525c9f3STakashi Iwai 191ee42381eSTakashi Iwai static inline int is_clfe_on(struct snd_ac97 *ac97) 1924525c9f3STakashi Iwai { 193eb9b4142STakashi Iwai return ac97->channel_mode >= 2; 1944525c9f3STakashi Iwai } 1954525c9f3STakashi Iwai 196831466f4SRandy Cushman /* system has shared jacks with surround out enabled */ 197831466f4SRandy Cushman static inline int is_shared_surrout(struct snd_ac97 *ac97) 198eb8caf30STakashi Iwai { 1994525c9f3STakashi Iwai return !ac97->indep_surround && is_surround_on(ac97); 200eb8caf30STakashi Iwai } 201eb8caf30STakashi Iwai 202831466f4SRandy Cushman /* system has shared jacks with center/lfe out enabled */ 203831466f4SRandy Cushman static inline int is_shared_clfeout(struct snd_ac97 *ac97) 204eb8caf30STakashi Iwai { 2054525c9f3STakashi Iwai return !ac97->indep_surround && is_clfe_on(ac97); 206eb8caf30STakashi Iwai } 207eb8caf30STakashi Iwai 208831466f4SRandy Cushman /* system has shared jacks with line in enabled */ 209831466f4SRandy Cushman static inline int is_shared_linein(struct snd_ac97 *ac97) 210831466f4SRandy Cushman { 211831466f4SRandy Cushman return !ac97->indep_surround && !is_surround_on(ac97); 212831466f4SRandy Cushman } 213831466f4SRandy Cushman 214831466f4SRandy Cushman /* system has shared jacks with mic in enabled */ 215831466f4SRandy Cushman static inline int is_shared_micin(struct snd_ac97 *ac97) 216831466f4SRandy Cushman { 217831466f4SRandy Cushman return !ac97->indep_surround && !is_clfe_on(ac97); 218831466f4SRandy Cushman } 219831466f4SRandy Cushman 2204235a317STakashi Iwai static inline int alc850_is_aux_back_surround(struct snd_ac97 *ac97) 2214235a317STakashi Iwai { 2224235a317STakashi Iwai return is_surround_on(ac97); 2234235a317STakashi Iwai } 224eb8caf30STakashi Iwai 2251da177e4SLinus Torvalds /* The following snd_ac97_ymf753_... items added by David Shust (dshust@shustring.com) */ 22643115f58SKeita Maehara /* Modified for YMF743 by Keita Maehara <maehara@debian.org> */ 2271da177e4SLinus Torvalds 22813043984SKeita Maehara /* It is possible to indicate to the Yamaha YMF7x3 the type of 22913043984SKeita Maehara speakers being used. */ 23013043984SKeita Maehara 23113043984SKeita Maehara static int snd_ac97_ymf7x3_info_speaker(struct snd_kcontrol *kcontrol, 23213043984SKeita Maehara struct snd_ctl_elem_info *uinfo) 2331da177e4SLinus Torvalds { 2341da177e4SLinus Torvalds static char *texts[3] = { 2351da177e4SLinus Torvalds "Standard", "Small", "Smaller" 2361da177e4SLinus Torvalds }; 2371da177e4SLinus Torvalds 2381da177e4SLinus Torvalds uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2391da177e4SLinus Torvalds uinfo->count = 1; 2401da177e4SLinus Torvalds uinfo->value.enumerated.items = 3; 2411da177e4SLinus Torvalds if (uinfo->value.enumerated.item > 2) 2421da177e4SLinus Torvalds uinfo->value.enumerated.item = 2; 2431da177e4SLinus Torvalds strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 2441da177e4SLinus Torvalds return 0; 2451da177e4SLinus Torvalds } 2461da177e4SLinus Torvalds 24713043984SKeita Maehara static int snd_ac97_ymf7x3_get_speaker(struct snd_kcontrol *kcontrol, 24813043984SKeita Maehara struct snd_ctl_elem_value *ucontrol) 2491da177e4SLinus Torvalds { 250ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 2511da177e4SLinus Torvalds unsigned short val; 2521da177e4SLinus Torvalds 25313043984SKeita Maehara val = ac97->regs[AC97_YMF7X3_3D_MODE_SEL]; 2541da177e4SLinus Torvalds val = (val >> 10) & 3; 2551da177e4SLinus Torvalds if (val > 0) /* 0 = invalid */ 2561da177e4SLinus Torvalds val--; 2571da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = val; 2581da177e4SLinus Torvalds return 0; 2591da177e4SLinus Torvalds } 2601da177e4SLinus Torvalds 26113043984SKeita Maehara static int snd_ac97_ymf7x3_put_speaker(struct snd_kcontrol *kcontrol, 26213043984SKeita Maehara struct snd_ctl_elem_value *ucontrol) 2631da177e4SLinus Torvalds { 264ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 2651da177e4SLinus Torvalds unsigned short val; 2661da177e4SLinus Torvalds 2671da177e4SLinus Torvalds if (ucontrol->value.enumerated.item[0] > 2) 2681da177e4SLinus Torvalds return -EINVAL; 2691da177e4SLinus Torvalds val = (ucontrol->value.enumerated.item[0] + 1) << 10; 27013043984SKeita Maehara return snd_ac97_update(ac97, AC97_YMF7X3_3D_MODE_SEL, val); 2711da177e4SLinus Torvalds } 2721da177e4SLinus Torvalds 27313043984SKeita Maehara static const struct snd_kcontrol_new snd_ac97_ymf7x3_controls_speaker = 2741da177e4SLinus Torvalds { 2751da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2761da177e4SLinus Torvalds .name = "3D Control - Speaker", 27713043984SKeita Maehara .info = snd_ac97_ymf7x3_info_speaker, 27813043984SKeita Maehara .get = snd_ac97_ymf7x3_get_speaker, 27913043984SKeita Maehara .put = snd_ac97_ymf7x3_put_speaker, 2801da177e4SLinus Torvalds }; 2811da177e4SLinus Torvalds 28213043984SKeita Maehara /* It is possible to indicate to the Yamaha YMF7x3 the source to 28313043984SKeita Maehara direct to the S/PDIF output. */ 28413043984SKeita Maehara static int snd_ac97_ymf7x3_spdif_source_info(struct snd_kcontrol *kcontrol, 28513043984SKeita Maehara struct snd_ctl_elem_info *uinfo) 2861da177e4SLinus Torvalds { 2871da177e4SLinus Torvalds static char *texts[2] = { "AC-Link", "A/D Converter" }; 2881da177e4SLinus Torvalds 2891da177e4SLinus Torvalds uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2901da177e4SLinus Torvalds uinfo->count = 1; 2911da177e4SLinus Torvalds uinfo->value.enumerated.items = 2; 2921da177e4SLinus Torvalds if (uinfo->value.enumerated.item > 1) 2931da177e4SLinus Torvalds uinfo->value.enumerated.item = 1; 2941da177e4SLinus Torvalds strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 2951da177e4SLinus Torvalds return 0; 2961da177e4SLinus Torvalds } 2971da177e4SLinus Torvalds 29813043984SKeita Maehara static int snd_ac97_ymf7x3_spdif_source_get(struct snd_kcontrol *kcontrol, 29913043984SKeita Maehara struct snd_ctl_elem_value *ucontrol) 3001da177e4SLinus Torvalds { 301ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 3021da177e4SLinus Torvalds unsigned short val; 3031da177e4SLinus Torvalds 30413043984SKeita Maehara val = ac97->regs[AC97_YMF7X3_DIT_CTRL]; 3051da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = (val >> 1) & 1; 3061da177e4SLinus Torvalds return 0; 3071da177e4SLinus Torvalds } 3081da177e4SLinus Torvalds 30913043984SKeita Maehara static int snd_ac97_ymf7x3_spdif_source_put(struct snd_kcontrol *kcontrol, 31013043984SKeita Maehara struct snd_ctl_elem_value *ucontrol) 3111da177e4SLinus Torvalds { 312ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 3131da177e4SLinus Torvalds unsigned short val; 3141da177e4SLinus Torvalds 3151da177e4SLinus Torvalds if (ucontrol->value.enumerated.item[0] > 1) 3161da177e4SLinus Torvalds return -EINVAL; 3171da177e4SLinus Torvalds val = ucontrol->value.enumerated.item[0] << 1; 31813043984SKeita Maehara return snd_ac97_update_bits(ac97, AC97_YMF7X3_DIT_CTRL, 0x0002, val); 3191da177e4SLinus Torvalds } 3201da177e4SLinus Torvalds 32143115f58SKeita Maehara static int patch_yamaha_ymf7x3_3d(struct snd_ac97 *ac97) 32243115f58SKeita Maehara { 32343115f58SKeita Maehara struct snd_kcontrol *kctl; 32443115f58SKeita Maehara int err; 32543115f58SKeita Maehara 32643115f58SKeita Maehara kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97); 32743115f58SKeita Maehara err = snd_ctl_add(ac97->bus->card, kctl); 32843115f58SKeita Maehara if (err < 0) 32943115f58SKeita Maehara return err; 33043115f58SKeita Maehara strcpy(kctl->id.name, "3D Control - Wide"); 33143115f58SKeita Maehara kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 9, 7, 0); 33243115f58SKeita Maehara snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000); 33343115f58SKeita Maehara err = snd_ctl_add(ac97->bus->card, 33443115f58SKeita Maehara snd_ac97_cnew(&snd_ac97_ymf7x3_controls_speaker, 33543115f58SKeita Maehara ac97)); 33643115f58SKeita Maehara if (err < 0) 33743115f58SKeita Maehara return err; 33843115f58SKeita Maehara snd_ac97_write_cache(ac97, AC97_YMF7X3_3D_MODE_SEL, 0x0c00); 33943115f58SKeita Maehara return 0; 34043115f58SKeita Maehara } 34143115f58SKeita Maehara 34243115f58SKeita Maehara static const struct snd_kcontrol_new snd_ac97_yamaha_ymf743_controls_spdif[3] = 34343115f58SKeita Maehara { 34443115f58SKeita Maehara AC97_SINGLE(SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH), 34543115f58SKeita Maehara AC97_YMF7X3_DIT_CTRL, 0, 1, 0), 34643115f58SKeita Maehara { 34743115f58SKeita Maehara .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 34843115f58SKeita Maehara .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, NONE) "Source", 34943115f58SKeita Maehara .info = snd_ac97_ymf7x3_spdif_source_info, 35043115f58SKeita Maehara .get = snd_ac97_ymf7x3_spdif_source_get, 35143115f58SKeita Maehara .put = snd_ac97_ymf7x3_spdif_source_put, 35243115f58SKeita Maehara }, 35343115f58SKeita Maehara AC97_SINGLE(SNDRV_CTL_NAME_IEC958("", NONE, NONE) "Mute", 35443115f58SKeita Maehara AC97_YMF7X3_DIT_CTRL, 2, 1, 1) 35543115f58SKeita Maehara }; 35643115f58SKeita Maehara 35743115f58SKeita Maehara static int patch_yamaha_ymf743_build_spdif(struct snd_ac97 *ac97) 35843115f58SKeita Maehara { 35943115f58SKeita Maehara int err; 36043115f58SKeita Maehara 36143115f58SKeita Maehara err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3); 36243115f58SKeita Maehara if (err < 0) 36343115f58SKeita Maehara return err; 36443115f58SKeita Maehara err = patch_build_controls(ac97, 36543115f58SKeita Maehara snd_ac97_yamaha_ymf743_controls_spdif, 3); 36643115f58SKeita Maehara if (err < 0) 36743115f58SKeita Maehara return err; 36843115f58SKeita Maehara /* set default PCM S/PDIF params */ 36943115f58SKeita Maehara /* PCM audio,no copyright,no preemphasis,PCM coder,original */ 37043115f58SKeita Maehara snd_ac97_write_cache(ac97, AC97_YMF7X3_DIT_CTRL, 0xa201); 37143115f58SKeita Maehara return 0; 37243115f58SKeita Maehara } 37343115f58SKeita Maehara 374*3e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_yamaha_ymf743_ops = { 37543115f58SKeita Maehara .build_spdif = patch_yamaha_ymf743_build_spdif, 37643115f58SKeita Maehara .build_3d = patch_yamaha_ymf7x3_3d, 37743115f58SKeita Maehara }; 37843115f58SKeita Maehara 37943115f58SKeita Maehara static int patch_yamaha_ymf743(struct snd_ac97 *ac97) 38043115f58SKeita Maehara { 38143115f58SKeita Maehara ac97->build_ops = &patch_yamaha_ymf743_ops; 38243115f58SKeita Maehara ac97->caps |= AC97_BC_BASS_TREBLE; 38343115f58SKeita Maehara ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */ 38443115f58SKeita Maehara ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */ 38543115f58SKeita Maehara ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */ 38643115f58SKeita Maehara return 0; 38743115f58SKeita Maehara } 38843115f58SKeita Maehara 3891da177e4SLinus Torvalds /* The AC'97 spec states that the S/PDIF signal is to be output at pin 48. 3901da177e4SLinus Torvalds The YMF753 will output the S/PDIF signal to pin 43, 47 (EAPD), or 48. 3911da177e4SLinus Torvalds By default, no output pin is selected, and the S/PDIF signal is not output. 3921da177e4SLinus Torvalds There is also a bit to mute S/PDIF output in a vendor-specific register. */ 393ee42381eSTakashi Iwai static int snd_ac97_ymf753_spdif_output_pin_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 3941da177e4SLinus Torvalds { 3951da177e4SLinus Torvalds static char *texts[3] = { "Disabled", "Pin 43", "Pin 48" }; 3961da177e4SLinus Torvalds 3971da177e4SLinus Torvalds uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 3981da177e4SLinus Torvalds uinfo->count = 1; 3991da177e4SLinus Torvalds uinfo->value.enumerated.items = 3; 4001da177e4SLinus Torvalds if (uinfo->value.enumerated.item > 2) 4011da177e4SLinus Torvalds uinfo->value.enumerated.item = 2; 4021da177e4SLinus Torvalds strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 4031da177e4SLinus Torvalds return 0; 4041da177e4SLinus Torvalds } 4051da177e4SLinus Torvalds 406ee42381eSTakashi Iwai static int snd_ac97_ymf753_spdif_output_pin_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 4071da177e4SLinus Torvalds { 408ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 4091da177e4SLinus Torvalds unsigned short val; 4101da177e4SLinus Torvalds 41113043984SKeita Maehara val = ac97->regs[AC97_YMF7X3_DIT_CTRL]; 4121da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = (val & 0x0008) ? 2 : (val & 0x0020) ? 1 : 0; 4131da177e4SLinus Torvalds return 0; 4141da177e4SLinus Torvalds } 4151da177e4SLinus Torvalds 416ee42381eSTakashi Iwai static int snd_ac97_ymf753_spdif_output_pin_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 4171da177e4SLinus Torvalds { 418ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 4191da177e4SLinus Torvalds unsigned short val; 4201da177e4SLinus Torvalds 4211da177e4SLinus Torvalds if (ucontrol->value.enumerated.item[0] > 2) 4221da177e4SLinus Torvalds return -EINVAL; 4231da177e4SLinus Torvalds val = (ucontrol->value.enumerated.item[0] == 2) ? 0x0008 : 4241da177e4SLinus Torvalds (ucontrol->value.enumerated.item[0] == 1) ? 0x0020 : 0; 42513043984SKeita Maehara return snd_ac97_update_bits(ac97, AC97_YMF7X3_DIT_CTRL, 0x0028, val); 4261da177e4SLinus Torvalds /* The following can be used to direct S/PDIF output to pin 47 (EAPD). 4271da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x62, snd_ac97_read(ac97, 0x62) | 0x0008); */ 4281da177e4SLinus Torvalds } 4291da177e4SLinus Torvalds 430ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ymf753_controls_spdif[3] = { 4311da177e4SLinus Torvalds { 4321da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 4331da177e4SLinus Torvalds .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source", 43413043984SKeita Maehara .info = snd_ac97_ymf7x3_spdif_source_info, 43513043984SKeita Maehara .get = snd_ac97_ymf7x3_spdif_source_get, 43613043984SKeita Maehara .put = snd_ac97_ymf7x3_spdif_source_put, 4371da177e4SLinus Torvalds }, 4381da177e4SLinus Torvalds { 4391da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 4401da177e4SLinus Torvalds .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Output Pin", 4411da177e4SLinus Torvalds .info = snd_ac97_ymf753_spdif_output_pin_info, 4421da177e4SLinus Torvalds .get = snd_ac97_ymf753_spdif_output_pin_get, 4431da177e4SLinus Torvalds .put = snd_ac97_ymf753_spdif_output_pin_put, 4441da177e4SLinus Torvalds }, 44513043984SKeita Maehara AC97_SINGLE(SNDRV_CTL_NAME_IEC958("", NONE, NONE) "Mute", 44613043984SKeita Maehara AC97_YMF7X3_DIT_CTRL, 2, 1, 1) 4471da177e4SLinus Torvalds }; 4481da177e4SLinus Torvalds 449ee42381eSTakashi Iwai static int patch_yamaha_ymf753_post_spdif(struct snd_ac97 * ac97) 4501da177e4SLinus Torvalds { 4511da177e4SLinus Torvalds int err; 4521da177e4SLinus Torvalds 4531da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, snd_ac97_ymf753_controls_spdif, ARRAY_SIZE(snd_ac97_ymf753_controls_spdif))) < 0) 4541da177e4SLinus Torvalds return err; 4551da177e4SLinus Torvalds return 0; 4561da177e4SLinus Torvalds } 4571da177e4SLinus Torvalds 458*3e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_yamaha_ymf753_ops = { 45913043984SKeita Maehara .build_3d = patch_yamaha_ymf7x3_3d, 4601da177e4SLinus Torvalds .build_post_spdif = patch_yamaha_ymf753_post_spdif 4611da177e4SLinus Torvalds }; 4621da177e4SLinus Torvalds 463ac519028STakashi Iwai static int patch_yamaha_ymf753(struct snd_ac97 * ac97) 4641da177e4SLinus Torvalds { 4651da177e4SLinus Torvalds /* Patch for Yamaha YMF753, Copyright (c) by David Shust, dshust@shustring.com. 4661da177e4SLinus Torvalds This chip has nonstandard and extended behaviour with regard to its S/PDIF output. 4671da177e4SLinus Torvalds The AC'97 spec states that the S/PDIF signal is to be output at pin 48. 4681da177e4SLinus Torvalds The YMF753 will ouput the S/PDIF signal to pin 43, 47 (EAPD), or 48. 4691da177e4SLinus Torvalds By default, no output pin is selected, and the S/PDIF signal is not output. 4701da177e4SLinus Torvalds There is also a bit to mute S/PDIF output in a vendor-specific register. 4711da177e4SLinus Torvalds */ 4721da177e4SLinus Torvalds ac97->build_ops = &patch_yamaha_ymf753_ops; 4731da177e4SLinus Torvalds ac97->caps |= AC97_BC_BASS_TREBLE; 4741da177e4SLinus Torvalds ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */ 4751da177e4SLinus Torvalds return 0; 4761da177e4SLinus Torvalds } 4771da177e4SLinus Torvalds 4781da177e4SLinus Torvalds /* 479d331124dSLiam Girdwood * May 2, 2003 Liam Girdwood <lrg@slimlogic.co.uk> 4801da177e4SLinus Torvalds * removed broken wolfson00 patch. 4811da177e4SLinus Torvalds * added support for WM9705,WM9708,WM9709,WM9710,WM9711,WM9712 and WM9717. 4821da177e4SLinus Torvalds */ 4831da177e4SLinus Torvalds 484ee42381eSTakashi Iwai static const struct snd_kcontrol_new wm97xx_snd_ac97_controls[] = { 4853998b70fSLiam Girdwood AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1), 4863998b70fSLiam Girdwood AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1), 4873998b70fSLiam Girdwood }; 4883998b70fSLiam Girdwood 489ee42381eSTakashi Iwai static int patch_wolfson_wm9703_specific(struct snd_ac97 * ac97) 4901da177e4SLinus Torvalds { 4911da177e4SLinus Torvalds /* This is known to work for the ViewSonic ViewPad 1000 4923998b70fSLiam Girdwood * Randolph Bentson <bentson@holmsjoen.com> 4933998b70fSLiam Girdwood * WM9703/9707/9708/9717 4943998b70fSLiam Girdwood */ 4953998b70fSLiam Girdwood int err, i; 4961da177e4SLinus Torvalds 4973998b70fSLiam Girdwood for (i = 0; i < ARRAY_SIZE(wm97xx_snd_ac97_controls); i++) { 4983998b70fSLiam Girdwood if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm97xx_snd_ac97_controls[i], ac97))) < 0) 4993998b70fSLiam Girdwood return err; 5003998b70fSLiam Girdwood } 5011da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808); 5021da177e4SLinus Torvalds return 0; 5031da177e4SLinus Torvalds } 5041da177e4SLinus Torvalds 505*3e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_wolfson_wm9703_ops = { 5063998b70fSLiam Girdwood .build_specific = patch_wolfson_wm9703_specific, 5073998b70fSLiam Girdwood }; 5083998b70fSLiam Girdwood 509ac519028STakashi Iwai static int patch_wolfson03(struct snd_ac97 * ac97) 5103998b70fSLiam Girdwood { 5113998b70fSLiam Girdwood ac97->build_ops = &patch_wolfson_wm9703_ops; 5123998b70fSLiam Girdwood return 0; 5133998b70fSLiam Girdwood } 5143998b70fSLiam Girdwood 515ee42381eSTakashi Iwai static const struct snd_kcontrol_new wm9704_snd_ac97_controls[] = { 5163998b70fSLiam Girdwood AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1), 5173998b70fSLiam Girdwood AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1), 5183998b70fSLiam Girdwood AC97_DOUBLE("Rear Playback Volume", AC97_WM9704_RMIXER_VOL, 8, 0, 31, 1), 5193998b70fSLiam Girdwood AC97_SINGLE("Rear Playback Switch", AC97_WM9704_RMIXER_VOL, 15, 1, 1), 5203998b70fSLiam Girdwood AC97_DOUBLE("Rear DAC Volume", AC97_WM9704_RPCM_VOL, 8, 0, 31, 1), 5213998b70fSLiam Girdwood AC97_DOUBLE("Surround Volume", AC97_SURROUND_MASTER, 8, 0, 31, 1), 5223998b70fSLiam Girdwood }; 5233998b70fSLiam Girdwood 524ee42381eSTakashi Iwai static int patch_wolfson_wm9704_specific(struct snd_ac97 * ac97) 5253998b70fSLiam Girdwood { 5263998b70fSLiam Girdwood int err, i; 5273998b70fSLiam Girdwood for (i = 0; i < ARRAY_SIZE(wm9704_snd_ac97_controls); i++) { 5283998b70fSLiam Girdwood if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9704_snd_ac97_controls[i], ac97))) < 0) 5293998b70fSLiam Girdwood return err; 5303998b70fSLiam Girdwood } 5313998b70fSLiam Girdwood /* patch for DVD noise */ 5323998b70fSLiam Girdwood snd_ac97_write_cache(ac97, AC97_WM9704_TEST, 0x0200); 5333998b70fSLiam Girdwood return 0; 5343998b70fSLiam Girdwood } 5353998b70fSLiam Girdwood 536*3e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_wolfson_wm9704_ops = { 5373998b70fSLiam Girdwood .build_specific = patch_wolfson_wm9704_specific, 5383998b70fSLiam Girdwood }; 5393998b70fSLiam Girdwood 540ac519028STakashi Iwai static int patch_wolfson04(struct snd_ac97 * ac97) 5411da177e4SLinus Torvalds { 5423998b70fSLiam Girdwood /* WM9704M/9704Q */ 5433998b70fSLiam Girdwood ac97->build_ops = &patch_wolfson_wm9704_ops; 5441da177e4SLinus Torvalds return 0; 5451da177e4SLinus Torvalds } 5461da177e4SLinus Torvalds 547ac519028STakashi Iwai static int patch_wolfson05(struct snd_ac97 * ac97) 5481da177e4SLinus Torvalds { 5493998b70fSLiam Girdwood /* WM9705, WM9710 */ 550dd3533ecSKrzysztof Helt ac97->build_ops = &patch_wolfson_wm9703_ops; 5511459c784SRodolfo Giometti #ifdef CONFIG_TOUCHSCREEN_WM9705 5521459c784SRodolfo Giometti /* WM9705 touchscreen uses AUX and VIDEO for touch */ 5538f88820eSLiam Girdwood ac97->flags |= AC97_HAS_NO_VIDEO | AC97_HAS_NO_AUX; 5541459c784SRodolfo Giometti #endif 5551da177e4SLinus Torvalds return 0; 5561da177e4SLinus Torvalds } 5571da177e4SLinus Torvalds 5583998b70fSLiam Girdwood static const char* wm9711_alc_select[] = {"None", "Left", "Right", "Stereo"}; 5593998b70fSLiam Girdwood static const char* wm9711_alc_mix[] = {"Stereo", "Right", "Left", "None"}; 5603998b70fSLiam Girdwood static const char* wm9711_out3_src[] = {"Left", "VREF", "Left + Right", "Mono"}; 5613998b70fSLiam Girdwood static const char* wm9711_out3_lrsrc[] = {"Master Mix", "Headphone Mix"}; 5623998b70fSLiam Girdwood static const char* wm9711_rec_adc[] = {"Stereo", "Left", "Right", "Mute"}; 5633998b70fSLiam Girdwood static const char* wm9711_base[] = {"Linear Control", "Adaptive Boost"}; 5643998b70fSLiam Girdwood static const char* wm9711_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"}; 5653998b70fSLiam Girdwood static const char* wm9711_mic[] = {"Mic 1", "Differential", "Mic 2", "Stereo"}; 5663998b70fSLiam Girdwood static const char* wm9711_rec_sel[] = 5673998b70fSLiam Girdwood {"Mic 1", "NC", "NC", "Master Mix", "Line", "Headphone Mix", "Phone Mix", "Phone"}; 5683998b70fSLiam Girdwood static const char* wm9711_ng_type[] = {"Constant Gain", "Mute"}; 5693998b70fSLiam Girdwood 5703998b70fSLiam Girdwood static const struct ac97_enum wm9711_enum[] = { 5713998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9711_alc_select), 5723998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_VIDEO, 10, 4, wm9711_alc_mix), 5733998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_AUX, 9, 4, wm9711_out3_src), 5743998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_AUX, 8, 2, wm9711_out3_lrsrc), 5753998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_REC_SEL, 12, 4, wm9711_rec_adc), 5763998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_MASTER_TONE, 15, 2, wm9711_base), 5773998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_REC_GAIN, 14, 6, 2, wm9711_rec_gain), 5783998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_MIC, 5, 4, wm9711_mic), 5793998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_REC_SEL, 8, 0, 8, wm9711_rec_sel), 5803998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9711_ng_type), 5813998b70fSLiam Girdwood }; 5823998b70fSLiam Girdwood 583ee42381eSTakashi Iwai static const struct snd_kcontrol_new wm9711_snd_ac97_controls[] = { 5843998b70fSLiam Girdwood AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0), 5853998b70fSLiam Girdwood AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0), 5863998b70fSLiam Girdwood AC97_SINGLE("ALC Decay Time", AC97_CODEC_CLASS_REV, 4, 15, 0), 5873998b70fSLiam Girdwood AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0), 5883998b70fSLiam Girdwood AC97_ENUM("ALC Function", wm9711_enum[0]), 5893998b70fSLiam Girdwood AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 1), 5903998b70fSLiam Girdwood AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 1), 5913998b70fSLiam Girdwood AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0), 5923998b70fSLiam Girdwood AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0), 5933998b70fSLiam Girdwood AC97_ENUM("ALC NG Type", wm9711_enum[9]), 5943998b70fSLiam Girdwood AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 1), 5953998b70fSLiam Girdwood 5963998b70fSLiam Girdwood AC97_SINGLE("Side Tone Switch", AC97_VIDEO, 15, 1, 1), 5973998b70fSLiam Girdwood AC97_SINGLE("Side Tone Volume", AC97_VIDEO, 12, 7, 1), 5983998b70fSLiam Girdwood AC97_ENUM("ALC Headphone Mux", wm9711_enum[1]), 5993998b70fSLiam Girdwood AC97_SINGLE("ALC Headphone Volume", AC97_VIDEO, 7, 7, 1), 6003998b70fSLiam Girdwood 6013998b70fSLiam Girdwood AC97_SINGLE("Out3 Switch", AC97_AUX, 15, 1, 1), 6022aedbda6SLuke Zhang AC97_SINGLE("Out3 ZC Switch", AC97_AUX, 7, 1, 0), 6033998b70fSLiam Girdwood AC97_ENUM("Out3 Mux", wm9711_enum[2]), 6043998b70fSLiam Girdwood AC97_ENUM("Out3 LR Mux", wm9711_enum[3]), 6053998b70fSLiam Girdwood AC97_SINGLE("Out3 Volume", AC97_AUX, 0, 31, 1), 6063998b70fSLiam Girdwood 6073998b70fSLiam Girdwood AC97_SINGLE("Beep to Headphone Switch", AC97_PC_BEEP, 15, 1, 1), 6083998b70fSLiam Girdwood AC97_SINGLE("Beep to Headphone Volume", AC97_PC_BEEP, 12, 7, 1), 6093998b70fSLiam Girdwood AC97_SINGLE("Beep to Side Tone Switch", AC97_PC_BEEP, 11, 1, 1), 6103998b70fSLiam Girdwood AC97_SINGLE("Beep to Side Tone Volume", AC97_PC_BEEP, 8, 7, 1), 6113998b70fSLiam Girdwood AC97_SINGLE("Beep to Phone Switch", AC97_PC_BEEP, 7, 1, 1), 6123998b70fSLiam Girdwood AC97_SINGLE("Beep to Phone Volume", AC97_PC_BEEP, 4, 7, 1), 6133998b70fSLiam Girdwood 6143998b70fSLiam Girdwood AC97_SINGLE("Aux to Headphone Switch", AC97_CD, 15, 1, 1), 6153998b70fSLiam Girdwood AC97_SINGLE("Aux to Headphone Volume", AC97_CD, 12, 7, 1), 6163998b70fSLiam Girdwood AC97_SINGLE("Aux to Side Tone Switch", AC97_CD, 11, 1, 1), 6173998b70fSLiam Girdwood AC97_SINGLE("Aux to Side Tone Volume", AC97_CD, 8, 7, 1), 6183998b70fSLiam Girdwood AC97_SINGLE("Aux to Phone Switch", AC97_CD, 7, 1, 1), 6193998b70fSLiam Girdwood AC97_SINGLE("Aux to Phone Volume", AC97_CD, 4, 7, 1), 6203998b70fSLiam Girdwood 6213998b70fSLiam Girdwood AC97_SINGLE("Phone to Headphone Switch", AC97_PHONE, 15, 1, 1), 6223998b70fSLiam Girdwood AC97_SINGLE("Phone to Master Switch", AC97_PHONE, 14, 1, 1), 6233998b70fSLiam Girdwood 6243998b70fSLiam Girdwood AC97_SINGLE("Line to Headphone Switch", AC97_LINE, 15, 1, 1), 6253998b70fSLiam Girdwood AC97_SINGLE("Line to Master Switch", AC97_LINE, 14, 1, 1), 6263998b70fSLiam Girdwood AC97_SINGLE("Line to Phone Switch", AC97_LINE, 13, 1, 1), 6273998b70fSLiam Girdwood 6283998b70fSLiam Girdwood AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PCM, 15, 1, 1), 6293998b70fSLiam Girdwood AC97_SINGLE("PCM Playback to Master Switch", AC97_PCM, 14, 1, 1), 6303998b70fSLiam Girdwood AC97_SINGLE("PCM Playback to Phone Switch", AC97_PCM, 13, 1, 1), 6313998b70fSLiam Girdwood 6323998b70fSLiam Girdwood AC97_SINGLE("Capture 20dB Boost Switch", AC97_REC_SEL, 14, 1, 0), 6333998b70fSLiam Girdwood AC97_ENUM("Capture to Phone Mux", wm9711_enum[4]), 6343998b70fSLiam Girdwood AC97_SINGLE("Capture to Phone 20dB Boost Switch", AC97_REC_SEL, 11, 1, 1), 6353998b70fSLiam Girdwood AC97_ENUM("Capture Select", wm9711_enum[8]), 6363998b70fSLiam Girdwood 6373998b70fSLiam Girdwood AC97_SINGLE("3D Upper Cut-off Switch", AC97_3D_CONTROL, 5, 1, 1), 6383998b70fSLiam Girdwood AC97_SINGLE("3D Lower Cut-off Switch", AC97_3D_CONTROL, 4, 1, 1), 6393998b70fSLiam Girdwood 6403998b70fSLiam Girdwood AC97_ENUM("Bass Control", wm9711_enum[5]), 6413998b70fSLiam Girdwood AC97_SINGLE("Bass Cut-off Switch", AC97_MASTER_TONE, 12, 1, 1), 6423998b70fSLiam Girdwood AC97_SINGLE("Tone Cut-off Switch", AC97_MASTER_TONE, 4, 1, 1), 6433998b70fSLiam Girdwood AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_MASTER_TONE, 6, 1, 0), 6443998b70fSLiam Girdwood 6453998b70fSLiam Girdwood AC97_SINGLE("ADC Switch", AC97_REC_GAIN, 15, 1, 1), 6463998b70fSLiam Girdwood AC97_ENUM("Capture Volume Steps", wm9711_enum[6]), 6472aedbda6SLuke Zhang AC97_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 63, 1), 6483998b70fSLiam Girdwood AC97_SINGLE("Capture ZC Switch", AC97_REC_GAIN, 7, 1, 0), 6493998b70fSLiam Girdwood 6503998b70fSLiam Girdwood AC97_SINGLE("Mic 1 to Phone Switch", AC97_MIC, 14, 1, 1), 6513998b70fSLiam Girdwood AC97_SINGLE("Mic 2 to Phone Switch", AC97_MIC, 13, 1, 1), 6523998b70fSLiam Girdwood AC97_ENUM("Mic Select Source", wm9711_enum[7]), 6532aedbda6SLuke Zhang AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1), 6542aedbda6SLuke Zhang AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1), 655d7f6f115SJames Courtier-Dutton AC97_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 7, 1, 0), 6563998b70fSLiam Girdwood 6570264b3b6SJuergen Beisert AC97_SINGLE("Master Left Inv Switch", AC97_MASTER, 6, 1, 0), 6583998b70fSLiam Girdwood AC97_SINGLE("Master ZC Switch", AC97_MASTER, 7, 1, 0), 6593998b70fSLiam Girdwood AC97_SINGLE("Headphone ZC Switch", AC97_HEADPHONE, 7, 1, 0), 6603998b70fSLiam Girdwood AC97_SINGLE("Mono ZC Switch", AC97_MASTER_MONO, 7, 1, 0), 6613998b70fSLiam Girdwood }; 6623998b70fSLiam Girdwood 663ee42381eSTakashi Iwai static int patch_wolfson_wm9711_specific(struct snd_ac97 * ac97) 6643998b70fSLiam Girdwood { 6653998b70fSLiam Girdwood int err, i; 6663998b70fSLiam Girdwood 6673998b70fSLiam Girdwood for (i = 0; i < ARRAY_SIZE(wm9711_snd_ac97_controls); i++) { 6683998b70fSLiam Girdwood if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9711_snd_ac97_controls[i], ac97))) < 0) 6693998b70fSLiam Girdwood return err; 6703998b70fSLiam Girdwood } 6713998b70fSLiam Girdwood snd_ac97_write_cache(ac97, AC97_CODEC_CLASS_REV, 0x0808); 6723998b70fSLiam Girdwood snd_ac97_write_cache(ac97, AC97_PCI_SVID, 0x0808); 6733998b70fSLiam Girdwood snd_ac97_write_cache(ac97, AC97_VIDEO, 0x0808); 6743998b70fSLiam Girdwood snd_ac97_write_cache(ac97, AC97_AUX, 0x0808); 6753998b70fSLiam Girdwood snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808); 6763998b70fSLiam Girdwood snd_ac97_write_cache(ac97, AC97_CD, 0x0000); 6773998b70fSLiam Girdwood return 0; 6783998b70fSLiam Girdwood } 6793998b70fSLiam Girdwood 680*3e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_wolfson_wm9711_ops = { 6813998b70fSLiam Girdwood .build_specific = patch_wolfson_wm9711_specific, 6823998b70fSLiam Girdwood }; 6833998b70fSLiam Girdwood 684ac519028STakashi Iwai static int patch_wolfson11(struct snd_ac97 * ac97) 6851da177e4SLinus Torvalds { 6863998b70fSLiam Girdwood /* WM9711, WM9712 */ 6873998b70fSLiam Girdwood ac97->build_ops = &patch_wolfson_wm9711_ops; 6883998b70fSLiam Girdwood 6893998b70fSLiam Girdwood ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_MIC | 6903998b70fSLiam Girdwood AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD; 6913998b70fSLiam Girdwood 6921da177e4SLinus Torvalds return 0; 6931da177e4SLinus Torvalds } 6941da177e4SLinus Torvalds 6951da177e4SLinus Torvalds static const char* wm9713_mic_mixer[] = {"Stereo", "Mic 1", "Mic 2", "Mute"}; 6961da177e4SLinus Torvalds static const char* wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"}; 6973998b70fSLiam Girdwood static const char* wm9713_rec_src[] = 6983998b70fSLiam Girdwood {"Mic 1", "Mic 2", "Line", "Mono In", "Headphone Mix", "Master Mix", 6993998b70fSLiam Girdwood "Mono Mix", "Zh"}; 7003998b70fSLiam Girdwood static const char* wm9713_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"}; 7013998b70fSLiam Girdwood static const char* wm9713_alc_select[] = {"None", "Left", "Right", "Stereo"}; 7023998b70fSLiam Girdwood static const char* wm9713_mono_pga[] = {"Vmid", "Zh", "Mono Mix", "Inv 1"}; 7033998b70fSLiam Girdwood static const char* wm9713_spk_pga[] = 7043998b70fSLiam Girdwood {"Vmid", "Zh", "Headphone Mix", "Master Mix", "Inv", "NC", "NC", "NC"}; 7053998b70fSLiam Girdwood static const char* wm9713_hp_pga[] = {"Vmid", "Zh", "Headphone Mix", "NC"}; 7063998b70fSLiam Girdwood static const char* wm9713_out3_pga[] = {"Vmid", "Zh", "Inv 1", "NC"}; 7073998b70fSLiam Girdwood static const char* wm9713_out4_pga[] = {"Vmid", "Zh", "Inv 2", "NC"}; 7083998b70fSLiam Girdwood static const char* wm9713_dac_inv[] = 7093998b70fSLiam Girdwood {"Off", "Mono Mix", "Master Mix", "Headphone Mix L", "Headphone Mix R", 7103998b70fSLiam Girdwood "Headphone Mix Mono", "NC", "Vmid"}; 7113998b70fSLiam Girdwood static const char* wm9713_base[] = {"Linear Control", "Adaptive Boost"}; 7123998b70fSLiam Girdwood static const char* wm9713_ng_type[] = {"Constant Gain", "Mute"}; 7131da177e4SLinus Torvalds 7141da177e4SLinus Torvalds static const struct ac97_enum wm9713_enum[] = { 7151da177e4SLinus Torvalds AC97_ENUM_SINGLE(AC97_LINE, 3, 4, wm9713_mic_mixer), 7161da177e4SLinus Torvalds AC97_ENUM_SINGLE(AC97_VIDEO, 14, 4, wm9713_rec_mux), 7171da177e4SLinus Torvalds AC97_ENUM_SINGLE(AC97_VIDEO, 9, 4, wm9713_rec_mux), 7183998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_VIDEO, 3, 0, 8, wm9713_rec_src), 7193998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_CD, 14, 6, 2, wm9713_rec_gain), 7203998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9713_alc_select), 7213998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_REC_GAIN, 14, 4, wm9713_mono_pga), 7223998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_REC_GAIN, 11, 8, 8, wm9713_spk_pga), 7233998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_REC_GAIN, 6, 4, 4, wm9713_hp_pga), 7243998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_REC_GAIN, 2, 4, wm9713_out3_pga), 7253998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_REC_GAIN, 0, 4, wm9713_out4_pga), 7263998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_REC_GAIN_MIC, 13, 10, 8, wm9713_dac_inv), 7273998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, wm9713_base), 7283998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9713_ng_type), 7291da177e4SLinus Torvalds }; 7301da177e4SLinus Torvalds 731ee42381eSTakashi Iwai static const struct snd_kcontrol_new wm13_snd_ac97_controls[] = { 7321da177e4SLinus Torvalds AC97_DOUBLE("Line In Volume", AC97_PC_BEEP, 8, 0, 31, 1), 7333998b70fSLiam Girdwood AC97_SINGLE("Line In to Headphone Switch", AC97_PC_BEEP, 15, 1, 1), 7343998b70fSLiam Girdwood AC97_SINGLE("Line In to Master Switch", AC97_PC_BEEP, 14, 1, 1), 7353998b70fSLiam Girdwood AC97_SINGLE("Line In to Mono Switch", AC97_PC_BEEP, 13, 1, 1), 7363998b70fSLiam Girdwood 7373998b70fSLiam Girdwood AC97_DOUBLE("PCM Playback Volume", AC97_PHONE, 8, 0, 31, 1), 7383998b70fSLiam Girdwood AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PHONE, 15, 1, 1), 7393998b70fSLiam Girdwood AC97_SINGLE("PCM Playback to Master Switch", AC97_PHONE, 14, 1, 1), 7403998b70fSLiam Girdwood AC97_SINGLE("PCM Playback to Mono Switch", AC97_PHONE, 13, 1, 1), 7413998b70fSLiam Girdwood 7423998b70fSLiam Girdwood AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1), 7433998b70fSLiam Girdwood AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1), 7443998b70fSLiam Girdwood AC97_SINGLE("Mic 1 to Mono Switch", AC97_LINE, 7, 1, 1), 7453998b70fSLiam Girdwood AC97_SINGLE("Mic 2 to Mono Switch", AC97_LINE, 6, 1, 1), 746d7f6f115SJames Courtier-Dutton AC97_SINGLE("Mic Boost (+20dB) Switch", AC97_LINE, 5, 1, 0), 7473998b70fSLiam Girdwood AC97_ENUM("Mic to Headphone Mux", wm9713_enum[0]), 7483998b70fSLiam Girdwood AC97_SINGLE("Mic Headphone Mixer Volume", AC97_LINE, 0, 7, 1), 7493998b70fSLiam Girdwood 7503998b70fSLiam Girdwood AC97_SINGLE("Capture Switch", AC97_CD, 15, 1, 1), 7513998b70fSLiam Girdwood AC97_ENUM("Capture Volume Steps", wm9713_enum[4]), 7523998b70fSLiam Girdwood AC97_DOUBLE("Capture Volume", AC97_CD, 8, 0, 15, 0), 7533998b70fSLiam Girdwood AC97_SINGLE("Capture ZC Switch", AC97_CD, 7, 1, 0), 7543998b70fSLiam Girdwood 7553998b70fSLiam Girdwood AC97_ENUM("Capture to Headphone Mux", wm9713_enum[1]), 7563998b70fSLiam Girdwood AC97_SINGLE("Capture to Headphone Volume", AC97_VIDEO, 11, 7, 1), 7573998b70fSLiam Girdwood AC97_ENUM("Capture to Mono Mux", wm9713_enum[2]), 7583998b70fSLiam Girdwood AC97_SINGLE("Capture to Mono Boost (+20dB) Switch", AC97_VIDEO, 8, 1, 0), 7593998b70fSLiam Girdwood AC97_SINGLE("Capture ADC Boost (+20dB) Switch", AC97_VIDEO, 6, 1, 0), 7603998b70fSLiam Girdwood AC97_ENUM("Capture Select", wm9713_enum[3]), 7613998b70fSLiam Girdwood 7623998b70fSLiam Girdwood AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0), 7633998b70fSLiam Girdwood AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0), 7643998b70fSLiam Girdwood AC97_SINGLE("ALC Decay Time ", AC97_CODEC_CLASS_REV, 4, 15, 0), 7653998b70fSLiam Girdwood AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0), 7663998b70fSLiam Girdwood AC97_ENUM("ALC Function", wm9713_enum[5]), 7673998b70fSLiam Girdwood AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 0), 7683998b70fSLiam Girdwood AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 0), 7693998b70fSLiam Girdwood AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0), 7703998b70fSLiam Girdwood AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0), 7713998b70fSLiam Girdwood AC97_ENUM("ALC NG Type", wm9713_enum[13]), 7723998b70fSLiam Girdwood AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 0), 7733998b70fSLiam Girdwood 7743998b70fSLiam Girdwood AC97_DOUBLE("Master ZC Switch", AC97_MASTER, 14, 6, 1, 0), 7753998b70fSLiam Girdwood AC97_DOUBLE("Headphone ZC Switch", AC97_HEADPHONE, 14, 6, 1, 0), 7763998b70fSLiam Girdwood AC97_DOUBLE("Out3/4 ZC Switch", AC97_MASTER_MONO, 14, 6, 1, 0), 7773998b70fSLiam Girdwood AC97_SINGLE("Master Right Switch", AC97_MASTER, 7, 1, 1), 7783998b70fSLiam Girdwood AC97_SINGLE("Headphone Right Switch", AC97_HEADPHONE, 7, 1, 1), 7793998b70fSLiam Girdwood AC97_SINGLE("Out3/4 Right Switch", AC97_MASTER_MONO, 7, 1, 1), 7803998b70fSLiam Girdwood 7813998b70fSLiam Girdwood AC97_SINGLE("Mono In to Headphone Switch", AC97_MASTER_TONE, 15, 1, 1), 7823998b70fSLiam Girdwood AC97_SINGLE("Mono In to Master Switch", AC97_MASTER_TONE, 14, 1, 1), 7833998b70fSLiam Girdwood AC97_SINGLE("Mono In Volume", AC97_MASTER_TONE, 8, 31, 1), 7843998b70fSLiam Girdwood AC97_SINGLE("Mono Switch", AC97_MASTER_TONE, 7, 1, 1), 7853998b70fSLiam Girdwood AC97_SINGLE("Mono ZC Switch", AC97_MASTER_TONE, 6, 1, 0), 7863998b70fSLiam Girdwood AC97_SINGLE("Mono Volume", AC97_MASTER_TONE, 0, 31, 1), 7873998b70fSLiam Girdwood 788d355c82aSJaroslav Kysela AC97_SINGLE("Beep to Headphone Switch", AC97_AUX, 15, 1, 1), 789d355c82aSJaroslav Kysela AC97_SINGLE("Beep to Headphone Volume", AC97_AUX, 12, 7, 1), 790d355c82aSJaroslav Kysela AC97_SINGLE("Beep to Master Switch", AC97_AUX, 11, 1, 1), 791d355c82aSJaroslav Kysela AC97_SINGLE("Beep to Master Volume", AC97_AUX, 8, 7, 1), 792d355c82aSJaroslav Kysela AC97_SINGLE("Beep to Mono Switch", AC97_AUX, 7, 1, 1), 793d355c82aSJaroslav Kysela AC97_SINGLE("Beep to Mono Volume", AC97_AUX, 4, 7, 1), 7943998b70fSLiam Girdwood 7953998b70fSLiam Girdwood AC97_SINGLE("Voice to Headphone Switch", AC97_PCM, 15, 1, 1), 7963998b70fSLiam Girdwood AC97_SINGLE("Voice to Headphone Volume", AC97_PCM, 12, 7, 1), 7973998b70fSLiam Girdwood AC97_SINGLE("Voice to Master Switch", AC97_PCM, 11, 1, 1), 7983998b70fSLiam Girdwood AC97_SINGLE("Voice to Master Volume", AC97_PCM, 8, 7, 1), 7993998b70fSLiam Girdwood AC97_SINGLE("Voice to Mono Switch", AC97_PCM, 7, 1, 1), 8003998b70fSLiam Girdwood AC97_SINGLE("Voice to Mono Volume", AC97_PCM, 4, 7, 1), 8013998b70fSLiam Girdwood 8023998b70fSLiam Girdwood AC97_SINGLE("Aux to Headphone Switch", AC97_REC_SEL, 15, 1, 1), 8033998b70fSLiam Girdwood AC97_SINGLE("Aux to Headphone Volume", AC97_REC_SEL, 12, 7, 1), 8043998b70fSLiam Girdwood AC97_SINGLE("Aux to Master Switch", AC97_REC_SEL, 11, 1, 1), 8053998b70fSLiam Girdwood AC97_SINGLE("Aux to Master Volume", AC97_REC_SEL, 8, 7, 1), 8063998b70fSLiam Girdwood AC97_SINGLE("Aux to Mono Switch", AC97_REC_SEL, 7, 1, 1), 8073998b70fSLiam Girdwood AC97_SINGLE("Aux to Mono Volume", AC97_REC_SEL, 4, 7, 1), 8083998b70fSLiam Girdwood 8093998b70fSLiam Girdwood AC97_ENUM("Mono Input Mux", wm9713_enum[6]), 8103998b70fSLiam Girdwood AC97_ENUM("Master Input Mux", wm9713_enum[7]), 8113998b70fSLiam Girdwood AC97_ENUM("Headphone Input Mux", wm9713_enum[8]), 8123998b70fSLiam Girdwood AC97_ENUM("Out 3 Input Mux", wm9713_enum[9]), 8133998b70fSLiam Girdwood AC97_ENUM("Out 4 Input Mux", wm9713_enum[10]), 8143998b70fSLiam Girdwood 8153998b70fSLiam Girdwood AC97_ENUM("Bass Control", wm9713_enum[12]), 8163998b70fSLiam Girdwood AC97_SINGLE("Bass Cut-off Switch", AC97_GENERAL_PURPOSE, 12, 1, 1), 8173998b70fSLiam Girdwood AC97_SINGLE("Tone Cut-off Switch", AC97_GENERAL_PURPOSE, 4, 1, 1), 8183998b70fSLiam Girdwood AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_GENERAL_PURPOSE, 6, 1, 0), 8193998b70fSLiam Girdwood AC97_SINGLE("Bass Volume", AC97_GENERAL_PURPOSE, 8, 15, 1), 8203998b70fSLiam Girdwood AC97_SINGLE("Tone Volume", AC97_GENERAL_PURPOSE, 0, 15, 1), 8211da177e4SLinus Torvalds }; 8221da177e4SLinus Torvalds 823ee42381eSTakashi Iwai static const struct snd_kcontrol_new wm13_snd_ac97_controls_3d[] = { 8243998b70fSLiam Girdwood AC97_ENUM("Inv Input Mux", wm9713_enum[11]), 8253998b70fSLiam Girdwood AC97_SINGLE("3D Upper Cut-off Switch", AC97_REC_GAIN_MIC, 5, 1, 0), 8263998b70fSLiam Girdwood AC97_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC, 4, 1, 0), 8273998b70fSLiam Girdwood AC97_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1), 8281da177e4SLinus Torvalds }; 8291da177e4SLinus Torvalds 830ee42381eSTakashi Iwai static int patch_wolfson_wm9713_3d (struct snd_ac97 * ac97) 8313998b70fSLiam Girdwood { 8323998b70fSLiam Girdwood int err, i; 8331da177e4SLinus Torvalds 8343998b70fSLiam Girdwood for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_3d); i++) { 8353998b70fSLiam Girdwood if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_3d[i], ac97))) < 0) 8363998b70fSLiam Girdwood return err; 8373998b70fSLiam Girdwood } 8383998b70fSLiam Girdwood return 0; 8393998b70fSLiam Girdwood } 8401da177e4SLinus Torvalds 841ee42381eSTakashi Iwai static int patch_wolfson_wm9713_specific(struct snd_ac97 * ac97) 8421da177e4SLinus Torvalds { 8431da177e4SLinus Torvalds int err, i; 8441da177e4SLinus Torvalds 8453998b70fSLiam Girdwood for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls); i++) { 8463998b70fSLiam Girdwood if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls[i], ac97))) < 0) 8471da177e4SLinus Torvalds return err; 8481da177e4SLinus Torvalds } 8491da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808); 8501da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_PHONE, 0x0808); 8511da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_MIC, 0x0808); 8521da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_LINE, 0x00da); 8531da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_CD, 0x0808); 8541da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_VIDEO, 0xd612); 8551da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x1ba0); 8561da177e4SLinus Torvalds return 0; 8571da177e4SLinus Torvalds } 8581da177e4SLinus Torvalds 8591da177e4SLinus Torvalds #ifdef CONFIG_PM 860ee42381eSTakashi Iwai static void patch_wolfson_wm9713_suspend (struct snd_ac97 * ac97) 8611da177e4SLinus Torvalds { 8621da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xfeff); 8631da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0xffff); 8641da177e4SLinus Torvalds } 8651da177e4SLinus Torvalds 866ee42381eSTakashi Iwai static void patch_wolfson_wm9713_resume (struct snd_ac97 * ac97) 8671da177e4SLinus Torvalds { 8681da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00); 8691da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810); 8701da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0); 8711da177e4SLinus Torvalds } 8721da177e4SLinus Torvalds #endif 8731da177e4SLinus Torvalds 874*3e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_wolfson_wm9713_ops = { 8751da177e4SLinus Torvalds .build_specific = patch_wolfson_wm9713_specific, 8763998b70fSLiam Girdwood .build_3d = patch_wolfson_wm9713_3d, 8771da177e4SLinus Torvalds #ifdef CONFIG_PM 8781da177e4SLinus Torvalds .suspend = patch_wolfson_wm9713_suspend, 8791da177e4SLinus Torvalds .resume = patch_wolfson_wm9713_resume 8801da177e4SLinus Torvalds #endif 8811da177e4SLinus Torvalds }; 8821da177e4SLinus Torvalds 883ac519028STakashi Iwai static int patch_wolfson13(struct snd_ac97 * ac97) 8841da177e4SLinus Torvalds { 8853998b70fSLiam Girdwood /* WM9713, WM9714 */ 8861da177e4SLinus Torvalds ac97->build_ops = &patch_wolfson_wm9713_ops; 8871da177e4SLinus Torvalds 8881da177e4SLinus Torvalds ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_PHONE | 8893998b70fSLiam Girdwood AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD | AC97_HAS_NO_TONE | 8903998b70fSLiam Girdwood AC97_HAS_NO_STD_PCM; 891064d2112SLiam Girdwood ac97->scaps &= ~AC97_SCAP_MODEM; 8921da177e4SLinus Torvalds 8931da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00); 8941da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810); 8951da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0); 8961da177e4SLinus Torvalds 8971da177e4SLinus Torvalds return 0; 8981da177e4SLinus Torvalds } 8991da177e4SLinus Torvalds 9001da177e4SLinus Torvalds /* 9011da177e4SLinus Torvalds * Tritech codec 9021da177e4SLinus Torvalds */ 903ac519028STakashi Iwai static int patch_tritech_tr28028(struct snd_ac97 * ac97) 9041da177e4SLinus Torvalds { 9051da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x26, 0x0300); 9061da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x26, 0x0000); 9071da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SURROUND_MASTER, 0x0000); 9081da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SPDIF, 0x0000); 9091da177e4SLinus Torvalds return 0; 9101da177e4SLinus Torvalds } 9111da177e4SLinus Torvalds 9121da177e4SLinus Torvalds /* 9131da177e4SLinus Torvalds * Sigmatel STAC97xx codecs 9141da177e4SLinus Torvalds */ 915ee42381eSTakashi Iwai static int patch_sigmatel_stac9700_3d(struct snd_ac97 * ac97) 9161da177e4SLinus Torvalds { 917ee42381eSTakashi Iwai struct snd_kcontrol *kctl; 9181da177e4SLinus Torvalds int err; 9191da177e4SLinus Torvalds 9201da177e4SLinus Torvalds if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0) 9211da177e4SLinus Torvalds return err; 9221da177e4SLinus Torvalds strcpy(kctl->id.name, "3D Control Sigmatel - Depth"); 9231da177e4SLinus Torvalds kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0); 9241da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000); 9251da177e4SLinus Torvalds return 0; 9261da177e4SLinus Torvalds } 9271da177e4SLinus Torvalds 928ee42381eSTakashi Iwai static int patch_sigmatel_stac9708_3d(struct snd_ac97 * ac97) 9291da177e4SLinus Torvalds { 930ee42381eSTakashi Iwai struct snd_kcontrol *kctl; 9311da177e4SLinus Torvalds int err; 9321da177e4SLinus Torvalds 9331da177e4SLinus Torvalds if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0) 9341da177e4SLinus Torvalds return err; 9351da177e4SLinus Torvalds strcpy(kctl->id.name, "3D Control Sigmatel - Depth"); 9361da177e4SLinus Torvalds kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 0, 3, 0); 9371da177e4SLinus Torvalds if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0) 9381da177e4SLinus Torvalds return err; 9391da177e4SLinus Torvalds strcpy(kctl->id.name, "3D Control Sigmatel - Rear Depth"); 9401da177e4SLinus Torvalds kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0); 9411da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000); 9421da177e4SLinus Torvalds return 0; 9431da177e4SLinus Torvalds } 9441da177e4SLinus Torvalds 945ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_sigmatel_4speaker = 946afe6d7e3SAndreas Mohr AC97_SINGLE("Sigmatel 4-Speaker Stereo Playback Switch", 947afe6d7e3SAndreas Mohr AC97_SIGMATEL_DAC2INVERT, 2, 1, 0); 9481da177e4SLinus Torvalds 949afe6d7e3SAndreas Mohr /* "Sigmatel " removed due to excessive name length: */ 950ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_sigmatel_phaseinvert = 951afe6d7e3SAndreas Mohr AC97_SINGLE("Surround Phase Inversion Playback Switch", 952afe6d7e3SAndreas Mohr AC97_SIGMATEL_DAC2INVERT, 3, 1, 0); 9531da177e4SLinus Torvalds 954ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_sigmatel_controls[] = { 9551da177e4SLinus Torvalds AC97_SINGLE("Sigmatel DAC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 1, 1, 0), 9561da177e4SLinus Torvalds AC97_SINGLE("Sigmatel ADC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 0, 1, 0) 9571da177e4SLinus Torvalds }; 9581da177e4SLinus Torvalds 959ee42381eSTakashi Iwai static int patch_sigmatel_stac97xx_specific(struct snd_ac97 * ac97) 9601da177e4SLinus Torvalds { 9611da177e4SLinus Torvalds int err; 9621da177e4SLinus Torvalds 9631da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_ANALOG, snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) & ~0x0003); 9641da177e4SLinus Torvalds if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 1)) 9651da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[0], 1)) < 0) 9661da177e4SLinus Torvalds return err; 9671da177e4SLinus Torvalds if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 0)) 9681da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[1], 1)) < 0) 9691da177e4SLinus Torvalds return err; 9701da177e4SLinus Torvalds if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 2)) 9711da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_4speaker, 1)) < 0) 9721da177e4SLinus Torvalds return err; 9731da177e4SLinus Torvalds if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 3)) 9741da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_phaseinvert, 1)) < 0) 9751da177e4SLinus Torvalds return err; 9761da177e4SLinus Torvalds return 0; 9771da177e4SLinus Torvalds } 9781da177e4SLinus Torvalds 979*3e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_sigmatel_stac9700_ops = { 9801da177e4SLinus Torvalds .build_3d = patch_sigmatel_stac9700_3d, 9811da177e4SLinus Torvalds .build_specific = patch_sigmatel_stac97xx_specific 9821da177e4SLinus Torvalds }; 9831da177e4SLinus Torvalds 984ac519028STakashi Iwai static int patch_sigmatel_stac9700(struct snd_ac97 * ac97) 9851da177e4SLinus Torvalds { 9861da177e4SLinus Torvalds ac97->build_ops = &patch_sigmatel_stac9700_ops; 9871da177e4SLinus Torvalds return 0; 9881da177e4SLinus Torvalds } 9891da177e4SLinus Torvalds 990ee42381eSTakashi Iwai static int snd_ac97_stac9708_put_bias(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 9911da177e4SLinus Torvalds { 992ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 9931da177e4SLinus Torvalds int err; 9941da177e4SLinus Torvalds 99562932df8SIngo Molnar mutex_lock(&ac97->page_mutex); 9961da177e4SLinus Torvalds snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0xabba); 9971da177e4SLinus Torvalds err = snd_ac97_update_bits(ac97, AC97_SIGMATEL_BIAS2, 0x0010, 9981da177e4SLinus Torvalds (ucontrol->value.integer.value[0] & 1) << 4); 9991da177e4SLinus Torvalds snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0); 100062932df8SIngo Molnar mutex_unlock(&ac97->page_mutex); 10011da177e4SLinus Torvalds return err; 10021da177e4SLinus Torvalds } 10031da177e4SLinus Torvalds 1004ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_stac9708_bias_control = { 10051da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 10061da177e4SLinus Torvalds .name = "Sigmatel Output Bias Switch", 10071da177e4SLinus Torvalds .info = snd_ac97_info_volsw, 10081da177e4SLinus Torvalds .get = snd_ac97_get_volsw, 10091da177e4SLinus Torvalds .put = snd_ac97_stac9708_put_bias, 10101da177e4SLinus Torvalds .private_value = AC97_SINGLE_VALUE(AC97_SIGMATEL_BIAS2, 4, 1, 0), 10111da177e4SLinus Torvalds }; 10121da177e4SLinus Torvalds 1013ee42381eSTakashi Iwai static int patch_sigmatel_stac9708_specific(struct snd_ac97 *ac97) 10141da177e4SLinus Torvalds { 10151da177e4SLinus Torvalds int err; 10161da177e4SLinus Torvalds 1017e4c3bf0fSJames C Georgas /* the register bit is writable, but the function is not implemented: */ 1018e4c3bf0fSJames C Georgas snd_ac97_remove_ctl(ac97, "PCM Out Path & Mute", NULL); 1019e4c3bf0fSJames C Georgas 10201da177e4SLinus Torvalds snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Sigmatel Surround Playback"); 10211da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_stac9708_bias_control, 1)) < 0) 10221da177e4SLinus Torvalds return err; 10231da177e4SLinus Torvalds return patch_sigmatel_stac97xx_specific(ac97); 10241da177e4SLinus Torvalds } 10251da177e4SLinus Torvalds 1026*3e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_sigmatel_stac9708_ops = { 10271da177e4SLinus Torvalds .build_3d = patch_sigmatel_stac9708_3d, 10281da177e4SLinus Torvalds .build_specific = patch_sigmatel_stac9708_specific 10291da177e4SLinus Torvalds }; 10301da177e4SLinus Torvalds 1031ac519028STakashi Iwai static int patch_sigmatel_stac9708(struct snd_ac97 * ac97) 10321da177e4SLinus Torvalds { 10331da177e4SLinus Torvalds unsigned int codec72, codec6c; 10341da177e4SLinus Torvalds 10351da177e4SLinus Torvalds ac97->build_ops = &patch_sigmatel_stac9708_ops; 10361da177e4SLinus Torvalds ac97->caps |= 0x10; /* HP (sigmatel surround) support */ 10371da177e4SLinus Torvalds 10381da177e4SLinus Torvalds codec72 = snd_ac97_read(ac97, AC97_SIGMATEL_BIAS2) & 0x8000; 10391da177e4SLinus Torvalds codec6c = snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG); 10401da177e4SLinus Torvalds 10411da177e4SLinus Torvalds if ((codec72==0) && (codec6c==0)) { 10421da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); 10431da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1000); 10441da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba); 10451da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0007); 10461da177e4SLinus Torvalds } else if ((codec72==0x8000) && (codec6c==0)) { 10471da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); 10481da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1001); 10491da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_DAC2INVERT, 0x0008); 10501da177e4SLinus Torvalds } else if ((codec72==0x8000) && (codec6c==0x0080)) { 10511da177e4SLinus Torvalds /* nothing */ 10521da177e4SLinus Torvalds } 10531da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000); 10541da177e4SLinus Torvalds return 0; 10551da177e4SLinus Torvalds } 10561da177e4SLinus Torvalds 1057ac519028STakashi Iwai static int patch_sigmatel_stac9721(struct snd_ac97 * ac97) 10581da177e4SLinus Torvalds { 10591da177e4SLinus Torvalds ac97->build_ops = &patch_sigmatel_stac9700_ops; 10601da177e4SLinus Torvalds if (snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) == 0) { 10611da177e4SLinus Torvalds // patch for SigmaTel 10621da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); 10631da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x4000); 10641da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba); 10651da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002); 10661da177e4SLinus Torvalds } 10671da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000); 10681da177e4SLinus Torvalds return 0; 10691da177e4SLinus Torvalds } 10701da177e4SLinus Torvalds 1071ac519028STakashi Iwai static int patch_sigmatel_stac9744(struct snd_ac97 * ac97) 10721da177e4SLinus Torvalds { 10731da177e4SLinus Torvalds // patch for SigmaTel 10741da177e4SLinus Torvalds ac97->build_ops = &patch_sigmatel_stac9700_ops; 10751da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); 10761da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */ 10771da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba); 10781da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002); 10791da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000); 10801da177e4SLinus Torvalds return 0; 10811da177e4SLinus Torvalds } 10821da177e4SLinus Torvalds 1083ac519028STakashi Iwai static int patch_sigmatel_stac9756(struct snd_ac97 * ac97) 10841da177e4SLinus Torvalds { 10851da177e4SLinus Torvalds // patch for SigmaTel 10861da177e4SLinus Torvalds ac97->build_ops = &patch_sigmatel_stac9700_ops; 10871da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); 10881da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */ 10891da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba); 10901da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002); 10911da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000); 10921da177e4SLinus Torvalds return 0; 10931da177e4SLinus Torvalds } 10941da177e4SLinus Torvalds 1095ee42381eSTakashi Iwai static int snd_ac97_stac9758_output_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 10961da177e4SLinus Torvalds { 10971da177e4SLinus Torvalds static char *texts[5] = { "Input/Disabled", "Front Output", 10981da177e4SLinus Torvalds "Rear Output", "Center/LFE Output", "Mixer Output" }; 10991da177e4SLinus Torvalds 11001da177e4SLinus Torvalds uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 11011da177e4SLinus Torvalds uinfo->count = 1; 11021da177e4SLinus Torvalds uinfo->value.enumerated.items = 5; 11031da177e4SLinus Torvalds if (uinfo->value.enumerated.item > 4) 11041da177e4SLinus Torvalds uinfo->value.enumerated.item = 4; 11051da177e4SLinus Torvalds strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 11061da177e4SLinus Torvalds return 0; 11071da177e4SLinus Torvalds } 11081da177e4SLinus Torvalds 1109ee42381eSTakashi Iwai static int snd_ac97_stac9758_output_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 11101da177e4SLinus Torvalds { 1111ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 11121da177e4SLinus Torvalds int shift = kcontrol->private_value; 11131da177e4SLinus Torvalds unsigned short val; 11141da177e4SLinus Torvalds 11151da177e4SLinus Torvalds val = ac97->regs[AC97_SIGMATEL_OUTSEL] >> shift; 11161da177e4SLinus Torvalds if (!(val & 4)) 11171da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = 0; 11181da177e4SLinus Torvalds else 11191da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = 1 + (val & 3); 11201da177e4SLinus Torvalds return 0; 11211da177e4SLinus Torvalds } 11221da177e4SLinus Torvalds 1123ee42381eSTakashi Iwai static int snd_ac97_stac9758_output_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 11241da177e4SLinus Torvalds { 1125ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 11261da177e4SLinus Torvalds int shift = kcontrol->private_value; 11271da177e4SLinus Torvalds unsigned short val; 11281da177e4SLinus Torvalds 11291da177e4SLinus Torvalds if (ucontrol->value.enumerated.item[0] > 4) 11301da177e4SLinus Torvalds return -EINVAL; 11311da177e4SLinus Torvalds if (ucontrol->value.enumerated.item[0] == 0) 11321da177e4SLinus Torvalds val = 0; 11331da177e4SLinus Torvalds else 11341da177e4SLinus Torvalds val = 4 | (ucontrol->value.enumerated.item[0] - 1); 11351da177e4SLinus Torvalds return ac97_update_bits_page(ac97, AC97_SIGMATEL_OUTSEL, 11361da177e4SLinus Torvalds 7 << shift, val << shift, 0); 11371da177e4SLinus Torvalds } 11381da177e4SLinus Torvalds 1139ee42381eSTakashi Iwai static int snd_ac97_stac9758_input_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 11401da177e4SLinus Torvalds { 11411da177e4SLinus Torvalds static char *texts[7] = { "Mic2 Jack", "Mic1 Jack", "Line In Jack", 11421da177e4SLinus Torvalds "Front Jack", "Rear Jack", "Center/LFE Jack", "Mute" }; 11431da177e4SLinus Torvalds 11441da177e4SLinus Torvalds uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 11451da177e4SLinus Torvalds uinfo->count = 1; 11461da177e4SLinus Torvalds uinfo->value.enumerated.items = 7; 11471da177e4SLinus Torvalds if (uinfo->value.enumerated.item > 6) 11481da177e4SLinus Torvalds uinfo->value.enumerated.item = 6; 11491da177e4SLinus Torvalds strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 11501da177e4SLinus Torvalds return 0; 11511da177e4SLinus Torvalds } 11521da177e4SLinus Torvalds 1153ee42381eSTakashi Iwai static int snd_ac97_stac9758_input_jack_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 int shift = kcontrol->private_value; 11571da177e4SLinus Torvalds unsigned short val; 11581da177e4SLinus Torvalds 11591da177e4SLinus Torvalds val = ac97->regs[AC97_SIGMATEL_INSEL]; 11601da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = (val >> shift) & 7; 11611da177e4SLinus Torvalds return 0; 11621da177e4SLinus Torvalds } 11631da177e4SLinus Torvalds 1164ee42381eSTakashi Iwai static int snd_ac97_stac9758_input_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 11651da177e4SLinus Torvalds { 1166ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 11671da177e4SLinus Torvalds int shift = kcontrol->private_value; 11681da177e4SLinus Torvalds 11691da177e4SLinus Torvalds return ac97_update_bits_page(ac97, AC97_SIGMATEL_INSEL, 7 << shift, 11701da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] << shift, 0); 11711da177e4SLinus Torvalds } 11721da177e4SLinus Torvalds 1173ee42381eSTakashi Iwai static int snd_ac97_stac9758_phonesel_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 11741da177e4SLinus Torvalds { 11751da177e4SLinus Torvalds static char *texts[3] = { "None", "Front Jack", "Rear Jack" }; 11761da177e4SLinus Torvalds 11771da177e4SLinus Torvalds uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 11781da177e4SLinus Torvalds uinfo->count = 1; 11791da177e4SLinus Torvalds uinfo->value.enumerated.items = 3; 11801da177e4SLinus Torvalds if (uinfo->value.enumerated.item > 2) 11811da177e4SLinus Torvalds uinfo->value.enumerated.item = 2; 11821da177e4SLinus Torvalds strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 11831da177e4SLinus Torvalds return 0; 11841da177e4SLinus Torvalds } 11851da177e4SLinus Torvalds 1186ee42381eSTakashi Iwai static int snd_ac97_stac9758_phonesel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 11871da177e4SLinus Torvalds { 1188ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 11891da177e4SLinus Torvalds 11901da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = ac97->regs[AC97_SIGMATEL_IOMISC] & 3; 11911da177e4SLinus Torvalds return 0; 11921da177e4SLinus Torvalds } 11931da177e4SLinus Torvalds 1194ee42381eSTakashi Iwai static int snd_ac97_stac9758_phonesel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 11951da177e4SLinus Torvalds { 1196ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 11971da177e4SLinus Torvalds 11981da177e4SLinus Torvalds return ac97_update_bits_page(ac97, AC97_SIGMATEL_IOMISC, 3, 11991da177e4SLinus Torvalds ucontrol->value.enumerated.item[0], 0); 12001da177e4SLinus Torvalds } 12011da177e4SLinus Torvalds 12021da177e4SLinus Torvalds #define STAC9758_OUTPUT_JACK(xname, shift) \ 12031da177e4SLinus Torvalds { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 12041da177e4SLinus Torvalds .info = snd_ac97_stac9758_output_jack_info, \ 12051da177e4SLinus Torvalds .get = snd_ac97_stac9758_output_jack_get, \ 12061da177e4SLinus Torvalds .put = snd_ac97_stac9758_output_jack_put, \ 12071da177e4SLinus Torvalds .private_value = shift } 12081da177e4SLinus Torvalds #define STAC9758_INPUT_JACK(xname, shift) \ 12091da177e4SLinus Torvalds { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 12101da177e4SLinus Torvalds .info = snd_ac97_stac9758_input_jack_info, \ 12111da177e4SLinus Torvalds .get = snd_ac97_stac9758_input_jack_get, \ 12121da177e4SLinus Torvalds .put = snd_ac97_stac9758_input_jack_put, \ 12131da177e4SLinus Torvalds .private_value = shift } 1214ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_sigmatel_stac9758_controls[] = { 12151da177e4SLinus Torvalds STAC9758_OUTPUT_JACK("Mic1 Jack", 1), 12161da177e4SLinus Torvalds STAC9758_OUTPUT_JACK("LineIn Jack", 4), 12171da177e4SLinus Torvalds STAC9758_OUTPUT_JACK("Front Jack", 7), 12181da177e4SLinus Torvalds STAC9758_OUTPUT_JACK("Rear Jack", 10), 12191da177e4SLinus Torvalds STAC9758_OUTPUT_JACK("Center/LFE Jack", 13), 12201da177e4SLinus Torvalds STAC9758_INPUT_JACK("Mic Input Source", 0), 12211da177e4SLinus Torvalds STAC9758_INPUT_JACK("Line Input Source", 8), 12221da177e4SLinus Torvalds { 12231da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 12241da177e4SLinus Torvalds .name = "Headphone Amp", 12251da177e4SLinus Torvalds .info = snd_ac97_stac9758_phonesel_info, 12261da177e4SLinus Torvalds .get = snd_ac97_stac9758_phonesel_get, 12271da177e4SLinus Torvalds .put = snd_ac97_stac9758_phonesel_put 12281da177e4SLinus Torvalds }, 12291da177e4SLinus Torvalds AC97_SINGLE("Exchange Center/LFE", AC97_SIGMATEL_IOMISC, 4, 1, 0), 12301da177e4SLinus Torvalds AC97_SINGLE("Headphone +3dB Boost", AC97_SIGMATEL_IOMISC, 8, 1, 0) 12311da177e4SLinus Torvalds }; 12321da177e4SLinus Torvalds 1233ee42381eSTakashi Iwai static int patch_sigmatel_stac9758_specific(struct snd_ac97 *ac97) 12341da177e4SLinus Torvalds { 12351da177e4SLinus Torvalds int err; 12361da177e4SLinus Torvalds 12371da177e4SLinus Torvalds err = patch_sigmatel_stac97xx_specific(ac97); 12381da177e4SLinus Torvalds if (err < 0) 12391da177e4SLinus Torvalds return err; 12401da177e4SLinus Torvalds err = patch_build_controls(ac97, snd_ac97_sigmatel_stac9758_controls, 12411da177e4SLinus Torvalds ARRAY_SIZE(snd_ac97_sigmatel_stac9758_controls)); 12421da177e4SLinus Torvalds if (err < 0) 12431da177e4SLinus Torvalds return err; 12441da177e4SLinus Torvalds /* DAC-A direct */ 12451da177e4SLinus Torvalds snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Front Playback"); 12461da177e4SLinus Torvalds /* DAC-A to Mix = PCM */ 12471da177e4SLinus Torvalds /* DAC-B direct = Surround */ 12481da177e4SLinus Torvalds /* DAC-B to Mix */ 12491da177e4SLinus Torvalds snd_ac97_rename_vol_ctl(ac97, "Video Playback", "Surround Mix Playback"); 12501da177e4SLinus Torvalds /* DAC-C direct = Center/LFE */ 12511da177e4SLinus Torvalds 12521da177e4SLinus Torvalds return 0; 12531da177e4SLinus Torvalds } 12541da177e4SLinus Torvalds 1255*3e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_sigmatel_stac9758_ops = { 12561da177e4SLinus Torvalds .build_3d = patch_sigmatel_stac9700_3d, 12571da177e4SLinus Torvalds .build_specific = patch_sigmatel_stac9758_specific 12581da177e4SLinus Torvalds }; 12591da177e4SLinus Torvalds 1260ac519028STakashi Iwai static int patch_sigmatel_stac9758(struct snd_ac97 * ac97) 12611da177e4SLinus Torvalds { 12621da177e4SLinus Torvalds static unsigned short regs[4] = { 12631da177e4SLinus Torvalds AC97_SIGMATEL_OUTSEL, 12641da177e4SLinus Torvalds AC97_SIGMATEL_IOMISC, 12651da177e4SLinus Torvalds AC97_SIGMATEL_INSEL, 12661da177e4SLinus Torvalds AC97_SIGMATEL_VARIOUS 12671da177e4SLinus Torvalds }; 12681da177e4SLinus Torvalds static unsigned short def_regs[4] = { 12691da177e4SLinus Torvalds /* OUTSEL */ 0xd794, /* CL:CL, SR:SR, LO:MX, LI:DS, MI:DS */ 12701da177e4SLinus Torvalds /* IOMISC */ 0x2001, 12711da177e4SLinus Torvalds /* INSEL */ 0x0201, /* LI:LI, MI:M1 */ 12721da177e4SLinus Torvalds /* VARIOUS */ 0x0040 12731da177e4SLinus Torvalds }; 12741da177e4SLinus Torvalds static unsigned short m675_regs[4] = { 12751da177e4SLinus Torvalds /* OUTSEL */ 0xfc70, /* CL:MX, SR:MX, LO:DS, LI:MX, MI:DS */ 12761da177e4SLinus Torvalds /* IOMISC */ 0x2102, /* HP amp on */ 12771da177e4SLinus Torvalds /* INSEL */ 0x0203, /* LI:LI, MI:FR */ 12781da177e4SLinus Torvalds /* VARIOUS */ 0x0041 /* stereo mic */ 12791da177e4SLinus Torvalds }; 12801da177e4SLinus Torvalds unsigned short *pregs = def_regs; 12811da177e4SLinus Torvalds int i; 12821da177e4SLinus Torvalds 12831da177e4SLinus Torvalds /* Gateway M675 notebook */ 12841da177e4SLinus Torvalds if (ac97->pci && 12851da177e4SLinus Torvalds ac97->subsystem_vendor == 0x107b && 12861da177e4SLinus Torvalds ac97->subsystem_device == 0x0601) 12871da177e4SLinus Torvalds pregs = m675_regs; 12881da177e4SLinus Torvalds 12891da177e4SLinus Torvalds // patch for SigmaTel 12901da177e4SLinus Torvalds ac97->build_ops = &patch_sigmatel_stac9758_ops; 12911da177e4SLinus Torvalds /* FIXME: assume only page 0 for writing cache */ 12921da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR); 12931da177e4SLinus Torvalds for (i = 0; i < 4; i++) 12941da177e4SLinus Torvalds snd_ac97_write_cache(ac97, regs[i], pregs[i]); 12951da177e4SLinus Torvalds 12961da177e4SLinus Torvalds ac97->flags |= AC97_STEREO_MUTES; 12971da177e4SLinus Torvalds return 0; 12981da177e4SLinus Torvalds } 12991da177e4SLinus Torvalds 13001da177e4SLinus Torvalds /* 13011da177e4SLinus Torvalds * Cirrus Logic CS42xx codecs 13021da177e4SLinus Torvalds */ 1303ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_cirrus_controls_spdif[2] = { 13041da177e4SLinus Torvalds AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CSR_SPDIF, 15, 1, 0), 13051da177e4SLinus Torvalds AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "AC97-SPSA", AC97_CSR_ACMODE, 0, 3, 0) 13061da177e4SLinus Torvalds }; 13071da177e4SLinus Torvalds 1308ee42381eSTakashi Iwai static int patch_cirrus_build_spdif(struct snd_ac97 * ac97) 13091da177e4SLinus Torvalds { 13101da177e4SLinus Torvalds int err; 13111da177e4SLinus Torvalds 13121da177e4SLinus Torvalds /* con mask, pro mask, default */ 13131da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0) 13141da177e4SLinus Torvalds return err; 13151da177e4SLinus Torvalds /* switch, spsa */ 13161da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[0], 1)) < 0) 13171da177e4SLinus Torvalds return err; 13181da177e4SLinus Torvalds switch (ac97->id & AC97_ID_CS_MASK) { 13191da177e4SLinus Torvalds case AC97_ID_CS4205: 13201da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[1], 1)) < 0) 13211da177e4SLinus Torvalds return err; 13221da177e4SLinus Torvalds break; 13231da177e4SLinus Torvalds } 13241da177e4SLinus Torvalds /* set default PCM S/PDIF params */ 13251da177e4SLinus Torvalds /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */ 13261da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_CSR_SPDIF, 0x0a20); 13271da177e4SLinus Torvalds return 0; 13281da177e4SLinus Torvalds } 13291da177e4SLinus Torvalds 1330*3e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_cirrus_ops = { 13311da177e4SLinus Torvalds .build_spdif = patch_cirrus_build_spdif 13321da177e4SLinus Torvalds }; 13331da177e4SLinus Torvalds 1334ac519028STakashi Iwai static int patch_cirrus_spdif(struct snd_ac97 * ac97) 13351da177e4SLinus Torvalds { 13361da177e4SLinus Torvalds /* Basically, the cs4201/cs4205/cs4297a has non-standard sp/dif registers. 13371da177e4SLinus Torvalds WHY CAN'T ANYONE FOLLOW THE BLOODY SPEC? *sigh* 13381da177e4SLinus Torvalds - sp/dif EA ID is not set, but sp/dif is always present. 13391da177e4SLinus Torvalds - enable/disable is spdif register bit 15. 13401da177e4SLinus Torvalds - sp/dif control register is 0x68. differs from AC97: 13411da177e4SLinus Torvalds - valid is bit 14 (vs 15) 13421da177e4SLinus Torvalds - no DRS 13431da177e4SLinus Torvalds - only 44.1/48k [00 = 48, 01=44,1] (AC97 is 00=44.1, 10=48) 13441da177e4SLinus Torvalds - sp/dif ssource select is in 0x5e bits 0,1. 13451da177e4SLinus Torvalds */ 13461da177e4SLinus Torvalds 13471da177e4SLinus Torvalds ac97->build_ops = &patch_cirrus_ops; 13481da177e4SLinus Torvalds ac97->flags |= AC97_CS_SPDIF; 13491da177e4SLinus Torvalds ac97->rates[AC97_RATES_SPDIF] &= ~SNDRV_PCM_RATE_32000; 13501da177e4SLinus Torvalds ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */ 13511da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_CSR_ACMODE, 0x0080); 13521da177e4SLinus Torvalds return 0; 13531da177e4SLinus Torvalds } 13541da177e4SLinus Torvalds 1355ac519028STakashi Iwai static int patch_cirrus_cs4299(struct snd_ac97 * ac97) 13561da177e4SLinus Torvalds { 13571da177e4SLinus Torvalds /* force the detection of PC Beep */ 13581da177e4SLinus Torvalds ac97->flags |= AC97_HAS_PC_BEEP; 13591da177e4SLinus Torvalds 13601da177e4SLinus Torvalds return patch_cirrus_spdif(ac97); 13611da177e4SLinus Torvalds } 13621da177e4SLinus Torvalds 13631da177e4SLinus Torvalds /* 13641da177e4SLinus Torvalds * Conexant codecs 13651da177e4SLinus Torvalds */ 1366ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_conexant_controls_spdif[1] = { 13671da177e4SLinus Torvalds AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CXR_AUDIO_MISC, 3, 1, 0), 13681da177e4SLinus Torvalds }; 13691da177e4SLinus Torvalds 1370ee42381eSTakashi Iwai static int patch_conexant_build_spdif(struct snd_ac97 * ac97) 13711da177e4SLinus Torvalds { 13721da177e4SLinus Torvalds int err; 13731da177e4SLinus Torvalds 13741da177e4SLinus Torvalds /* con mask, pro mask, default */ 13751da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0) 13761da177e4SLinus Torvalds return err; 13771da177e4SLinus Torvalds /* switch */ 13781da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_conexant_controls_spdif[0], 1)) < 0) 13791da177e4SLinus Torvalds return err; 13801da177e4SLinus Torvalds /* set default PCM S/PDIF params */ 13811da177e4SLinus Torvalds /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */ 13821da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_CXR_AUDIO_MISC, 13831da177e4SLinus Torvalds snd_ac97_read(ac97, AC97_CXR_AUDIO_MISC) & ~(AC97_CXR_SPDIFEN|AC97_CXR_COPYRGT|AC97_CXR_SPDIF_MASK)); 13841da177e4SLinus Torvalds return 0; 13851da177e4SLinus Torvalds } 13861da177e4SLinus Torvalds 1387*3e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_conexant_ops = { 13881da177e4SLinus Torvalds .build_spdif = patch_conexant_build_spdif 13891da177e4SLinus Torvalds }; 13901da177e4SLinus Torvalds 1391ac519028STakashi Iwai static int patch_conexant(struct snd_ac97 * ac97) 13921da177e4SLinus Torvalds { 13931da177e4SLinus Torvalds ac97->build_ops = &patch_conexant_ops; 13941da177e4SLinus Torvalds ac97->flags |= AC97_CX_SPDIF; 13951da177e4SLinus Torvalds ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */ 13961da177e4SLinus Torvalds ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */ 13971da177e4SLinus Torvalds return 0; 13981da177e4SLinus Torvalds } 13991da177e4SLinus Torvalds 1400ac519028STakashi Iwai static int patch_cx20551(struct snd_ac97 *ac97) 14019e292c00STakashi Iwai { 14029e292c00STakashi Iwai snd_ac97_update_bits(ac97, 0x5c, 0x01, 0x01); 14039e292c00STakashi Iwai return 0; 14049e292c00STakashi Iwai } 14059e292c00STakashi Iwai 14061da177e4SLinus Torvalds /* 14071da177e4SLinus Torvalds * Analog Device AD18xx, AD19xx codecs 14081da177e4SLinus Torvalds */ 14091da177e4SLinus Torvalds #ifdef CONFIG_PM 1410ee42381eSTakashi Iwai static void ad18xx_resume(struct snd_ac97 *ac97) 14111da177e4SLinus Torvalds { 14121da177e4SLinus Torvalds static unsigned short setup_regs[] = { 14131da177e4SLinus Torvalds AC97_AD_MISC, AC97_AD_SERIAL_CFG, AC97_AD_JACK_SPDIF, 14141da177e4SLinus Torvalds }; 14151da177e4SLinus Torvalds int i, codec; 14161da177e4SLinus Torvalds 14171da177e4SLinus Torvalds for (i = 0; i < (int)ARRAY_SIZE(setup_regs); i++) { 14181da177e4SLinus Torvalds unsigned short reg = setup_regs[i]; 14191da177e4SLinus Torvalds if (test_bit(reg, ac97->reg_accessed)) { 14201da177e4SLinus Torvalds snd_ac97_write(ac97, reg, ac97->regs[reg]); 14211da177e4SLinus Torvalds snd_ac97_read(ac97, reg); 14221da177e4SLinus Torvalds } 14231da177e4SLinus Torvalds } 14241da177e4SLinus Torvalds 14251da177e4SLinus Torvalds if (! (ac97->flags & AC97_AD_MULTI)) 14261da177e4SLinus Torvalds /* normal restore */ 14271da177e4SLinus Torvalds snd_ac97_restore_status(ac97); 14281da177e4SLinus Torvalds else { 14291da177e4SLinus Torvalds /* restore the AD18xx codec configurations */ 14301da177e4SLinus Torvalds for (codec = 0; codec < 3; codec++) { 14311da177e4SLinus Torvalds if (! ac97->spec.ad18xx.id[codec]) 14321da177e4SLinus Torvalds continue; 14331da177e4SLinus Torvalds /* select single codec */ 14341da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 14351da177e4SLinus Torvalds ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]); 14361da177e4SLinus Torvalds ac97->bus->ops->write(ac97, AC97_AD_CODEC_CFG, ac97->spec.ad18xx.codec_cfg[codec]); 14371da177e4SLinus Torvalds } 14381da177e4SLinus Torvalds /* select all codecs */ 14391da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000); 14401da177e4SLinus Torvalds 14411da177e4SLinus Torvalds /* restore status */ 14421da177e4SLinus Torvalds for (i = 2; i < 0x7c ; i += 2) { 14431da177e4SLinus Torvalds if (i == AC97_POWERDOWN || i == AC97_EXTENDED_ID) 14441da177e4SLinus Torvalds continue; 14451da177e4SLinus Torvalds if (test_bit(i, ac97->reg_accessed)) { 14461da177e4SLinus Torvalds /* handle multi codecs for AD18xx */ 14471da177e4SLinus Torvalds if (i == AC97_PCM) { 14481da177e4SLinus Torvalds for (codec = 0; codec < 3; codec++) { 14491da177e4SLinus Torvalds if (! ac97->spec.ad18xx.id[codec]) 14501da177e4SLinus Torvalds continue; 14511da177e4SLinus Torvalds /* select single codec */ 14521da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 14531da177e4SLinus Torvalds ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]); 14541da177e4SLinus Torvalds /* update PCM bits */ 14551da177e4SLinus Torvalds ac97->bus->ops->write(ac97, AC97_PCM, ac97->spec.ad18xx.pcmreg[codec]); 14561da177e4SLinus Torvalds } 14571da177e4SLinus Torvalds /* select all codecs */ 14581da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000); 14591da177e4SLinus Torvalds continue; 14601da177e4SLinus Torvalds } else if (i == AC97_AD_TEST || 14611da177e4SLinus Torvalds i == AC97_AD_CODEC_CFG || 14621da177e4SLinus Torvalds i == AC97_AD_SERIAL_CFG) 14631da177e4SLinus Torvalds continue; /* ignore */ 14641da177e4SLinus Torvalds } 14651da177e4SLinus Torvalds snd_ac97_write(ac97, i, ac97->regs[i]); 14661da177e4SLinus Torvalds snd_ac97_read(ac97, i); 14671da177e4SLinus Torvalds } 14681da177e4SLinus Torvalds } 14691da177e4SLinus Torvalds 14701da177e4SLinus Torvalds snd_ac97_restore_iec958(ac97); 14711da177e4SLinus Torvalds } 14721561f09aSJaya Kumar 14731561f09aSJaya Kumar static void ad1888_resume(struct snd_ac97 *ac97) 14741561f09aSJaya Kumar { 14751561f09aSJaya Kumar ad18xx_resume(ac97); 14761561f09aSJaya Kumar snd_ac97_write_cache(ac97, AC97_CODEC_CLASS_REV, 0x8080); 14771561f09aSJaya Kumar } 14781561f09aSJaya Kumar 14791da177e4SLinus Torvalds #endif 14801da177e4SLinus Torvalds 1481bd25b7caSVille Syrjala static const struct snd_ac97_res_table ad1819_restbl[] = { 1482bd25b7caSVille Syrjala { AC97_PHONE, 0x9f1f }, 1483bd25b7caSVille Syrjala { AC97_MIC, 0x9f1f }, 1484bd25b7caSVille Syrjala { AC97_LINE, 0x9f1f }, 1485bd25b7caSVille Syrjala { AC97_CD, 0x9f1f }, 1486bd25b7caSVille Syrjala { AC97_VIDEO, 0x9f1f }, 1487bd25b7caSVille Syrjala { AC97_AUX, 0x9f1f }, 1488bd25b7caSVille Syrjala { AC97_PCM, 0x9f1f }, 1489bd25b7caSVille Syrjala { } /* terminator */ 1490bd25b7caSVille Syrjala }; 1491bd25b7caSVille Syrjala 1492ac519028STakashi Iwai static int patch_ad1819(struct snd_ac97 * ac97) 14931da177e4SLinus Torvalds { 14941da177e4SLinus Torvalds unsigned short scfg; 14951da177e4SLinus Torvalds 14961da177e4SLinus Torvalds // patch for Analog Devices 14971da177e4SLinus Torvalds scfg = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG); 14981da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, scfg | 0x7000); /* select all codecs */ 1499bd25b7caSVille Syrjala ac97->res_table = ad1819_restbl; 15001da177e4SLinus Torvalds return 0; 15011da177e4SLinus Torvalds } 15021da177e4SLinus Torvalds 1503ee42381eSTakashi Iwai static unsigned short patch_ad1881_unchained(struct snd_ac97 * ac97, int idx, unsigned short mask) 15041da177e4SLinus Torvalds { 15051da177e4SLinus Torvalds unsigned short val; 15061da177e4SLinus Torvalds 15071da177e4SLinus Torvalds // test for unchained codec 15081da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, mask); 15091da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000); /* ID0C, ID1C, SDIE = off */ 15101da177e4SLinus Torvalds val = snd_ac97_read(ac97, AC97_VENDOR_ID2); 15111da177e4SLinus Torvalds if ((val & 0xff40) != 0x5340) 15121da177e4SLinus Torvalds return 0; 15131da177e4SLinus Torvalds ac97->spec.ad18xx.unchained[idx] = mask; 15141da177e4SLinus Torvalds ac97->spec.ad18xx.id[idx] = val; 15151da177e4SLinus Torvalds ac97->spec.ad18xx.codec_cfg[idx] = 0x0000; 15161da177e4SLinus Torvalds return mask; 15171da177e4SLinus Torvalds } 15181da177e4SLinus Torvalds 1519ee42381eSTakashi Iwai static int patch_ad1881_chained1(struct snd_ac97 * ac97, int idx, unsigned short codec_bits) 15201da177e4SLinus Torvalds { 15211da177e4SLinus Torvalds static int cfg_bits[3] = { 1<<12, 1<<14, 1<<13 }; 15221da177e4SLinus Torvalds unsigned short val; 15231da177e4SLinus Torvalds 15241da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, cfg_bits[idx]); 15251da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0004); // SDIE 15261da177e4SLinus Torvalds val = snd_ac97_read(ac97, AC97_VENDOR_ID2); 15271da177e4SLinus Torvalds if ((val & 0xff40) != 0x5340) 15281da177e4SLinus Torvalds return 0; 15291da177e4SLinus Torvalds if (codec_bits) 15301da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, codec_bits); 15311da177e4SLinus Torvalds ac97->spec.ad18xx.chained[idx] = cfg_bits[idx]; 15321da177e4SLinus Torvalds ac97->spec.ad18xx.id[idx] = val; 15331da177e4SLinus Torvalds ac97->spec.ad18xx.codec_cfg[idx] = codec_bits ? codec_bits : 0x0004; 15341da177e4SLinus Torvalds return 1; 15351da177e4SLinus Torvalds } 15361da177e4SLinus Torvalds 1537ee42381eSTakashi Iwai static void patch_ad1881_chained(struct snd_ac97 * ac97, int unchained_idx, int cidx1, int cidx2) 15381da177e4SLinus Torvalds { 15391da177e4SLinus Torvalds // already detected? 15401da177e4SLinus Torvalds if (ac97->spec.ad18xx.unchained[cidx1] || ac97->spec.ad18xx.chained[cidx1]) 15411da177e4SLinus Torvalds cidx1 = -1; 15421da177e4SLinus Torvalds if (ac97->spec.ad18xx.unchained[cidx2] || ac97->spec.ad18xx.chained[cidx2]) 15431da177e4SLinus Torvalds cidx2 = -1; 15441da177e4SLinus Torvalds if (cidx1 < 0 && cidx2 < 0) 15451da177e4SLinus Torvalds return; 15461da177e4SLinus Torvalds // test for chained codecs 15471da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 15481da177e4SLinus Torvalds ac97->spec.ad18xx.unchained[unchained_idx]); 15491da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0002); // ID1C 15501da177e4SLinus Torvalds ac97->spec.ad18xx.codec_cfg[unchained_idx] = 0x0002; 15511da177e4SLinus Torvalds if (cidx1 >= 0) { 1552c19bcdc6STakashi Iwai if (cidx2 < 0) 1553c19bcdc6STakashi Iwai patch_ad1881_chained1(ac97, cidx1, 0); 1554c19bcdc6STakashi Iwai else if (patch_ad1881_chained1(ac97, cidx1, 0x0006)) // SDIE | ID1C 15551da177e4SLinus Torvalds patch_ad1881_chained1(ac97, cidx2, 0); 15561da177e4SLinus Torvalds else if (patch_ad1881_chained1(ac97, cidx2, 0x0006)) // SDIE | ID1C 15571da177e4SLinus Torvalds patch_ad1881_chained1(ac97, cidx1, 0); 15581da177e4SLinus Torvalds } else if (cidx2 >= 0) { 15591da177e4SLinus Torvalds patch_ad1881_chained1(ac97, cidx2, 0); 15601da177e4SLinus Torvalds } 15611da177e4SLinus Torvalds } 15621da177e4SLinus Torvalds 1563*3e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ad1881_build_ops = { 15641da177e4SLinus Torvalds #ifdef CONFIG_PM 15651da177e4SLinus Torvalds .resume = ad18xx_resume 15661da177e4SLinus Torvalds #endif 15671da177e4SLinus Torvalds }; 15681da177e4SLinus Torvalds 1569ac519028STakashi Iwai static int patch_ad1881(struct snd_ac97 * ac97) 15701da177e4SLinus Torvalds { 15711da177e4SLinus Torvalds static const char cfg_idxs[3][2] = { 15721da177e4SLinus Torvalds {2, 1}, 15731da177e4SLinus Torvalds {0, 2}, 15741da177e4SLinus Torvalds {0, 1} 15751da177e4SLinus Torvalds }; 15761da177e4SLinus Torvalds 15771da177e4SLinus Torvalds // patch for Analog Devices 15781da177e4SLinus Torvalds unsigned short codecs[3]; 15791da177e4SLinus Torvalds unsigned short val; 15801da177e4SLinus Torvalds int idx, num; 15811da177e4SLinus Torvalds 15821da177e4SLinus Torvalds val = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG); 15831da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, val); 15841da177e4SLinus Torvalds codecs[0] = patch_ad1881_unchained(ac97, 0, (1<<12)); 15851da177e4SLinus Torvalds codecs[1] = patch_ad1881_unchained(ac97, 1, (1<<14)); 15861da177e4SLinus Torvalds codecs[2] = patch_ad1881_unchained(ac97, 2, (1<<13)); 15871da177e4SLinus Torvalds 15887c22f1aaSTakashi Iwai if (! (codecs[0] || codecs[1] || codecs[2])) 15897c22f1aaSTakashi Iwai goto __end; 15901da177e4SLinus Torvalds 15911da177e4SLinus Torvalds for (idx = 0; idx < 3; idx++) 15921da177e4SLinus Torvalds if (ac97->spec.ad18xx.unchained[idx]) 15931da177e4SLinus Torvalds patch_ad1881_chained(ac97, idx, cfg_idxs[idx][0], cfg_idxs[idx][1]); 15941da177e4SLinus Torvalds 15951da177e4SLinus Torvalds if (ac97->spec.ad18xx.id[1]) { 15961da177e4SLinus Torvalds ac97->flags |= AC97_AD_MULTI; 15971da177e4SLinus Torvalds ac97->scaps |= AC97_SCAP_SURROUND_DAC; 15981da177e4SLinus Torvalds } 15991da177e4SLinus Torvalds if (ac97->spec.ad18xx.id[2]) { 16001da177e4SLinus Torvalds ac97->flags |= AC97_AD_MULTI; 16011da177e4SLinus Torvalds ac97->scaps |= AC97_SCAP_CENTER_LFE_DAC; 16021da177e4SLinus Torvalds } 16031da177e4SLinus Torvalds 16041da177e4SLinus Torvalds __end: 16051da177e4SLinus Torvalds /* select all codecs */ 16061da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000); 16071da177e4SLinus Torvalds /* check if only one codec is present */ 16081da177e4SLinus Torvalds for (idx = num = 0; idx < 3; idx++) 16091da177e4SLinus Torvalds if (ac97->spec.ad18xx.id[idx]) 16101da177e4SLinus Torvalds num++; 16111da177e4SLinus Torvalds if (num == 1) { 16121da177e4SLinus Torvalds /* ok, deselect all ID bits */ 16131da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000); 16141da177e4SLinus Torvalds ac97->spec.ad18xx.codec_cfg[0] = 16151da177e4SLinus Torvalds ac97->spec.ad18xx.codec_cfg[1] = 16161da177e4SLinus Torvalds ac97->spec.ad18xx.codec_cfg[2] = 0x0000; 16171da177e4SLinus Torvalds } 16181da177e4SLinus Torvalds /* required for AD1886/AD1885 combination */ 16191da177e4SLinus Torvalds ac97->ext_id = snd_ac97_read(ac97, AC97_EXTENDED_ID); 16201da177e4SLinus Torvalds if (ac97->spec.ad18xx.id[0]) { 16211da177e4SLinus Torvalds ac97->id &= 0xffff0000; 16221da177e4SLinus Torvalds ac97->id |= ac97->spec.ad18xx.id[0]; 16231da177e4SLinus Torvalds } 16241da177e4SLinus Torvalds ac97->build_ops = &patch_ad1881_build_ops; 16251da177e4SLinus Torvalds return 0; 16261da177e4SLinus Torvalds } 16271da177e4SLinus Torvalds 1628ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_ad1885[] = { 16291da177e4SLinus Torvalds AC97_SINGLE("Digital Mono Direct", AC97_AD_MISC, 11, 1, 0), 16301da177e4SLinus Torvalds /* AC97_SINGLE("Digital Audio Mode", AC97_AD_MISC, 12, 1, 0), */ /* seems problematic */ 16311da177e4SLinus Torvalds AC97_SINGLE("Low Power Mixer", AC97_AD_MISC, 14, 1, 0), 16321da177e4SLinus Torvalds AC97_SINGLE("Zero Fill DAC", AC97_AD_MISC, 15, 1, 0), 16331da177e4SLinus Torvalds AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 9, 1, 1), /* inverted */ 16341da177e4SLinus Torvalds AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 8, 1, 1), /* inverted */ 16351da177e4SLinus Torvalds }; 16361da177e4SLinus Torvalds 16370cb29ea0STakashi Iwai static const DECLARE_TLV_DB_SCALE(db_scale_6bit_6db_max, -8850, 150, 0); 16382f3482fbSTakashi Iwai 1639ee42381eSTakashi Iwai static int patch_ad1885_specific(struct snd_ac97 * ac97) 16401da177e4SLinus Torvalds { 16411da177e4SLinus Torvalds int err; 16421da177e4SLinus Torvalds 16431da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, snd_ac97_controls_ad1885, ARRAY_SIZE(snd_ac97_controls_ad1885))) < 0) 16441da177e4SLinus Torvalds return err; 16452f3482fbSTakashi Iwai reset_tlv(ac97, "Headphone Playback Volume", 16462f3482fbSTakashi Iwai db_scale_6bit_6db_max); 16471da177e4SLinus Torvalds return 0; 16481da177e4SLinus Torvalds } 16491da177e4SLinus Torvalds 1650*3e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ad1885_build_ops = { 16511da177e4SLinus Torvalds .build_specific = &patch_ad1885_specific, 16521da177e4SLinus Torvalds #ifdef CONFIG_PM 16531da177e4SLinus Torvalds .resume = ad18xx_resume 16541da177e4SLinus Torvalds #endif 16551da177e4SLinus Torvalds }; 16561da177e4SLinus Torvalds 1657ac519028STakashi Iwai static int patch_ad1885(struct snd_ac97 * ac97) 16581da177e4SLinus Torvalds { 16591da177e4SLinus Torvalds patch_ad1881(ac97); 16601da177e4SLinus Torvalds /* This is required to deal with the Intel D815EEAL2 */ 16611da177e4SLinus Torvalds /* i.e. Line out is actually headphone out from codec */ 16621da177e4SLinus Torvalds 16631da177e4SLinus Torvalds /* set default */ 16641da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_AD_MISC, 0x0404); 16651da177e4SLinus Torvalds 16661da177e4SLinus Torvalds ac97->build_ops = &patch_ad1885_build_ops; 16671da177e4SLinus Torvalds return 0; 16681da177e4SLinus Torvalds } 16691da177e4SLinus Torvalds 16702f3482fbSTakashi Iwai static int patch_ad1886_specific(struct snd_ac97 * ac97) 16712f3482fbSTakashi Iwai { 16722f3482fbSTakashi Iwai reset_tlv(ac97, "Headphone Playback Volume", 16732f3482fbSTakashi Iwai db_scale_6bit_6db_max); 16742f3482fbSTakashi Iwai return 0; 16752f3482fbSTakashi Iwai } 16762f3482fbSTakashi Iwai 1677*3e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ad1886_build_ops = { 16782f3482fbSTakashi Iwai .build_specific = &patch_ad1886_specific, 16792f3482fbSTakashi Iwai #ifdef CONFIG_PM 16802f3482fbSTakashi Iwai .resume = ad18xx_resume 16812f3482fbSTakashi Iwai #endif 16822f3482fbSTakashi Iwai }; 16832f3482fbSTakashi Iwai 1684ac519028STakashi Iwai static int patch_ad1886(struct snd_ac97 * ac97) 16851da177e4SLinus Torvalds { 16861da177e4SLinus Torvalds patch_ad1881(ac97); 16871da177e4SLinus Torvalds /* Presario700 workaround */ 16881da177e4SLinus Torvalds /* for Jack Sense/SPDIF Register misetting causing */ 16891da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_AD_JACK_SPDIF, 0x0010); 16902f3482fbSTakashi Iwai ac97->build_ops = &patch_ad1886_build_ops; 16911da177e4SLinus Torvalds return 0; 16921da177e4SLinus Torvalds } 16931da177e4SLinus Torvalds 169467e9f4b6SRandy Cushman /* MISC bits (AD1888/AD1980/AD1985 register 0x76) */ 16951da177e4SLinus Torvalds #define AC97_AD198X_MBC 0x0003 /* mic boost */ 16961da177e4SLinus Torvalds #define AC97_AD198X_MBC_20 0x0000 /* +20dB */ 16971da177e4SLinus Torvalds #define AC97_AD198X_MBC_10 0x0001 /* +10dB */ 16981da177e4SLinus Torvalds #define AC97_AD198X_MBC_30 0x0002 /* +30dB */ 16991da177e4SLinus Torvalds #define AC97_AD198X_VREFD 0x0004 /* VREF high-Z */ 17006428ea1bSRandy Cushman #define AC97_AD198X_VREFH 0x0008 /* 0=2.25V, 1=3.7V */ 17016428ea1bSRandy Cushman #define AC97_AD198X_VREF_0 0x000c /* 0V (AD1985 only) */ 17026428ea1bSRandy Cushman #define AC97_AD198X_VREF_MASK (AC97_AD198X_VREFH | AC97_AD198X_VREFD) 17036428ea1bSRandy Cushman #define AC97_AD198X_VREF_SHIFT 2 17041da177e4SLinus Torvalds #define AC97_AD198X_SRU 0x0010 /* sample rate unlock */ 17051da177e4SLinus Torvalds #define AC97_AD198X_LOSEL 0x0020 /* LINE_OUT amplifiers input select */ 17061da177e4SLinus Torvalds #define AC97_AD198X_2MIC 0x0040 /* 2-channel mic select */ 17071da177e4SLinus Torvalds #define AC97_AD198X_SPRD 0x0080 /* SPREAD enable */ 17086428ea1bSRandy Cushman #define AC97_AD198X_DMIX0 0x0100 /* downmix mode: */ 17096428ea1bSRandy Cushman /* 0 = 6-to-4, 1 = 6-to-2 downmix */ 17101da177e4SLinus Torvalds #define AC97_AD198X_DMIX1 0x0200 /* downmix mode: 1 = enabled */ 17111da177e4SLinus Torvalds #define AC97_AD198X_HPSEL 0x0400 /* headphone amplifier input select */ 17121da177e4SLinus Torvalds #define AC97_AD198X_CLDIS 0x0800 /* center/lfe disable */ 17131da177e4SLinus Torvalds #define AC97_AD198X_LODIS 0x1000 /* LINE_OUT disable */ 17141da177e4SLinus Torvalds #define AC97_AD198X_MSPLT 0x2000 /* mute split */ 17151da177e4SLinus Torvalds #define AC97_AD198X_AC97NC 0x4000 /* AC97 no compatible mode */ 17161da177e4SLinus Torvalds #define AC97_AD198X_DACZ 0x8000 /* DAC zero-fill mode */ 17171da177e4SLinus Torvalds 171867e9f4b6SRandy Cushman /* MISC 1 bits (AD1986 register 0x76) */ 171967e9f4b6SRandy Cushman #define AC97_AD1986_MBC 0x0003 /* mic boost */ 172067e9f4b6SRandy Cushman #define AC97_AD1986_MBC_20 0x0000 /* +20dB */ 172167e9f4b6SRandy Cushman #define AC97_AD1986_MBC_10 0x0001 /* +10dB */ 172267e9f4b6SRandy Cushman #define AC97_AD1986_MBC_30 0x0002 /* +30dB */ 172367e9f4b6SRandy Cushman #define AC97_AD1986_LISEL0 0x0004 /* LINE_IN select bit 0 */ 172467e9f4b6SRandy Cushman #define AC97_AD1986_LISEL1 0x0008 /* LINE_IN select bit 1 */ 172567e9f4b6SRandy Cushman #define AC97_AD1986_LISEL_MASK (AC97_AD1986_LISEL1 | AC97_AD1986_LISEL0) 172667e9f4b6SRandy Cushman #define AC97_AD1986_LISEL_LI 0x0000 /* LINE_IN pins as LINE_IN source */ 172767e9f4b6SRandy Cushman #define AC97_AD1986_LISEL_SURR 0x0004 /* SURROUND pins as LINE_IN source */ 172867e9f4b6SRandy Cushman #define AC97_AD1986_LISEL_MIC 0x0008 /* MIC_1/2 pins as LINE_IN source */ 172967e9f4b6SRandy Cushman #define AC97_AD1986_SRU 0x0010 /* sample rate unlock */ 173067e9f4b6SRandy Cushman #define AC97_AD1986_SOSEL 0x0020 /* SURROUND_OUT amplifiers input sel */ 173167e9f4b6SRandy Cushman #define AC97_AD1986_2MIC 0x0040 /* 2-channel mic select */ 173267e9f4b6SRandy Cushman #define AC97_AD1986_SPRD 0x0080 /* SPREAD enable */ 173367e9f4b6SRandy Cushman #define AC97_AD1986_DMIX0 0x0100 /* downmix mode: */ 173467e9f4b6SRandy Cushman /* 0 = 6-to-4, 1 = 6-to-2 downmix */ 173567e9f4b6SRandy Cushman #define AC97_AD1986_DMIX1 0x0200 /* downmix mode: 1 = enabled */ 173667e9f4b6SRandy Cushman #define AC97_AD1986_CLDIS 0x0800 /* center/lfe disable */ 173767e9f4b6SRandy Cushman #define AC97_AD1986_SODIS 0x1000 /* SURROUND_OUT disable */ 173867e9f4b6SRandy Cushman #define AC97_AD1986_MSPLT 0x2000 /* mute split (read only 1) */ 173967e9f4b6SRandy Cushman #define AC97_AD1986_AC97NC 0x4000 /* AC97 no compatible mode (r/o 1) */ 174067e9f4b6SRandy Cushman #define AC97_AD1986_DACZ 0x8000 /* DAC zero-fill mode */ 174167e9f4b6SRandy Cushman 174267e9f4b6SRandy Cushman /* MISC 2 bits (AD1986 register 0x70) */ 174367e9f4b6SRandy Cushman #define AC97_AD_MISC2 0x70 /* Misc Control Bits 2 (AD1986) */ 174467e9f4b6SRandy Cushman 174567e9f4b6SRandy Cushman #define AC97_AD1986_CVREF0 0x0004 /* C/LFE VREF_OUT 2.25V */ 174667e9f4b6SRandy Cushman #define AC97_AD1986_CVREF1 0x0008 /* C/LFE VREF_OUT 0V */ 174767e9f4b6SRandy Cushman #define AC97_AD1986_CVREF2 0x0010 /* C/LFE VREF_OUT 3.7V */ 174867e9f4b6SRandy Cushman #define AC97_AD1986_CVREF_MASK \ 174967e9f4b6SRandy Cushman (AC97_AD1986_CVREF2 | AC97_AD1986_CVREF1 | AC97_AD1986_CVREF0) 175067e9f4b6SRandy Cushman #define AC97_AD1986_JSMAP 0x0020 /* Jack Sense Mapping 1 = alternate */ 175167e9f4b6SRandy Cushman #define AC97_AD1986_MMDIS 0x0080 /* Mono Mute Disable */ 175267e9f4b6SRandy Cushman #define AC97_AD1986_MVREF0 0x0400 /* MIC VREF_OUT 2.25V */ 175367e9f4b6SRandy Cushman #define AC97_AD1986_MVREF1 0x0800 /* MIC VREF_OUT 0V */ 175467e9f4b6SRandy Cushman #define AC97_AD1986_MVREF2 0x1000 /* MIC VREF_OUT 3.7V */ 175567e9f4b6SRandy Cushman #define AC97_AD1986_MVREF_MASK \ 175667e9f4b6SRandy Cushman (AC97_AD1986_MVREF2 | AC97_AD1986_MVREF1 | AC97_AD1986_MVREF0) 175767e9f4b6SRandy Cushman 175867e9f4b6SRandy Cushman /* MISC 3 bits (AD1986 register 0x7a) */ 175967e9f4b6SRandy Cushman #define AC97_AD_MISC3 0x7a /* Misc Control Bits 3 (AD1986) */ 176067e9f4b6SRandy Cushman 176167e9f4b6SRandy Cushman #define AC97_AD1986_MMIX 0x0004 /* Mic Mix, left/right */ 176267e9f4b6SRandy Cushman #define AC97_AD1986_GPO 0x0008 /* General Purpose Out */ 176367e9f4b6SRandy Cushman #define AC97_AD1986_LOHPEN 0x0010 /* LINE_OUT headphone drive */ 176467e9f4b6SRandy Cushman #define AC97_AD1986_LVREF0 0x0100 /* LINE_OUT VREF_OUT 2.25V */ 176567e9f4b6SRandy Cushman #define AC97_AD1986_LVREF1 0x0200 /* LINE_OUT VREF_OUT 0V */ 176667e9f4b6SRandy Cushman #define AC97_AD1986_LVREF2 0x0400 /* LINE_OUT VREF_OUT 3.7V */ 176767e9f4b6SRandy Cushman #define AC97_AD1986_LVREF_MASK \ 176867e9f4b6SRandy Cushman (AC97_AD1986_LVREF2 | AC97_AD1986_LVREF1 | AC97_AD1986_LVREF0) 176967e9f4b6SRandy Cushman #define AC97_AD1986_JSINVA 0x0800 /* Jack Sense Invert SENSE_A */ 177067e9f4b6SRandy Cushman #define AC97_AD1986_LOSEL 0x1000 /* LINE_OUT amplifiers input select */ 177167e9f4b6SRandy Cushman #define AC97_AD1986_HPSEL0 0x2000 /* Headphone amplifiers */ 177267e9f4b6SRandy Cushman /* input select Surround DACs */ 177367e9f4b6SRandy Cushman #define AC97_AD1986_HPSEL1 0x4000 /* Headphone amplifiers input */ 177467e9f4b6SRandy Cushman /* select C/LFE DACs */ 177567e9f4b6SRandy Cushman #define AC97_AD1986_JSINVB 0x8000 /* Jack Sense Invert SENSE_B */ 177667e9f4b6SRandy Cushman 177767e9f4b6SRandy Cushman /* Serial Config bits (AD1986 register 0x74) (incomplete) */ 177867e9f4b6SRandy Cushman #define AC97_AD1986_OMS0 0x0100 /* Optional Mic Selector bit 0 */ 177967e9f4b6SRandy Cushman #define AC97_AD1986_OMS1 0x0200 /* Optional Mic Selector bit 1 */ 178067e9f4b6SRandy Cushman #define AC97_AD1986_OMS2 0x0400 /* Optional Mic Selector bit 2 */ 178167e9f4b6SRandy Cushman #define AC97_AD1986_OMS_MASK \ 178267e9f4b6SRandy Cushman (AC97_AD1986_OMS2 | AC97_AD1986_OMS1 | AC97_AD1986_OMS0) 178367e9f4b6SRandy Cushman #define AC97_AD1986_OMS_M 0x0000 /* MIC_1/2 pins are MIC sources */ 178467e9f4b6SRandy Cushman #define AC97_AD1986_OMS_L 0x0100 /* LINE_IN pins are MIC sources */ 178567e9f4b6SRandy Cushman #define AC97_AD1986_OMS_C 0x0200 /* Center/LFE pins are MCI sources */ 178667e9f4b6SRandy Cushman #define AC97_AD1986_OMS_MC 0x0400 /* Mix of MIC and C/LFE pins */ 178767e9f4b6SRandy Cushman /* are MIC sources */ 178867e9f4b6SRandy Cushman #define AC97_AD1986_OMS_ML 0x0500 /* MIX of MIC and LINE_IN pins */ 178967e9f4b6SRandy Cushman /* are MIC sources */ 179067e9f4b6SRandy Cushman #define AC97_AD1986_OMS_LC 0x0600 /* MIX of LINE_IN and C/LFE pins */ 179167e9f4b6SRandy Cushman /* are MIC sources */ 179267e9f4b6SRandy Cushman #define AC97_AD1986_OMS_MLC 0x0700 /* MIX of MIC, LINE_IN, C/LFE pins */ 179367e9f4b6SRandy Cushman /* are MIC sources */ 179467e9f4b6SRandy Cushman 17951da177e4SLinus Torvalds 1796ee42381eSTakashi Iwai static int snd_ac97_ad198x_spdif_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 17971da177e4SLinus Torvalds { 17981da177e4SLinus Torvalds static char *texts[2] = { "AC-Link", "A/D Converter" }; 17991da177e4SLinus Torvalds 18001da177e4SLinus Torvalds uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 18011da177e4SLinus Torvalds uinfo->count = 1; 18021da177e4SLinus Torvalds uinfo->value.enumerated.items = 2; 18031da177e4SLinus Torvalds if (uinfo->value.enumerated.item > 1) 18041da177e4SLinus Torvalds uinfo->value.enumerated.item = 1; 18051da177e4SLinus Torvalds strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 18061da177e4SLinus Torvalds return 0; 18071da177e4SLinus Torvalds } 18081da177e4SLinus Torvalds 1809ee42381eSTakashi Iwai static int snd_ac97_ad198x_spdif_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 18101da177e4SLinus Torvalds { 1811ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 18121da177e4SLinus Torvalds unsigned short val; 18131da177e4SLinus Torvalds 18141da177e4SLinus Torvalds val = ac97->regs[AC97_AD_SERIAL_CFG]; 18151da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = (val >> 2) & 1; 18161da177e4SLinus Torvalds return 0; 18171da177e4SLinus Torvalds } 18181da177e4SLinus Torvalds 1819ee42381eSTakashi Iwai static int snd_ac97_ad198x_spdif_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 18201da177e4SLinus Torvalds { 1821ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 18221da177e4SLinus Torvalds unsigned short val; 18231da177e4SLinus Torvalds 18241da177e4SLinus Torvalds if (ucontrol->value.enumerated.item[0] > 1) 18251da177e4SLinus Torvalds return -EINVAL; 18261da177e4SLinus Torvalds val = ucontrol->value.enumerated.item[0] << 2; 18271da177e4SLinus Torvalds return snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x0004, val); 18281da177e4SLinus Torvalds } 18291da177e4SLinus Torvalds 1830ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ad198x_spdif_source = { 18311da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 18321da177e4SLinus Torvalds .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source", 18331da177e4SLinus Torvalds .info = snd_ac97_ad198x_spdif_source_info, 18341da177e4SLinus Torvalds .get = snd_ac97_ad198x_spdif_source_get, 18351da177e4SLinus Torvalds .put = snd_ac97_ad198x_spdif_source_put, 18361da177e4SLinus Torvalds }; 18371da177e4SLinus Torvalds 1838ee42381eSTakashi Iwai static int patch_ad198x_post_spdif(struct snd_ac97 * ac97) 18391da177e4SLinus Torvalds { 18401da177e4SLinus Torvalds return patch_build_controls(ac97, &snd_ac97_ad198x_spdif_source, 1); 18411da177e4SLinus Torvalds } 18421da177e4SLinus Torvalds 1843ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ad1981x_jack_sense[] = { 18441da177e4SLinus Torvalds AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 11, 1, 0), 18451da177e4SLinus Torvalds AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0), 18461da177e4SLinus Torvalds }; 18471da177e4SLinus Torvalds 1848128a46a5STakashi Iwai /* black list to avoid HP/Line jack-sense controls 1849128a46a5STakashi Iwai * (SS vendor << 16 | device) 1850128a46a5STakashi Iwai */ 1851128a46a5STakashi Iwai static unsigned int ad1981_jacks_blacklist[] = { 1852a31e8c72STakashi Iwai 0x10140523, /* Thinkpad R40 */ 1853a31e8c72STakashi Iwai 0x10140534, /* Thinkpad X31 */ 1854a43c4d4dSTakashi Iwai 0x10140537, /* Thinkpad T41p */ 1855e1f7f02bSDaniel T Chen 0x1014053e, /* Thinkpad R40e */ 1856128a46a5STakashi Iwai 0x10140554, /* Thinkpad T42p/R50p */ 18578286c53eSDaniel T Chen 0x10140567, /* Thinkpad T43p 2668-G7U */ 18588286c53eSDaniel T Chen 0x10140581, /* Thinkpad X41-2527 */ 1859af9a75ddSDaniel T Chen 0x10280160, /* Dell Dimension 2400 */ 18608286c53eSDaniel T Chen 0x104380b0, /* Asus A7V8X-MX */ 18618286c53eSDaniel T Chen 0x11790241, /* Toshiba Satellite A-15 S127 */ 18625cd165e7SDaniel Chen 0x1179ff10, /* Toshiba P500 */ 18638286c53eSDaniel T Chen 0x144dc01a, /* Samsung NP-X20C004/SEG */ 1864128a46a5STakashi Iwai 0 /* end */ 1865128a46a5STakashi Iwai }; 1866128a46a5STakashi Iwai 1867128a46a5STakashi Iwai static int check_list(struct snd_ac97 *ac97, const unsigned int *list) 1868128a46a5STakashi Iwai { 1869128a46a5STakashi Iwai u32 subid = ((u32)ac97->subsystem_vendor << 16) | ac97->subsystem_device; 1870128a46a5STakashi Iwai for (; *list; list++) 1871128a46a5STakashi Iwai if (*list == subid) 1872128a46a5STakashi Iwai return 1; 1873128a46a5STakashi Iwai return 0; 1874128a46a5STakashi Iwai } 1875128a46a5STakashi Iwai 1876ee42381eSTakashi Iwai static int patch_ad1981a_specific(struct snd_ac97 * ac97) 18771da177e4SLinus Torvalds { 1878128a46a5STakashi Iwai if (check_list(ac97, ad1981_jacks_blacklist)) 1879128a46a5STakashi Iwai return 0; 18801da177e4SLinus Torvalds return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense, 18811da177e4SLinus Torvalds ARRAY_SIZE(snd_ac97_ad1981x_jack_sense)); 18821da177e4SLinus Torvalds } 18831da177e4SLinus Torvalds 1884*3e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ad1981a_build_ops = { 18851da177e4SLinus Torvalds .build_post_spdif = patch_ad198x_post_spdif, 18861da177e4SLinus Torvalds .build_specific = patch_ad1981a_specific, 18871da177e4SLinus Torvalds #ifdef CONFIG_PM 18881da177e4SLinus Torvalds .resume = ad18xx_resume 18891da177e4SLinus Torvalds #endif 18901da177e4SLinus Torvalds }; 18911da177e4SLinus Torvalds 1892128a46a5STakashi Iwai /* white list to enable HP jack-sense bits 1893128a46a5STakashi Iwai * (SS vendor << 16 | device) 1894128a46a5STakashi Iwai */ 1895128a46a5STakashi Iwai static unsigned int ad1981_jacks_whitelist[] = { 1896128a46a5STakashi Iwai 0x0e11005a, /* HP nc4000/4010 */ 1897128a46a5STakashi Iwai 0x103c0890, /* HP nc6000 */ 1898128a46a5STakashi Iwai 0x103c0938, /* HP nc4220 */ 1899128a46a5STakashi Iwai 0x103c099c, /* HP nx6110 */ 1900128a46a5STakashi Iwai 0x103c0944, /* HP nc6220 */ 1901128a46a5STakashi Iwai 0x103c0934, /* HP nc8220 */ 1902128a46a5STakashi Iwai 0x103c006d, /* HP nx9105 */ 1903128a46a5STakashi Iwai 0x17340088, /* FSC Scenic-W */ 1904128a46a5STakashi Iwai 0 /* end */ 1905128a46a5STakashi Iwai }; 1906128a46a5STakashi Iwai 1907ee42381eSTakashi Iwai static void check_ad1981_hp_jack_sense(struct snd_ac97 *ac97) 19081da177e4SLinus Torvalds { 1909128a46a5STakashi Iwai if (check_list(ac97, ad1981_jacks_whitelist)) 19101da177e4SLinus Torvalds /* enable headphone jack sense */ 19111da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_AD_JACK_SPDIF, 1<<11, 1<<11); 19121da177e4SLinus Torvalds } 19131da177e4SLinus Torvalds 1914ac519028STakashi Iwai static int patch_ad1981a(struct snd_ac97 *ac97) 19151da177e4SLinus Torvalds { 19161da177e4SLinus Torvalds patch_ad1881(ac97); 19171da177e4SLinus Torvalds ac97->build_ops = &patch_ad1981a_build_ops; 19181da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT); 19191da177e4SLinus Torvalds ac97->flags |= AC97_STEREO_MUTES; 19201da177e4SLinus Torvalds check_ad1981_hp_jack_sense(ac97); 19211da177e4SLinus Torvalds return 0; 19221da177e4SLinus Torvalds } 19231da177e4SLinus Torvalds 1924ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ad198x_2cmic = 19251da177e4SLinus Torvalds AC97_SINGLE("Stereo Mic", AC97_AD_MISC, 6, 1, 0); 19261da177e4SLinus Torvalds 1927ee42381eSTakashi Iwai static int patch_ad1981b_specific(struct snd_ac97 *ac97) 19281da177e4SLinus Torvalds { 19291da177e4SLinus Torvalds int err; 19301da177e4SLinus Torvalds 19311da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0) 19321da177e4SLinus Torvalds return err; 1933128a46a5STakashi Iwai if (check_list(ac97, ad1981_jacks_blacklist)) 1934128a46a5STakashi Iwai return 0; 19351da177e4SLinus Torvalds return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense, 19361da177e4SLinus Torvalds ARRAY_SIZE(snd_ac97_ad1981x_jack_sense)); 19371da177e4SLinus Torvalds } 19381da177e4SLinus Torvalds 1939*3e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ad1981b_build_ops = { 19401da177e4SLinus Torvalds .build_post_spdif = patch_ad198x_post_spdif, 19411da177e4SLinus Torvalds .build_specific = patch_ad1981b_specific, 19421da177e4SLinus Torvalds #ifdef CONFIG_PM 19431da177e4SLinus Torvalds .resume = ad18xx_resume 19441da177e4SLinus Torvalds #endif 19451da177e4SLinus Torvalds }; 19461da177e4SLinus Torvalds 1947ac519028STakashi Iwai static int patch_ad1981b(struct snd_ac97 *ac97) 19481da177e4SLinus Torvalds { 19491da177e4SLinus Torvalds patch_ad1881(ac97); 19501da177e4SLinus Torvalds ac97->build_ops = &patch_ad1981b_build_ops; 19511da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT); 19521da177e4SLinus Torvalds ac97->flags |= AC97_STEREO_MUTES; 19531da177e4SLinus Torvalds check_ad1981_hp_jack_sense(ac97); 19541da177e4SLinus Torvalds return 0; 19551da177e4SLinus Torvalds } 19561da177e4SLinus Torvalds 1957a5ce8890STakashi Iwai #define snd_ac97_ad1888_lohpsel_info snd_ctl_boolean_mono_info 19581da177e4SLinus Torvalds 1959ee42381eSTakashi Iwai static int snd_ac97_ad1888_lohpsel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 19601da177e4SLinus Torvalds { 1961ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 19621da177e4SLinus Torvalds unsigned short val; 19631da177e4SLinus Torvalds 19641da177e4SLinus Torvalds val = ac97->regs[AC97_AD_MISC]; 19651da177e4SLinus Torvalds ucontrol->value.integer.value[0] = !(val & AC97_AD198X_LOSEL); 1966e48d6d97STakashi Iwai if (ac97->spec.ad18xx.lo_as_master) 1967e48d6d97STakashi Iwai ucontrol->value.integer.value[0] = 1968e48d6d97STakashi Iwai !ucontrol->value.integer.value[0]; 19691da177e4SLinus Torvalds return 0; 19701da177e4SLinus Torvalds } 19711da177e4SLinus Torvalds 1972ee42381eSTakashi Iwai static int snd_ac97_ad1888_lohpsel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 19731da177e4SLinus Torvalds { 1974ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 19751da177e4SLinus Torvalds unsigned short val; 19761da177e4SLinus Torvalds 1977e48d6d97STakashi Iwai val = !ucontrol->value.integer.value[0]; 1978e48d6d97STakashi Iwai if (ac97->spec.ad18xx.lo_as_master) 1979e48d6d97STakashi Iwai val = !val; 1980e48d6d97STakashi Iwai val = val ? (AC97_AD198X_LOSEL | AC97_AD198X_HPSEL) : 0; 19811da177e4SLinus Torvalds return snd_ac97_update_bits(ac97, AC97_AD_MISC, 19821da177e4SLinus Torvalds AC97_AD198X_LOSEL | AC97_AD198X_HPSEL, val); 19831da177e4SLinus Torvalds } 19841da177e4SLinus Torvalds 1985ee42381eSTakashi Iwai static int snd_ac97_ad1888_downmix_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 19861da177e4SLinus Torvalds { 19871da177e4SLinus Torvalds static char *texts[3] = {"Off", "6 -> 4", "6 -> 2"}; 19881da177e4SLinus Torvalds 19891da177e4SLinus Torvalds uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 19901da177e4SLinus Torvalds uinfo->count = 1; 19911da177e4SLinus Torvalds uinfo->value.enumerated.items = 3; 19921da177e4SLinus Torvalds if (uinfo->value.enumerated.item > 2) 19931da177e4SLinus Torvalds uinfo->value.enumerated.item = 2; 19941da177e4SLinus Torvalds strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 19951da177e4SLinus Torvalds return 0; 19961da177e4SLinus Torvalds } 19971da177e4SLinus Torvalds 1998ee42381eSTakashi Iwai static int snd_ac97_ad1888_downmix_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 19991da177e4SLinus Torvalds { 2000ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 20011da177e4SLinus Torvalds unsigned short val; 20021da177e4SLinus Torvalds 20031da177e4SLinus Torvalds val = ac97->regs[AC97_AD_MISC]; 20041da177e4SLinus Torvalds if (!(val & AC97_AD198X_DMIX1)) 20051da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = 0; 20061da177e4SLinus Torvalds else 20071da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = 1 + ((val >> 8) & 1); 20081da177e4SLinus Torvalds return 0; 20091da177e4SLinus Torvalds } 20101da177e4SLinus Torvalds 2011ee42381eSTakashi Iwai static int snd_ac97_ad1888_downmix_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 20121da177e4SLinus Torvalds { 2013ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 20141da177e4SLinus Torvalds unsigned short val; 20151da177e4SLinus Torvalds 20161da177e4SLinus Torvalds if (ucontrol->value.enumerated.item[0] > 2) 20171da177e4SLinus Torvalds return -EINVAL; 20181da177e4SLinus Torvalds if (ucontrol->value.enumerated.item[0] == 0) 20191da177e4SLinus Torvalds val = 0; 20201da177e4SLinus Torvalds else 20211da177e4SLinus Torvalds val = AC97_AD198X_DMIX1 | 20221da177e4SLinus Torvalds ((ucontrol->value.enumerated.item[0] - 1) << 8); 20231da177e4SLinus Torvalds return snd_ac97_update_bits(ac97, AC97_AD_MISC, 20241da177e4SLinus Torvalds AC97_AD198X_DMIX0 | AC97_AD198X_DMIX1, val); 20251da177e4SLinus Torvalds } 20261da177e4SLinus Torvalds 2027ee42381eSTakashi Iwai static void ad1888_update_jacks(struct snd_ac97 *ac97) 2028eb8caf30STakashi Iwai { 20294525c9f3STakashi Iwai unsigned short val = 0; 2030c26a8de2SRandy Cushman /* clear LODIS if shared jack is to be used for Surround out */ 2031e48d6d97STakashi Iwai if (!ac97->spec.ad18xx.lo_as_master && is_shared_linein(ac97)) 20324525c9f3STakashi Iwai val |= (1 << 12); 2033c26a8de2SRandy Cushman /* clear CLDIS if shared jack is to be used for C/LFE out */ 2034c26a8de2SRandy Cushman if (is_shared_micin(ac97)) 20354525c9f3STakashi Iwai val |= (1 << 11); 2036eb8caf30STakashi Iwai /* shared Line-In */ 20374525c9f3STakashi Iwai snd_ac97_update_bits(ac97, AC97_AD_MISC, (1 << 11) | (1 << 12), val); 2038eb8caf30STakashi Iwai } 2039eb8caf30STakashi Iwai 2040ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ad1888_controls[] = { 20411da177e4SLinus Torvalds { 20421da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 20431da177e4SLinus Torvalds .name = "Exchange Front/Surround", 20441da177e4SLinus Torvalds .info = snd_ac97_ad1888_lohpsel_info, 20451da177e4SLinus Torvalds .get = snd_ac97_ad1888_lohpsel_get, 20461da177e4SLinus Torvalds .put = snd_ac97_ad1888_lohpsel_put 20471da177e4SLinus Torvalds }, 20480bed7b29SAndres Salomon AC97_SINGLE("V_REFOUT Enable", AC97_AD_MISC, AC97_AD_VREFD_SHIFT, 1, 1), 20490bed7b29SAndres Salomon AC97_SINGLE("High Pass Filter Enable", AC97_AD_TEST2, 20500bed7b29SAndres Salomon AC97_AD_HPFD_SHIFT, 1, 1), 20511da177e4SLinus Torvalds AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC, 7, 1, 0), 20521da177e4SLinus Torvalds { 20531da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 20541da177e4SLinus Torvalds .name = "Downmix", 20551da177e4SLinus Torvalds .info = snd_ac97_ad1888_downmix_info, 20561da177e4SLinus Torvalds .get = snd_ac97_ad1888_downmix_get, 20571da177e4SLinus Torvalds .put = snd_ac97_ad1888_downmix_put 20581da177e4SLinus Torvalds }, 2059eb8caf30STakashi Iwai AC97_SURROUND_JACK_MODE_CTL, 2060eb8caf30STakashi Iwai AC97_CHANNEL_MODE_CTL, 2061eeacb545SSergey Ulanov 2062eeacb545SSergey Ulanov AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0), 2063eeacb545SSergey Ulanov AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0), 20641da177e4SLinus Torvalds }; 20651da177e4SLinus Torvalds 2066ee42381eSTakashi Iwai static int patch_ad1888_specific(struct snd_ac97 *ac97) 20671da177e4SLinus Torvalds { 2068e48d6d97STakashi Iwai if (!ac97->spec.ad18xx.lo_as_master) { 20691da177e4SLinus Torvalds /* rename 0x04 as "Master" and 0x02 as "Master Surround" */ 2070e48d6d97STakashi Iwai snd_ac97_rename_vol_ctl(ac97, "Master Playback", 2071e48d6d97STakashi Iwai "Master Surround Playback"); 2072e48d6d97STakashi Iwai snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", 2073e48d6d97STakashi Iwai "Master Playback"); 2074e48d6d97STakashi Iwai } 20751da177e4SLinus Torvalds return patch_build_controls(ac97, snd_ac97_ad1888_controls, ARRAY_SIZE(snd_ac97_ad1888_controls)); 20761da177e4SLinus Torvalds } 20771da177e4SLinus Torvalds 2078*3e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ad1888_build_ops = { 20791da177e4SLinus Torvalds .build_post_spdif = patch_ad198x_post_spdif, 20801da177e4SLinus Torvalds .build_specific = patch_ad1888_specific, 20811da177e4SLinus Torvalds #ifdef CONFIG_PM 20821561f09aSJaya Kumar .resume = ad1888_resume, 20831da177e4SLinus Torvalds #endif 2084eb8caf30STakashi Iwai .update_jacks = ad1888_update_jacks, 20851da177e4SLinus Torvalds }; 20861da177e4SLinus Torvalds 2087ac519028STakashi Iwai static int patch_ad1888(struct snd_ac97 * ac97) 20881da177e4SLinus Torvalds { 20891da177e4SLinus Torvalds unsigned short misc; 20901da177e4SLinus Torvalds 20911da177e4SLinus Torvalds patch_ad1881(ac97); 20921da177e4SLinus Torvalds ac97->build_ops = &patch_ad1888_build_ops; 2093e48d6d97STakashi Iwai 2094e48d6d97STakashi Iwai /* 2095e48d6d97STakashi Iwai * LO can be used as a real line-out on some devices, 2096e48d6d97STakashi Iwai * and we need to revert the front/surround mixer switches 2097e48d6d97STakashi Iwai */ 2098e48d6d97STakashi Iwai if (ac97->subsystem_vendor == 0x1043 && 2099e48d6d97STakashi Iwai ac97->subsystem_device == 0x1193) /* ASUS A9T laptop */ 2100e48d6d97STakashi Iwai ac97->spec.ad18xx.lo_as_master = 1; 2101e48d6d97STakashi Iwai 2102e48d6d97STakashi Iwai misc = snd_ac97_read(ac97, AC97_AD_MISC); 21031da177e4SLinus Torvalds /* AD-compatible mode */ 21041da177e4SLinus Torvalds /* Stereo mutes enabled */ 2105e48d6d97STakashi Iwai misc |= AC97_AD198X_MSPLT | AC97_AD198X_AC97NC; 2106e48d6d97STakashi Iwai if (!ac97->spec.ad18xx.lo_as_master) 2107e48d6d97STakashi Iwai /* Switch FRONT/SURROUND LINE-OUT/HP-OUT default connection */ 2108e48d6d97STakashi Iwai /* it seems that most vendors connect line-out connector to 2109e48d6d97STakashi Iwai * headphone out of AC'97 2110e48d6d97STakashi Iwai */ 2111e48d6d97STakashi Iwai misc |= AC97_AD198X_LOSEL | AC97_AD198X_HPSEL; 2112e48d6d97STakashi Iwai 2113e48d6d97STakashi Iwai snd_ac97_write_cache(ac97, AC97_AD_MISC, misc); 21141da177e4SLinus Torvalds ac97->flags |= AC97_STEREO_MUTES; 21151da177e4SLinus Torvalds return 0; 21161da177e4SLinus Torvalds } 21171da177e4SLinus Torvalds 2118ee42381eSTakashi Iwai static int patch_ad1980_specific(struct snd_ac97 *ac97) 21191da177e4SLinus Torvalds { 21201da177e4SLinus Torvalds int err; 21211da177e4SLinus Torvalds 21221da177e4SLinus Torvalds if ((err = patch_ad1888_specific(ac97)) < 0) 21231da177e4SLinus Torvalds return err; 21241da177e4SLinus Torvalds return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1); 21251da177e4SLinus Torvalds } 21261da177e4SLinus Torvalds 2127*3e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ad1980_build_ops = { 21281da177e4SLinus Torvalds .build_post_spdif = patch_ad198x_post_spdif, 21291da177e4SLinus Torvalds .build_specific = patch_ad1980_specific, 21301da177e4SLinus Torvalds #ifdef CONFIG_PM 2131462c4173SClemens Ladisch .resume = ad18xx_resume, 21321da177e4SLinus Torvalds #endif 2133462c4173SClemens Ladisch .update_jacks = ad1888_update_jacks, 21341da177e4SLinus Torvalds }; 21351da177e4SLinus Torvalds 2136ac519028STakashi Iwai static int patch_ad1980(struct snd_ac97 * ac97) 21371da177e4SLinus Torvalds { 21381da177e4SLinus Torvalds patch_ad1888(ac97); 21391da177e4SLinus Torvalds ac97->build_ops = &patch_ad1980_build_ops; 21401da177e4SLinus Torvalds return 0; 21411da177e4SLinus Torvalds } 21421da177e4SLinus Torvalds 21436428ea1bSRandy Cushman static int snd_ac97_ad1985_vrefout_info(struct snd_kcontrol *kcontrol, 21446428ea1bSRandy Cushman struct snd_ctl_elem_info *uinfo) 21456428ea1bSRandy Cushman { 21466428ea1bSRandy Cushman static char *texts[4] = {"High-Z", "3.7 V", "2.25 V", "0 V"}; 21476428ea1bSRandy Cushman 21486428ea1bSRandy Cushman uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 21496428ea1bSRandy Cushman uinfo->count = 1; 21506428ea1bSRandy Cushman uinfo->value.enumerated.items = 4; 21516428ea1bSRandy Cushman if (uinfo->value.enumerated.item > 3) 21526428ea1bSRandy Cushman uinfo->value.enumerated.item = 3; 21536428ea1bSRandy Cushman strcpy(uinfo->value.enumerated.name, 21546428ea1bSRandy Cushman texts[uinfo->value.enumerated.item]); 21556428ea1bSRandy Cushman return 0; 21566428ea1bSRandy Cushman } 21576428ea1bSRandy Cushman 21586428ea1bSRandy Cushman static int snd_ac97_ad1985_vrefout_get(struct snd_kcontrol *kcontrol, 21596428ea1bSRandy Cushman struct snd_ctl_elem_value *ucontrol) 21606428ea1bSRandy Cushman { 21616428ea1bSRandy Cushman static const int reg2ctrl[4] = {2, 0, 1, 3}; 21626428ea1bSRandy Cushman struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 21636428ea1bSRandy Cushman unsigned short val; 21646428ea1bSRandy Cushman val = (ac97->regs[AC97_AD_MISC] & AC97_AD198X_VREF_MASK) 21656428ea1bSRandy Cushman >> AC97_AD198X_VREF_SHIFT; 21666428ea1bSRandy Cushman ucontrol->value.enumerated.item[0] = reg2ctrl[val]; 21676428ea1bSRandy Cushman return 0; 21686428ea1bSRandy Cushman } 21696428ea1bSRandy Cushman 21706428ea1bSRandy Cushman static int snd_ac97_ad1985_vrefout_put(struct snd_kcontrol *kcontrol, 21716428ea1bSRandy Cushman struct snd_ctl_elem_value *ucontrol) 21726428ea1bSRandy Cushman { 21736428ea1bSRandy Cushman static const int ctrl2reg[4] = {1, 2, 0, 3}; 21746428ea1bSRandy Cushman struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 21756428ea1bSRandy Cushman unsigned short val; 21766428ea1bSRandy Cushman 21774e98d6a7STakashi Iwai if (ucontrol->value.enumerated.item[0] > 3) 21786428ea1bSRandy Cushman return -EINVAL; 21796428ea1bSRandy Cushman val = ctrl2reg[ucontrol->value.enumerated.item[0]] 21806428ea1bSRandy Cushman << AC97_AD198X_VREF_SHIFT; 21816428ea1bSRandy Cushman return snd_ac97_update_bits(ac97, AC97_AD_MISC, 21826428ea1bSRandy Cushman AC97_AD198X_VREF_MASK, val); 21836428ea1bSRandy Cushman } 21846428ea1bSRandy Cushman 2185ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ad1985_controls[] = { 21866428ea1bSRandy Cushman AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0), 21876428ea1bSRandy Cushman { 21886428ea1bSRandy Cushman .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 21896428ea1bSRandy Cushman .name = "Exchange Front/Surround", 21906428ea1bSRandy Cushman .info = snd_ac97_ad1888_lohpsel_info, 21916428ea1bSRandy Cushman .get = snd_ac97_ad1888_lohpsel_get, 21926428ea1bSRandy Cushman .put = snd_ac97_ad1888_lohpsel_put 21936428ea1bSRandy Cushman }, 21946428ea1bSRandy Cushman AC97_SINGLE("High Pass Filter Enable", AC97_AD_TEST2, 12, 1, 1), 21956428ea1bSRandy Cushman AC97_SINGLE("Spread Front to Surround and Center/LFE", 21966428ea1bSRandy Cushman AC97_AD_MISC, 7, 1, 0), 21976428ea1bSRandy Cushman { 21986428ea1bSRandy Cushman .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 21996428ea1bSRandy Cushman .name = "Downmix", 22006428ea1bSRandy Cushman .info = snd_ac97_ad1888_downmix_info, 22016428ea1bSRandy Cushman .get = snd_ac97_ad1888_downmix_get, 22026428ea1bSRandy Cushman .put = snd_ac97_ad1888_downmix_put 22036428ea1bSRandy Cushman }, 22046428ea1bSRandy Cushman { 22056428ea1bSRandy Cushman .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 22066428ea1bSRandy Cushman .name = "V_REFOUT", 22076428ea1bSRandy Cushman .info = snd_ac97_ad1985_vrefout_info, 22086428ea1bSRandy Cushman .get = snd_ac97_ad1985_vrefout_get, 22096428ea1bSRandy Cushman .put = snd_ac97_ad1985_vrefout_put 22106428ea1bSRandy Cushman }, 22116428ea1bSRandy Cushman AC97_SURROUND_JACK_MODE_CTL, 22126428ea1bSRandy Cushman AC97_CHANNEL_MODE_CTL, 22136428ea1bSRandy Cushman 22146428ea1bSRandy Cushman AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0), 22156428ea1bSRandy Cushman AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0), 22161da177e4SLinus Torvalds }; 22171da177e4SLinus Torvalds 2218ee42381eSTakashi Iwai static void ad1985_update_jacks(struct snd_ac97 *ac97) 2219e5b3f45fSTakashi Iwai { 22204525c9f3STakashi Iwai ad1888_update_jacks(ac97); 2221c26a8de2SRandy Cushman /* clear OMS if shared jack is to be used for C/LFE out */ 2222fc232c6eSTakashi Iwai snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 1 << 9, 2223c26a8de2SRandy Cushman is_shared_micin(ac97) ? 1 << 9 : 0); 2224e5b3f45fSTakashi Iwai } 2225e5b3f45fSTakashi Iwai 2226ee42381eSTakashi Iwai static int patch_ad1985_specific(struct snd_ac97 *ac97) 22271da177e4SLinus Torvalds { 22281da177e4SLinus Torvalds int err; 22291da177e4SLinus Torvalds 22306428ea1bSRandy Cushman /* rename 0x04 as "Master" and 0x02 as "Master Surround" */ 22316428ea1bSRandy Cushman snd_ac97_rename_vol_ctl(ac97, "Master Playback", 22326428ea1bSRandy Cushman "Master Surround Playback"); 22336428ea1bSRandy Cushman snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback"); 22346428ea1bSRandy Cushman 22356428ea1bSRandy Cushman if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0) 22361da177e4SLinus Torvalds return err; 22376428ea1bSRandy Cushman 22386428ea1bSRandy Cushman return patch_build_controls(ac97, snd_ac97_ad1985_controls, 22396428ea1bSRandy Cushman ARRAY_SIZE(snd_ac97_ad1985_controls)); 22401da177e4SLinus Torvalds } 22411da177e4SLinus Torvalds 2242*3e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ad1985_build_ops = { 22431da177e4SLinus Torvalds .build_post_spdif = patch_ad198x_post_spdif, 22441da177e4SLinus Torvalds .build_specific = patch_ad1985_specific, 22451da177e4SLinus Torvalds #ifdef CONFIG_PM 2246462c4173SClemens Ladisch .resume = ad18xx_resume, 22471da177e4SLinus Torvalds #endif 2248e5b3f45fSTakashi Iwai .update_jacks = ad1985_update_jacks, 22491da177e4SLinus Torvalds }; 22501da177e4SLinus Torvalds 2251ac519028STakashi Iwai static int patch_ad1985(struct snd_ac97 * ac97) 22521da177e4SLinus Torvalds { 22531da177e4SLinus Torvalds unsigned short misc; 22541da177e4SLinus Torvalds 22551da177e4SLinus Torvalds patch_ad1881(ac97); 22561da177e4SLinus Torvalds ac97->build_ops = &patch_ad1985_build_ops; 22571da177e4SLinus Torvalds misc = snd_ac97_read(ac97, AC97_AD_MISC); 22581da177e4SLinus Torvalds /* switch front/surround line-out/hp-out */ 22591da177e4SLinus Torvalds /* AD-compatible mode */ 22601da177e4SLinus Torvalds /* Stereo mutes enabled */ 22611da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_AD_MISC, misc | 22621da177e4SLinus Torvalds AC97_AD198X_LOSEL | 22631da177e4SLinus Torvalds AC97_AD198X_HPSEL | 22641da177e4SLinus Torvalds AC97_AD198X_MSPLT | 22651da177e4SLinus Torvalds AC97_AD198X_AC97NC); 22661da177e4SLinus Torvalds ac97->flags |= AC97_STEREO_MUTES; 22676428ea1bSRandy Cushman 22686428ea1bSRandy Cushman /* update current jack configuration */ 22696428ea1bSRandy Cushman ad1985_update_jacks(ac97); 22706428ea1bSRandy Cushman 22711da177e4SLinus Torvalds /* on AD1985 rev. 3, AC'97 revision bits are zero */ 22721da177e4SLinus Torvalds ac97->ext_id = (ac97->ext_id & ~AC97_EI_REV_MASK) | AC97_EI_REV_23; 22731da177e4SLinus Torvalds return 0; 22741da177e4SLinus Torvalds } 22751da177e4SLinus Torvalds 2276a5ce8890STakashi Iwai #define snd_ac97_ad1986_bool_info snd_ctl_boolean_mono_info 227767e9f4b6SRandy Cushman 227867e9f4b6SRandy Cushman static int snd_ac97_ad1986_lososel_get(struct snd_kcontrol *kcontrol, 227967e9f4b6SRandy Cushman struct snd_ctl_elem_value *ucontrol) 228067e9f4b6SRandy Cushman { 228167e9f4b6SRandy Cushman struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 228267e9f4b6SRandy Cushman unsigned short val; 228367e9f4b6SRandy Cushman 228467e9f4b6SRandy Cushman val = ac97->regs[AC97_AD_MISC3]; 228567e9f4b6SRandy Cushman ucontrol->value.integer.value[0] = (val & AC97_AD1986_LOSEL) != 0; 228667e9f4b6SRandy Cushman return 0; 228767e9f4b6SRandy Cushman } 228867e9f4b6SRandy Cushman 228967e9f4b6SRandy Cushman static int snd_ac97_ad1986_lososel_put(struct snd_kcontrol *kcontrol, 229067e9f4b6SRandy Cushman struct snd_ctl_elem_value *ucontrol) 229167e9f4b6SRandy Cushman { 229267e9f4b6SRandy Cushman struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 229367e9f4b6SRandy Cushman int ret0; 229467e9f4b6SRandy Cushman int ret1; 229567e9f4b6SRandy Cushman int sprd = (ac97->regs[AC97_AD_MISC] & AC97_AD1986_SPRD) != 0; 229667e9f4b6SRandy Cushman 229767e9f4b6SRandy Cushman ret0 = snd_ac97_update_bits(ac97, AC97_AD_MISC3, AC97_AD1986_LOSEL, 229867e9f4b6SRandy Cushman ucontrol->value.integer.value[0] != 0 229967e9f4b6SRandy Cushman ? AC97_AD1986_LOSEL : 0); 230067e9f4b6SRandy Cushman if (ret0 < 0) 230167e9f4b6SRandy Cushman return ret0; 230267e9f4b6SRandy Cushman 230367e9f4b6SRandy Cushman /* SOSEL is set to values of "Spread" or "Exchange F/S" controls */ 230467e9f4b6SRandy Cushman ret1 = snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD1986_SOSEL, 230567e9f4b6SRandy Cushman (ucontrol->value.integer.value[0] != 0 230667e9f4b6SRandy Cushman || sprd) 230767e9f4b6SRandy Cushman ? AC97_AD1986_SOSEL : 0); 230867e9f4b6SRandy Cushman if (ret1 < 0) 230967e9f4b6SRandy Cushman return ret1; 231067e9f4b6SRandy Cushman 231167e9f4b6SRandy Cushman return (ret0 > 0 || ret1 > 0) ? 1 : 0; 231267e9f4b6SRandy Cushman } 231367e9f4b6SRandy Cushman 231467e9f4b6SRandy Cushman static int snd_ac97_ad1986_spread_get(struct snd_kcontrol *kcontrol, 231567e9f4b6SRandy Cushman struct snd_ctl_elem_value *ucontrol) 231667e9f4b6SRandy Cushman { 231767e9f4b6SRandy Cushman struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 231867e9f4b6SRandy Cushman unsigned short val; 231967e9f4b6SRandy Cushman 232067e9f4b6SRandy Cushman val = ac97->regs[AC97_AD_MISC]; 232167e9f4b6SRandy Cushman ucontrol->value.integer.value[0] = (val & AC97_AD1986_SPRD) != 0; 232267e9f4b6SRandy Cushman return 0; 232367e9f4b6SRandy Cushman } 232467e9f4b6SRandy Cushman 232567e9f4b6SRandy Cushman static int snd_ac97_ad1986_spread_put(struct snd_kcontrol *kcontrol, 232667e9f4b6SRandy Cushman struct snd_ctl_elem_value *ucontrol) 232767e9f4b6SRandy Cushman { 232867e9f4b6SRandy Cushman struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 232967e9f4b6SRandy Cushman int ret0; 233067e9f4b6SRandy Cushman int ret1; 233167e9f4b6SRandy Cushman int sprd = (ac97->regs[AC97_AD_MISC3] & AC97_AD1986_LOSEL) != 0; 233267e9f4b6SRandy Cushman 233367e9f4b6SRandy Cushman ret0 = snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD1986_SPRD, 233467e9f4b6SRandy Cushman ucontrol->value.integer.value[0] != 0 233567e9f4b6SRandy Cushman ? AC97_AD1986_SPRD : 0); 233667e9f4b6SRandy Cushman if (ret0 < 0) 233767e9f4b6SRandy Cushman return ret0; 233867e9f4b6SRandy Cushman 233967e9f4b6SRandy Cushman /* SOSEL is set to values of "Spread" or "Exchange F/S" controls */ 234067e9f4b6SRandy Cushman ret1 = snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD1986_SOSEL, 234167e9f4b6SRandy Cushman (ucontrol->value.integer.value[0] != 0 234267e9f4b6SRandy Cushman || sprd) 234367e9f4b6SRandy Cushman ? AC97_AD1986_SOSEL : 0); 234467e9f4b6SRandy Cushman if (ret1 < 0) 234567e9f4b6SRandy Cushman return ret1; 234667e9f4b6SRandy Cushman 234767e9f4b6SRandy Cushman return (ret0 > 0 || ret1 > 0) ? 1 : 0; 234867e9f4b6SRandy Cushman } 234967e9f4b6SRandy Cushman 235067e9f4b6SRandy Cushman static int snd_ac97_ad1986_miclisel_get(struct snd_kcontrol *kcontrol, 235167e9f4b6SRandy Cushman struct snd_ctl_elem_value *ucontrol) 235267e9f4b6SRandy Cushman { 235367e9f4b6SRandy Cushman struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 235467e9f4b6SRandy Cushman 235567e9f4b6SRandy Cushman ucontrol->value.integer.value[0] = ac97->spec.ad18xx.swap_mic_linein; 235667e9f4b6SRandy Cushman return 0; 235767e9f4b6SRandy Cushman } 235867e9f4b6SRandy Cushman 235967e9f4b6SRandy Cushman static int snd_ac97_ad1986_miclisel_put(struct snd_kcontrol *kcontrol, 236067e9f4b6SRandy Cushman struct snd_ctl_elem_value *ucontrol) 236167e9f4b6SRandy Cushman { 236267e9f4b6SRandy Cushman struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 236367e9f4b6SRandy Cushman unsigned char swap = ucontrol->value.integer.value[0] != 0; 236467e9f4b6SRandy Cushman 236567e9f4b6SRandy Cushman if (swap != ac97->spec.ad18xx.swap_mic_linein) { 236667e9f4b6SRandy Cushman ac97->spec.ad18xx.swap_mic_linein = swap; 236767e9f4b6SRandy Cushman if (ac97->build_ops->update_jacks) 236867e9f4b6SRandy Cushman ac97->build_ops->update_jacks(ac97); 236967e9f4b6SRandy Cushman return 1; 237067e9f4b6SRandy Cushman } 237167e9f4b6SRandy Cushman return 0; 237267e9f4b6SRandy Cushman } 237367e9f4b6SRandy Cushman 237467e9f4b6SRandy Cushman static int snd_ac97_ad1986_vrefout_get(struct snd_kcontrol *kcontrol, 237567e9f4b6SRandy Cushman struct snd_ctl_elem_value *ucontrol) 237667e9f4b6SRandy Cushman { 237767e9f4b6SRandy Cushman /* Use MIC_1/2 V_REFOUT as the "get" value */ 237867e9f4b6SRandy Cushman struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 237967e9f4b6SRandy Cushman unsigned short val; 238067e9f4b6SRandy Cushman unsigned short reg = ac97->regs[AC97_AD_MISC2]; 238167e9f4b6SRandy Cushman if ((reg & AC97_AD1986_MVREF0) != 0) 238267e9f4b6SRandy Cushman val = 2; 238367e9f4b6SRandy Cushman else if ((reg & AC97_AD1986_MVREF1) != 0) 238467e9f4b6SRandy Cushman val = 3; 238567e9f4b6SRandy Cushman else if ((reg & AC97_AD1986_MVREF2) != 0) 238667e9f4b6SRandy Cushman val = 1; 238767e9f4b6SRandy Cushman else 238867e9f4b6SRandy Cushman val = 0; 238967e9f4b6SRandy Cushman ucontrol->value.enumerated.item[0] = val; 239067e9f4b6SRandy Cushman return 0; 239167e9f4b6SRandy Cushman } 239267e9f4b6SRandy Cushman 239367e9f4b6SRandy Cushman static int snd_ac97_ad1986_vrefout_put(struct snd_kcontrol *kcontrol, 239467e9f4b6SRandy Cushman struct snd_ctl_elem_value *ucontrol) 239567e9f4b6SRandy Cushman { 239667e9f4b6SRandy Cushman struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 239767e9f4b6SRandy Cushman unsigned short cval; 239867e9f4b6SRandy Cushman unsigned short lval; 239967e9f4b6SRandy Cushman unsigned short mval; 240067e9f4b6SRandy Cushman int cret; 240167e9f4b6SRandy Cushman int lret; 240267e9f4b6SRandy Cushman int mret; 240367e9f4b6SRandy Cushman 240467e9f4b6SRandy Cushman switch (ucontrol->value.enumerated.item[0]) 240567e9f4b6SRandy Cushman { 240667e9f4b6SRandy Cushman case 0: /* High-Z */ 240767e9f4b6SRandy Cushman cval = 0; 240867e9f4b6SRandy Cushman lval = 0; 240967e9f4b6SRandy Cushman mval = 0; 241067e9f4b6SRandy Cushman break; 241167e9f4b6SRandy Cushman case 1: /* 3.7 V */ 241267e9f4b6SRandy Cushman cval = AC97_AD1986_CVREF2; 241367e9f4b6SRandy Cushman lval = AC97_AD1986_LVREF2; 241467e9f4b6SRandy Cushman mval = AC97_AD1986_MVREF2; 241567e9f4b6SRandy Cushman break; 241667e9f4b6SRandy Cushman case 2: /* 2.25 V */ 241767e9f4b6SRandy Cushman cval = AC97_AD1986_CVREF0; 241867e9f4b6SRandy Cushman lval = AC97_AD1986_LVREF0; 241967e9f4b6SRandy Cushman mval = AC97_AD1986_MVREF0; 242067e9f4b6SRandy Cushman break; 242167e9f4b6SRandy Cushman case 3: /* 0 V */ 242267e9f4b6SRandy Cushman cval = AC97_AD1986_CVREF1; 242367e9f4b6SRandy Cushman lval = AC97_AD1986_LVREF1; 242467e9f4b6SRandy Cushman mval = AC97_AD1986_MVREF1; 242567e9f4b6SRandy Cushman break; 242667e9f4b6SRandy Cushman default: 242767e9f4b6SRandy Cushman return -EINVAL; 242867e9f4b6SRandy Cushman } 242967e9f4b6SRandy Cushman 243067e9f4b6SRandy Cushman cret = snd_ac97_update_bits(ac97, AC97_AD_MISC2, 243167e9f4b6SRandy Cushman AC97_AD1986_CVREF_MASK, cval); 243267e9f4b6SRandy Cushman if (cret < 0) 243367e9f4b6SRandy Cushman return cret; 243467e9f4b6SRandy Cushman lret = snd_ac97_update_bits(ac97, AC97_AD_MISC3, 243567e9f4b6SRandy Cushman AC97_AD1986_LVREF_MASK, lval); 243667e9f4b6SRandy Cushman if (lret < 0) 243767e9f4b6SRandy Cushman return lret; 243867e9f4b6SRandy Cushman mret = snd_ac97_update_bits(ac97, AC97_AD_MISC2, 243967e9f4b6SRandy Cushman AC97_AD1986_MVREF_MASK, mval); 244067e9f4b6SRandy Cushman if (mret < 0) 244167e9f4b6SRandy Cushman return mret; 244267e9f4b6SRandy Cushman 244367e9f4b6SRandy Cushman return (cret > 0 || lret > 0 || mret > 0) ? 1 : 0; 244467e9f4b6SRandy Cushman } 244567e9f4b6SRandy Cushman 244667e9f4b6SRandy Cushman static const struct snd_kcontrol_new snd_ac97_ad1986_controls[] = { 244767e9f4b6SRandy Cushman AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0), 244867e9f4b6SRandy Cushman { 244967e9f4b6SRandy Cushman .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 245067e9f4b6SRandy Cushman .name = "Exchange Front/Surround", 245167e9f4b6SRandy Cushman .info = snd_ac97_ad1986_bool_info, 245267e9f4b6SRandy Cushman .get = snd_ac97_ad1986_lososel_get, 245367e9f4b6SRandy Cushman .put = snd_ac97_ad1986_lososel_put 245467e9f4b6SRandy Cushman }, 245567e9f4b6SRandy Cushman { 245667e9f4b6SRandy Cushman .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 245767e9f4b6SRandy Cushman .name = "Exchange Mic/Line In", 245867e9f4b6SRandy Cushman .info = snd_ac97_ad1986_bool_info, 245967e9f4b6SRandy Cushman .get = snd_ac97_ad1986_miclisel_get, 246067e9f4b6SRandy Cushman .put = snd_ac97_ad1986_miclisel_put 246167e9f4b6SRandy Cushman }, 246267e9f4b6SRandy Cushman { 246367e9f4b6SRandy Cushman .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 246467e9f4b6SRandy Cushman .name = "Spread Front to Surround and Center/LFE", 246567e9f4b6SRandy Cushman .info = snd_ac97_ad1986_bool_info, 246667e9f4b6SRandy Cushman .get = snd_ac97_ad1986_spread_get, 246767e9f4b6SRandy Cushman .put = snd_ac97_ad1986_spread_put 246867e9f4b6SRandy Cushman }, 246967e9f4b6SRandy Cushman { 247067e9f4b6SRandy Cushman .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 247167e9f4b6SRandy Cushman .name = "Downmix", 247267e9f4b6SRandy Cushman .info = snd_ac97_ad1888_downmix_info, 247367e9f4b6SRandy Cushman .get = snd_ac97_ad1888_downmix_get, 247467e9f4b6SRandy Cushman .put = snd_ac97_ad1888_downmix_put 247567e9f4b6SRandy Cushman }, 247667e9f4b6SRandy Cushman { 247767e9f4b6SRandy Cushman .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 247867e9f4b6SRandy Cushman .name = "V_REFOUT", 247967e9f4b6SRandy Cushman .info = snd_ac97_ad1985_vrefout_info, 248067e9f4b6SRandy Cushman .get = snd_ac97_ad1986_vrefout_get, 248167e9f4b6SRandy Cushman .put = snd_ac97_ad1986_vrefout_put 248267e9f4b6SRandy Cushman }, 248367e9f4b6SRandy Cushman AC97_SURROUND_JACK_MODE_CTL, 248467e9f4b6SRandy Cushman AC97_CHANNEL_MODE_CTL, 248567e9f4b6SRandy Cushman 248667e9f4b6SRandy Cushman AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0), 248767e9f4b6SRandy Cushman AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0) 248867e9f4b6SRandy Cushman }; 248967e9f4b6SRandy Cushman 249067e9f4b6SRandy Cushman static void ad1986_update_jacks(struct snd_ac97 *ac97) 249167e9f4b6SRandy Cushman { 249267e9f4b6SRandy Cushman unsigned short misc_val = 0; 249367e9f4b6SRandy Cushman unsigned short ser_val; 249467e9f4b6SRandy Cushman 249567e9f4b6SRandy Cushman /* disable SURROUND and CENTER/LFE if not surround mode */ 249667e9f4b6SRandy Cushman if (!is_surround_on(ac97)) 249767e9f4b6SRandy Cushman misc_val |= AC97_AD1986_SODIS; 249867e9f4b6SRandy Cushman if (!is_clfe_on(ac97)) 249967e9f4b6SRandy Cushman misc_val |= AC97_AD1986_CLDIS; 250067e9f4b6SRandy Cushman 250167e9f4b6SRandy Cushman /* select line input (default=LINE_IN, SURROUND or MIC_1/2) */ 250267e9f4b6SRandy Cushman if (is_shared_linein(ac97)) 250367e9f4b6SRandy Cushman misc_val |= AC97_AD1986_LISEL_SURR; 250467e9f4b6SRandy Cushman else if (ac97->spec.ad18xx.swap_mic_linein != 0) 250567e9f4b6SRandy Cushman misc_val |= AC97_AD1986_LISEL_MIC; 250667e9f4b6SRandy Cushman snd_ac97_update_bits(ac97, AC97_AD_MISC, 250767e9f4b6SRandy Cushman AC97_AD1986_SODIS | AC97_AD1986_CLDIS | 250867e9f4b6SRandy Cushman AC97_AD1986_LISEL_MASK, 250967e9f4b6SRandy Cushman misc_val); 251067e9f4b6SRandy Cushman 251167e9f4b6SRandy Cushman /* select microphone input (MIC_1/2, Center/LFE or LINE_IN) */ 251267e9f4b6SRandy Cushman if (is_shared_micin(ac97)) 251367e9f4b6SRandy Cushman ser_val = AC97_AD1986_OMS_C; 251467e9f4b6SRandy Cushman else if (ac97->spec.ad18xx.swap_mic_linein != 0) 251567e9f4b6SRandy Cushman ser_val = AC97_AD1986_OMS_L; 251667e9f4b6SRandy Cushman else 251767e9f4b6SRandy Cushman ser_val = AC97_AD1986_OMS_M; 251867e9f4b6SRandy Cushman snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 251967e9f4b6SRandy Cushman AC97_AD1986_OMS_MASK, 252067e9f4b6SRandy Cushman ser_val); 252167e9f4b6SRandy Cushman } 252267e9f4b6SRandy Cushman 252367e9f4b6SRandy Cushman static int patch_ad1986_specific(struct snd_ac97 *ac97) 252467e9f4b6SRandy Cushman { 252567e9f4b6SRandy Cushman int err; 252667e9f4b6SRandy Cushman 252767e9f4b6SRandy Cushman if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0) 252867e9f4b6SRandy Cushman return err; 252967e9f4b6SRandy Cushman 253067e9f4b6SRandy Cushman return patch_build_controls(ac97, snd_ac97_ad1986_controls, 253167e9f4b6SRandy Cushman ARRAY_SIZE(snd_ac97_ad1985_controls)); 253267e9f4b6SRandy Cushman } 253367e9f4b6SRandy Cushman 2534*3e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ad1986_build_ops = { 253567e9f4b6SRandy Cushman .build_post_spdif = patch_ad198x_post_spdif, 253667e9f4b6SRandy Cushman .build_specific = patch_ad1986_specific, 253767e9f4b6SRandy Cushman #ifdef CONFIG_PM 253867e9f4b6SRandy Cushman .resume = ad18xx_resume, 253967e9f4b6SRandy Cushman #endif 254067e9f4b6SRandy Cushman .update_jacks = ad1986_update_jacks, 254167e9f4b6SRandy Cushman }; 254267e9f4b6SRandy Cushman 2543ac519028STakashi Iwai static int patch_ad1986(struct snd_ac97 * ac97) 254467e9f4b6SRandy Cushman { 254567e9f4b6SRandy Cushman patch_ad1881(ac97); 254667e9f4b6SRandy Cushman ac97->build_ops = &patch_ad1986_build_ops; 254767e9f4b6SRandy Cushman ac97->flags |= AC97_STEREO_MUTES; 254867e9f4b6SRandy Cushman 254967e9f4b6SRandy Cushman /* update current jack configuration */ 255067e9f4b6SRandy Cushman ad1986_update_jacks(ac97); 255167e9f4b6SRandy Cushman 255267e9f4b6SRandy Cushman return 0; 255367e9f4b6SRandy Cushman } 255467e9f4b6SRandy Cushman 25558f4f4ef6STakashi Iwai /* 25568f4f4ef6STakashi Iwai * realtek ALC203: use mono-out for pin 37 25578f4f4ef6STakashi Iwai */ 25588f4f4ef6STakashi Iwai static int patch_alc203(struct snd_ac97 *ac97) 25598f4f4ef6STakashi Iwai { 25608f4f4ef6STakashi Iwai snd_ac97_update_bits(ac97, 0x7a, 0x400, 0x400); 25618f4f4ef6STakashi Iwai return 0; 25628f4f4ef6STakashi Iwai } 256367e9f4b6SRandy Cushman 25641da177e4SLinus Torvalds /* 25651da177e4SLinus Torvalds * realtek ALC65x/850 codecs 25661da177e4SLinus Torvalds */ 2567ee42381eSTakashi Iwai static void alc650_update_jacks(struct snd_ac97 *ac97) 25681da177e4SLinus Torvalds { 2569eb8caf30STakashi Iwai int shared; 25701da177e4SLinus Torvalds 2571831466f4SRandy Cushman /* shared Line-In / Surround Out */ 2572831466f4SRandy Cushman shared = is_shared_surrout(ac97); 2573eb8caf30STakashi Iwai snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 9, 2574eb8caf30STakashi Iwai shared ? (1 << 9) : 0); 2575831466f4SRandy Cushman /* update shared Mic In / Center/LFE Out */ 2576831466f4SRandy Cushman shared = is_shared_clfeout(ac97); 25771da177e4SLinus Torvalds /* disable/enable vref */ 25781da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12, 2579eb8caf30STakashi Iwai shared ? (1 << 12) : 0); 25801da177e4SLinus Torvalds /* turn on/off center-on-mic */ 25811da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 10, 2582eb8caf30STakashi Iwai shared ? (1 << 10) : 0); 25831da177e4SLinus Torvalds /* GPIO0 high for mic */ 25841da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_ALC650_GPIO_STATUS, 0x100, 2585eb8caf30STakashi Iwai shared ? 0 : 0x100); 25861da177e4SLinus Torvalds } 25871da177e4SLinus Torvalds 2588ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_alc650[] = { 25891da177e4SLinus Torvalds AC97_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0), 25901da177e4SLinus Torvalds AC97_SINGLE("Surround Down Mix", AC97_ALC650_MULTICH, 1, 1, 0), 25911da177e4SLinus Torvalds AC97_SINGLE("Center/LFE Down Mix", AC97_ALC650_MULTICH, 2, 1, 0), 25921da177e4SLinus Torvalds AC97_SINGLE("Exchange Center/LFE", AC97_ALC650_MULTICH, 3, 1, 0), 25931da177e4SLinus Torvalds /* 4: Analog Input To Surround */ 25941da177e4SLinus Torvalds /* 5: Analog Input To Center/LFE */ 25951da177e4SLinus Torvalds /* 6: Independent Master Volume Right */ 25961da177e4SLinus Torvalds /* 7: Independent Master Volume Left */ 25971da177e4SLinus Torvalds /* 8: reserved */ 2598eb8caf30STakashi Iwai /* 9: Line-In/Surround share */ 2599eb8caf30STakashi Iwai /* 10: Mic/CLFE share */ 26001da177e4SLinus Torvalds /* 11-13: in IEC958 controls */ 26011da177e4SLinus Torvalds AC97_SINGLE("Swap Surround Slot", AC97_ALC650_MULTICH, 14, 1, 0), 26021da177e4SLinus Torvalds #if 0 /* always set in patch_alc650 */ 26031da177e4SLinus Torvalds AC97_SINGLE("IEC958 Input Clock Enable", AC97_ALC650_CLOCK, 0, 1, 0), 26041da177e4SLinus Torvalds AC97_SINGLE("IEC958 Input Pin Enable", AC97_ALC650_CLOCK, 1, 1, 0), 26051da177e4SLinus Torvalds AC97_SINGLE("Surround DAC Switch", AC97_ALC650_SURR_DAC_VOL, 15, 1, 1), 26061da177e4SLinus Torvalds AC97_DOUBLE("Surround DAC Volume", AC97_ALC650_SURR_DAC_VOL, 8, 0, 31, 1), 26071da177e4SLinus Torvalds AC97_SINGLE("Center/LFE DAC Switch", AC97_ALC650_LFE_DAC_VOL, 15, 1, 1), 26081da177e4SLinus Torvalds AC97_DOUBLE("Center/LFE DAC Volume", AC97_ALC650_LFE_DAC_VOL, 8, 0, 31, 1), 26091da177e4SLinus Torvalds #endif 2610eb8caf30STakashi Iwai AC97_SURROUND_JACK_MODE_CTL, 2611eb8caf30STakashi Iwai AC97_CHANNEL_MODE_CTL, 26121da177e4SLinus Torvalds }; 26131da177e4SLinus Torvalds 2614ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc650[] = { 261510e8d78aSClemens Ladisch AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0), 26161da177e4SLinus Torvalds AC97_SINGLE("Analog to IEC958 Output", AC97_ALC650_MULTICH, 12, 1, 0), 26171da177e4SLinus Torvalds /* disable this controls since it doesn't work as expected */ 26181da177e4SLinus Torvalds /* AC97_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 13, 1, 0), */ 26191da177e4SLinus Torvalds }; 26201da177e4SLinus Torvalds 26210cb29ea0STakashi Iwai static const DECLARE_TLV_DB_SCALE(db_scale_5bit_3db_max, -4350, 150, 0); 26222f3482fbSTakashi Iwai 2623ee42381eSTakashi Iwai static int patch_alc650_specific(struct snd_ac97 * ac97) 26241da177e4SLinus Torvalds { 26251da177e4SLinus Torvalds int err; 26261da177e4SLinus Torvalds 26271da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, snd_ac97_controls_alc650, ARRAY_SIZE(snd_ac97_controls_alc650))) < 0) 26281da177e4SLinus Torvalds return err; 26291da177e4SLinus Torvalds if (ac97->ext_id & AC97_EI_SPDIF) { 26301da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc650, ARRAY_SIZE(snd_ac97_spdif_controls_alc650))) < 0) 26311da177e4SLinus Torvalds return err; 26321da177e4SLinus Torvalds } 26332f3482fbSTakashi Iwai if (ac97->id != AC97_ID_ALC650F) 26342f3482fbSTakashi Iwai reset_tlv(ac97, "Master Playback Volume", 26352f3482fbSTakashi Iwai db_scale_5bit_3db_max); 26361da177e4SLinus Torvalds return 0; 26371da177e4SLinus Torvalds } 26381da177e4SLinus Torvalds 2639*3e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_alc650_ops = { 2640eb8caf30STakashi Iwai .build_specific = patch_alc650_specific, 2641eb8caf30STakashi Iwai .update_jacks = alc650_update_jacks 26421da177e4SLinus Torvalds }; 26431da177e4SLinus Torvalds 2644ac519028STakashi Iwai static int patch_alc650(struct snd_ac97 * ac97) 26451da177e4SLinus Torvalds { 26461da177e4SLinus Torvalds unsigned short val; 26471da177e4SLinus Torvalds 26481da177e4SLinus Torvalds ac97->build_ops = &patch_alc650_ops; 26491da177e4SLinus Torvalds 26501da177e4SLinus Torvalds /* determine the revision */ 26511da177e4SLinus Torvalds val = snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f; 26521da177e4SLinus Torvalds if (val < 3) 26531da177e4SLinus Torvalds ac97->id = 0x414c4720; /* Old version */ 26541da177e4SLinus Torvalds else if (val < 0x10) 26551da177e4SLinus Torvalds ac97->id = 0x414c4721; /* D version */ 26561da177e4SLinus Torvalds else if (val < 0x20) 26571da177e4SLinus Torvalds ac97->id = 0x414c4722; /* E version */ 26581da177e4SLinus Torvalds else if (val < 0x30) 26591da177e4SLinus Torvalds ac97->id = 0x414c4723; /* F version */ 26601da177e4SLinus Torvalds 26611da177e4SLinus Torvalds /* revision E or F */ 26621da177e4SLinus Torvalds /* FIXME: what about revision D ? */ 26631da177e4SLinus Torvalds ac97->spec.dev_flags = (ac97->id == 0x414c4722 || 26641da177e4SLinus Torvalds ac97->id == 0x414c4723); 26651da177e4SLinus Torvalds 26661da177e4SLinus Torvalds /* enable AC97_ALC650_GPIO_SETUP, AC97_ALC650_CLOCK for R/W */ 26671da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS, 26681da177e4SLinus Torvalds snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x8000); 26691da177e4SLinus Torvalds 26701da177e4SLinus Torvalds /* Enable SPDIF-IN only on Rev.E and above */ 26711da177e4SLinus Torvalds val = snd_ac97_read(ac97, AC97_ALC650_CLOCK); 26721da177e4SLinus Torvalds /* SPDIF IN with pin 47 */ 2673eed65649STakashi Iwai if (ac97->spec.dev_flags && 2674eed65649STakashi Iwai /* ASUS A6KM requires EAPD */ 2675eed65649STakashi Iwai ! (ac97->subsystem_vendor == 0x1043 && 2676eed65649STakashi Iwai ac97->subsystem_device == 0x1103)) 26771da177e4SLinus Torvalds val |= 0x03; /* enable */ 26781da177e4SLinus Torvalds else 26791da177e4SLinus Torvalds val &= ~0x03; /* disable */ 26801da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_CLOCK, val); 26811da177e4SLinus Torvalds 26821da177e4SLinus Torvalds /* set default: slot 3,4,7,8,6,9 26831da177e4SLinus Torvalds spdif-in monitor off, analog-spdif off, spdif-in off 26841da177e4SLinus Torvalds center on mic off, surround on line-in off 26851da177e4SLinus Torvalds downmix off, duplicate front off 26861da177e4SLinus Torvalds */ 26871da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 0); 26881da177e4SLinus Torvalds 26891da177e4SLinus Torvalds /* set GPIO0 for mic bias */ 26901da177e4SLinus Torvalds /* GPIO0 pin output, no interrupt, high */ 26911da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_SETUP, 26921da177e4SLinus Torvalds snd_ac97_read(ac97, AC97_ALC650_GPIO_SETUP) | 0x01); 26931da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS, 26941da177e4SLinus Torvalds (snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x100) & ~0x10); 26951da177e4SLinus Torvalds 26961da177e4SLinus Torvalds /* full DAC volume */ 26971da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808); 26981da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808); 26991da177e4SLinus Torvalds return 0; 27001da177e4SLinus Torvalds } 27011da177e4SLinus Torvalds 2702ee42381eSTakashi Iwai static void alc655_update_jacks(struct snd_ac97 *ac97) 27031da177e4SLinus Torvalds { 2704eb8caf30STakashi Iwai int shared; 27051da177e4SLinus Torvalds 2706831466f4SRandy Cushman /* shared Line-In / Surround Out */ 2707831466f4SRandy Cushman shared = is_shared_surrout(ac97); 2708eb8caf30STakashi Iwai ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 9, 2709eb8caf30STakashi Iwai shared ? (1 << 9) : 0, 0); 2710831466f4SRandy Cushman /* update shared Mic In / Center/LFE Out */ 2711831466f4SRandy Cushman shared = is_shared_clfeout(ac97); 27121da177e4SLinus Torvalds /* misc control; vrefout disable */ 27131da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12, 2714eb8caf30STakashi Iwai shared ? (1 << 12) : 0); 2715eb8caf30STakashi Iwai ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 10, 2716eb8caf30STakashi Iwai shared ? (1 << 10) : 0, 0); 27171da177e4SLinus Torvalds } 27181da177e4SLinus Torvalds 2719ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_alc655[] = { 27201da177e4SLinus Torvalds AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0), 2721eb8caf30STakashi Iwai AC97_SURROUND_JACK_MODE_CTL, 2722eb8caf30STakashi Iwai AC97_CHANNEL_MODE_CTL, 27231da177e4SLinus Torvalds }; 27241da177e4SLinus Torvalds 2725ee42381eSTakashi Iwai static int alc655_iec958_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 27261da177e4SLinus Torvalds { 27271da177e4SLinus Torvalds static char *texts_655[3] = { "PCM", "Analog In", "IEC958 In" }; 27281da177e4SLinus Torvalds static char *texts_658[4] = { "PCM", "Analog1 In", "Analog2 In", "IEC958 In" }; 2729ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 27301da177e4SLinus Torvalds 27311da177e4SLinus Torvalds uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 27321da177e4SLinus Torvalds uinfo->count = 1; 27331da177e4SLinus Torvalds uinfo->value.enumerated.items = ac97->spec.dev_flags ? 4 : 3; 27341da177e4SLinus Torvalds if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 27351da177e4SLinus Torvalds uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 27361da177e4SLinus Torvalds strcpy(uinfo->value.enumerated.name, 27371da177e4SLinus Torvalds ac97->spec.dev_flags ? 27381da177e4SLinus Torvalds texts_658[uinfo->value.enumerated.item] : 27391da177e4SLinus Torvalds texts_655[uinfo->value.enumerated.item]); 27401da177e4SLinus Torvalds return 0; 27411da177e4SLinus Torvalds } 27421da177e4SLinus Torvalds 2743ee42381eSTakashi Iwai static int alc655_iec958_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 27441da177e4SLinus Torvalds { 2745ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 27461da177e4SLinus Torvalds unsigned short val; 27471da177e4SLinus Torvalds 27481da177e4SLinus Torvalds val = ac97->regs[AC97_ALC650_MULTICH]; 27491da177e4SLinus Torvalds val = (val >> 12) & 3; 27501da177e4SLinus Torvalds if (ac97->spec.dev_flags && val == 3) 27511da177e4SLinus Torvalds val = 0; 27521da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = val; 27531da177e4SLinus Torvalds return 0; 27541da177e4SLinus Torvalds } 27551da177e4SLinus Torvalds 2756ee42381eSTakashi Iwai static int alc655_iec958_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 27571da177e4SLinus Torvalds { 2758ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 27591da177e4SLinus Torvalds 27601da177e4SLinus Torvalds return ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 3 << 12, 27611da177e4SLinus Torvalds (unsigned short)ucontrol->value.enumerated.item[0] << 12, 27621da177e4SLinus Torvalds 0); 27631da177e4SLinus Torvalds } 27641da177e4SLinus Torvalds 2765ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc655[] = { 276610e8d78aSClemens Ladisch AC97_PAGE_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0, 0), 27671da177e4SLinus Torvalds /* disable this controls since it doesn't work as expected */ 27681da177e4SLinus Torvalds /* AC97_PAGE_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 14, 1, 0, 0), */ 27691da177e4SLinus Torvalds { 27701da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2771031c95d4STakashi Iwai .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source", 27721da177e4SLinus Torvalds .info = alc655_iec958_route_info, 27731da177e4SLinus Torvalds .get = alc655_iec958_route_get, 27741da177e4SLinus Torvalds .put = alc655_iec958_route_put, 27751da177e4SLinus Torvalds }, 27761da177e4SLinus Torvalds }; 27771da177e4SLinus Torvalds 2778ee42381eSTakashi Iwai static int patch_alc655_specific(struct snd_ac97 * ac97) 27791da177e4SLinus Torvalds { 27801da177e4SLinus Torvalds int err; 27811da177e4SLinus Torvalds 27821da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, snd_ac97_controls_alc655, ARRAY_SIZE(snd_ac97_controls_alc655))) < 0) 27831da177e4SLinus Torvalds return err; 27841da177e4SLinus Torvalds if (ac97->ext_id & AC97_EI_SPDIF) { 27851da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0) 27861da177e4SLinus Torvalds return err; 27871da177e4SLinus Torvalds } 27881da177e4SLinus Torvalds return 0; 27891da177e4SLinus Torvalds } 27901da177e4SLinus Torvalds 2791*3e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_alc655_ops = { 2792eb8caf30STakashi Iwai .build_specific = patch_alc655_specific, 2793eb8caf30STakashi Iwai .update_jacks = alc655_update_jacks 27941da177e4SLinus Torvalds }; 27951da177e4SLinus Torvalds 2796ac519028STakashi Iwai static int patch_alc655(struct snd_ac97 * ac97) 27971da177e4SLinus Torvalds { 27981da177e4SLinus Torvalds unsigned int val; 27991da177e4SLinus Torvalds 2800a5022b0dSTakashi Iwai if (ac97->id == AC97_ID_ALC658) { 2801a5022b0dSTakashi Iwai ac97->spec.dev_flags = 1; /* ALC658 */ 2802a5022b0dSTakashi Iwai if ((snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f) == 2) { 2803a5022b0dSTakashi Iwai ac97->id = AC97_ID_ALC658D; 2804a5022b0dSTakashi Iwai ac97->spec.dev_flags = 2; 2805a5022b0dSTakashi Iwai } 2806a5022b0dSTakashi Iwai } 28071da177e4SLinus Torvalds 28081da177e4SLinus Torvalds ac97->build_ops = &patch_alc655_ops; 28091da177e4SLinus Torvalds 28101da177e4SLinus Torvalds /* assume only page 0 for writing cache */ 28111da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR); 28121da177e4SLinus Torvalds 28131da177e4SLinus Torvalds /* adjust default values */ 28141da177e4SLinus Torvalds val = snd_ac97_read(ac97, 0x7a); /* misc control */ 2815a5022b0dSTakashi Iwai if (ac97->spec.dev_flags) /* ALC658 */ 28161da177e4SLinus Torvalds val &= ~(1 << 1); /* Pin 47 is spdif input pin */ 2817ee71508eSTakashi Iwai else { /* ALC655 */ 2818ee71508eSTakashi Iwai if (ac97->subsystem_vendor == 0x1462 && 2819d244bf89SMagnus Sandin (ac97->subsystem_device == 0x0131 || /* MSI S270 laptop */ 2820e7d24f0bSJaroslav Kysela ac97->subsystem_device == 0x0161 || /* LG K1 Express */ 2821cbcc2c4cSJerome Demange ac97->subsystem_device == 0x0351 || /* MSI L725 laptop */ 2822592a82e8STakashi Iwai ac97->subsystem_device == 0x0471 || /* MSI L720 laptop */ 2823cbcc2c4cSJerome Demange ac97->subsystem_device == 0x0061)) /* MSI S250 laptop */ 2824ee71508eSTakashi Iwai val &= ~(1 << 1); /* Pin 47 is EAPD (for internal speaker) */ 2825ee71508eSTakashi Iwai else 28261da177e4SLinus Torvalds val |= (1 << 1); /* Pin 47 is spdif input pin */ 2827c872e8caSTakashi Iwai /* this seems missing on some hardwares */ 2828c872e8caSTakashi Iwai ac97->ext_id |= AC97_EI_SPDIF; 2829ee71508eSTakashi Iwai } 28301da177e4SLinus Torvalds val &= ~(1 << 12); /* vref enable */ 28311da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x7a, val); 28321da177e4SLinus Torvalds /* set default: spdif-in enabled, 28331da177e4SLinus Torvalds spdif-in monitor off, spdif-in PCM off 28341da177e4SLinus Torvalds center on mic off, surround on line-in off 28351da177e4SLinus Torvalds duplicate front off 28361da177e4SLinus Torvalds */ 28371da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15); 28381da177e4SLinus Torvalds 28391da177e4SLinus Torvalds /* full DAC volume */ 28401da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808); 28411da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808); 2842a5022b0dSTakashi Iwai 2843a5022b0dSTakashi Iwai /* update undocumented bit... */ 2844a5022b0dSTakashi Iwai if (ac97->id == AC97_ID_ALC658D) 2845a5022b0dSTakashi Iwai snd_ac97_update_bits(ac97, 0x74, 0x0800, 0x0800); 2846a5022b0dSTakashi Iwai 28471da177e4SLinus Torvalds return 0; 28481da177e4SLinus Torvalds } 28491da177e4SLinus Torvalds 28501da177e4SLinus Torvalds 28511da177e4SLinus Torvalds #define AC97_ALC850_JACK_SELECT 0x76 28521da177e4SLinus Torvalds #define AC97_ALC850_MISC1 0x7a 28534235a317STakashi Iwai #define AC97_ALC850_MULTICH 0x6a 28541da177e4SLinus Torvalds 2855ee42381eSTakashi Iwai static void alc850_update_jacks(struct snd_ac97 *ac97) 28561da177e4SLinus Torvalds { 2857eb8caf30STakashi Iwai int shared; 28584235a317STakashi Iwai int aux_is_back_surround; 28591da177e4SLinus Torvalds 2860831466f4SRandy Cushman /* shared Line-In / Surround Out */ 2861831466f4SRandy Cushman shared = is_shared_surrout(ac97); 28621da177e4SLinus Torvalds /* SURR 1kOhm (bit4), Amp (bit5) */ 28631da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<4)|(1<<5), 2864eb8caf30STakashi Iwai shared ? (1<<5) : (1<<4)); 28651da177e4SLinus Torvalds /* LINE-IN = 0, SURROUND = 2 */ 2866eb8caf30STakashi Iwai snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 12, 2867eb8caf30STakashi Iwai shared ? (2<<12) : (0<<12)); 2868831466f4SRandy Cushman /* update shared Mic In / Center/LFE Out */ 2869831466f4SRandy Cushman shared = is_shared_clfeout(ac97); 28701da177e4SLinus Torvalds /* Vref disable (bit12), 1kOhm (bit13) */ 28711da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<12)|(1<<13), 2872eb8caf30STakashi Iwai shared ? (1<<12) : (1<<13)); 2873da79e44dSTakashi Iwai /* MIC-IN = 1, CENTER-LFE = 5 */ 2874eb8caf30STakashi Iwai snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 4, 2875da79e44dSTakashi Iwai shared ? (5<<4) : (1<<4)); 28764235a317STakashi Iwai 28774235a317STakashi Iwai aux_is_back_surround = alc850_is_aux_back_surround(ac97); 28784235a317STakashi Iwai /* Aux is Back Surround */ 28794235a317STakashi Iwai snd_ac97_update_bits(ac97, AC97_ALC850_MULTICH, 1 << 10, 28804235a317STakashi Iwai aux_is_back_surround ? (1<<10) : (0<<10)); 28811da177e4SLinus Torvalds } 28821da177e4SLinus Torvalds 2883ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_alc850[] = { 28841da177e4SLinus Torvalds AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0), 288567e1b51eSSergey Vlasov AC97_SINGLE("Mic Front Input Switch", AC97_ALC850_JACK_SELECT, 15, 1, 1), 2886eb8caf30STakashi Iwai AC97_SURROUND_JACK_MODE_CTL, 28874235a317STakashi Iwai AC97_CHANNEL_MODE_8CH_CTL, 28881da177e4SLinus Torvalds }; 28891da177e4SLinus Torvalds 2890ee42381eSTakashi Iwai static int patch_alc850_specific(struct snd_ac97 *ac97) 28911da177e4SLinus Torvalds { 28921da177e4SLinus Torvalds int err; 28931da177e4SLinus Torvalds 28941da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, snd_ac97_controls_alc850, ARRAY_SIZE(snd_ac97_controls_alc850))) < 0) 28951da177e4SLinus Torvalds return err; 28961da177e4SLinus Torvalds if (ac97->ext_id & AC97_EI_SPDIF) { 28971da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0) 28981da177e4SLinus Torvalds return err; 28991da177e4SLinus Torvalds } 29001da177e4SLinus Torvalds return 0; 29011da177e4SLinus Torvalds } 29021da177e4SLinus Torvalds 2903*3e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_alc850_ops = { 2904eb8caf30STakashi Iwai .build_specific = patch_alc850_specific, 2905eb8caf30STakashi Iwai .update_jacks = alc850_update_jacks 29061da177e4SLinus Torvalds }; 29071da177e4SLinus Torvalds 2908ac519028STakashi Iwai static int patch_alc850(struct snd_ac97 *ac97) 29091da177e4SLinus Torvalds { 29101da177e4SLinus Torvalds ac97->build_ops = &patch_alc850_ops; 29111da177e4SLinus Torvalds 29121da177e4SLinus Torvalds ac97->spec.dev_flags = 0; /* for IEC958 playback route - ALC655 compatible */ 29134235a317STakashi Iwai ac97->flags |= AC97_HAS_8CH; 29141da177e4SLinus Torvalds 29151da177e4SLinus Torvalds /* assume only page 0 for writing cache */ 29161da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR); 29171da177e4SLinus Torvalds 29181da177e4SLinus Torvalds /* adjust default values */ 29191da177e4SLinus Torvalds /* set default: spdif-in enabled, 29201da177e4SLinus Torvalds spdif-in monitor off, spdif-in PCM off 29211da177e4SLinus Torvalds center on mic off, surround on line-in off 29221da177e4SLinus Torvalds duplicate front off 29234235a317STakashi Iwai NB default bit 10=0 = Aux is Capture, not Back Surround 29241da177e4SLinus Torvalds */ 29251da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15); 29261da177e4SLinus Torvalds /* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off 29271da177e4SLinus Torvalds * Front Amp: on, Vref: enable, Center 1kOhm: on, Mix: on 29281da177e4SLinus Torvalds */ 29291da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x7a, (1<<1)|(1<<4)|(0<<5)|(1<<6)| 29301da177e4SLinus Torvalds (1<<7)|(0<<12)|(1<<13)|(0<<14)); 29311da177e4SLinus Torvalds /* detection UIO2,3: all path floating, UIO3: MIC, Vref2: disable, 29321da177e4SLinus Torvalds * UIO1: FRONT, Vref3: disable, UIO3: LINE, Front-Mic: mute 29331da177e4SLinus Torvalds */ 29341da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x76, (0<<0)|(0<<2)|(1<<4)|(1<<7)|(2<<8)| 29351da177e4SLinus Torvalds (1<<11)|(0<<12)|(1<<15)); 29361da177e4SLinus Torvalds 29371da177e4SLinus Torvalds /* full DAC volume */ 29381da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808); 29391da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808); 29401da177e4SLinus Torvalds return 0; 29411da177e4SLinus Torvalds } 29421da177e4SLinus Torvalds 29431da177e4SLinus Torvalds 29441da177e4SLinus Torvalds /* 29451da177e4SLinus Torvalds * C-Media CM97xx codecs 29461da177e4SLinus Torvalds */ 2947ee42381eSTakashi Iwai static void cm9738_update_jacks(struct snd_ac97 *ac97) 2948eb8caf30STakashi Iwai { 2949831466f4SRandy Cushman /* shared Line-In / Surround Out */ 2950eb8caf30STakashi Iwai snd_ac97_update_bits(ac97, AC97_CM9738_VENDOR_CTRL, 1 << 10, 2951831466f4SRandy Cushman is_shared_surrout(ac97) ? (1 << 10) : 0); 2952eb8caf30STakashi Iwai } 2953eb8caf30STakashi Iwai 2954ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_cm9738_controls[] = { 29551da177e4SLinus Torvalds AC97_SINGLE("Duplicate Front", AC97_CM9738_VENDOR_CTRL, 13, 1, 0), 2956eb8caf30STakashi Iwai AC97_SURROUND_JACK_MODE_CTL, 2957eb8caf30STakashi Iwai AC97_CHANNEL_MODE_4CH_CTL, 29581da177e4SLinus Torvalds }; 29591da177e4SLinus Torvalds 2960ee42381eSTakashi Iwai static int patch_cm9738_specific(struct snd_ac97 * ac97) 29611da177e4SLinus Torvalds { 29621da177e4SLinus Torvalds return patch_build_controls(ac97, snd_ac97_cm9738_controls, ARRAY_SIZE(snd_ac97_cm9738_controls)); 29631da177e4SLinus Torvalds } 29641da177e4SLinus Torvalds 2965*3e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_cm9738_ops = { 2966eb8caf30STakashi Iwai .build_specific = patch_cm9738_specific, 2967eb8caf30STakashi Iwai .update_jacks = cm9738_update_jacks 29681da177e4SLinus Torvalds }; 29691da177e4SLinus Torvalds 2970ac519028STakashi Iwai static int patch_cm9738(struct snd_ac97 * ac97) 29711da177e4SLinus Torvalds { 29721da177e4SLinus Torvalds ac97->build_ops = &patch_cm9738_ops; 29731da177e4SLinus Torvalds /* FIXME: can anyone confirm below? */ 29741da177e4SLinus Torvalds /* CM9738 has no PCM volume although the register reacts */ 29751da177e4SLinus Torvalds ac97->flags |= AC97_HAS_NO_PCM_VOL; 29761da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_PCM, 0x8000); 29771da177e4SLinus Torvalds 29781da177e4SLinus Torvalds return 0; 29791da177e4SLinus Torvalds } 29801da177e4SLinus Torvalds 2981ee42381eSTakashi Iwai static int snd_ac97_cmedia_spdif_playback_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 29821da177e4SLinus Torvalds { 29831da177e4SLinus Torvalds static char *texts[] = { "Analog", "Digital" }; 29841da177e4SLinus Torvalds 29851da177e4SLinus Torvalds uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 29861da177e4SLinus Torvalds uinfo->count = 1; 29871da177e4SLinus Torvalds uinfo->value.enumerated.items = 2; 29881da177e4SLinus Torvalds if (uinfo->value.enumerated.item > 1) 29891da177e4SLinus Torvalds uinfo->value.enumerated.item = 1; 29901da177e4SLinus Torvalds strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 29911da177e4SLinus Torvalds return 0; 29921da177e4SLinus Torvalds } 29931da177e4SLinus Torvalds 2994ee42381eSTakashi Iwai static int snd_ac97_cmedia_spdif_playback_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 29951da177e4SLinus Torvalds { 2996ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 29971da177e4SLinus Torvalds unsigned short val; 29981da177e4SLinus Torvalds 29991da177e4SLinus Torvalds val = ac97->regs[AC97_CM9739_SPDIF_CTRL]; 30001da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = (val >> 1) & 0x01; 30011da177e4SLinus Torvalds return 0; 30021da177e4SLinus Torvalds } 30031da177e4SLinus Torvalds 3004ee42381eSTakashi Iwai static int snd_ac97_cmedia_spdif_playback_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 30051da177e4SLinus Torvalds { 3006ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 30071da177e4SLinus Torvalds 30081da177e4SLinus Torvalds return snd_ac97_update_bits(ac97, AC97_CM9739_SPDIF_CTRL, 30091da177e4SLinus Torvalds 0x01 << 1, 30101da177e4SLinus Torvalds (ucontrol->value.enumerated.item[0] & 0x01) << 1); 30111da177e4SLinus Torvalds } 30121da177e4SLinus Torvalds 3013ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_cm9739_controls_spdif[] = { 30141da177e4SLinus Torvalds /* BIT 0: SPDI_EN - always true */ 30151da177e4SLinus Torvalds { /* BIT 1: SPDIFS */ 30161da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 30171da177e4SLinus Torvalds .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source", 30181da177e4SLinus Torvalds .info = snd_ac97_cmedia_spdif_playback_source_info, 30191da177e4SLinus Torvalds .get = snd_ac97_cmedia_spdif_playback_source_get, 30201da177e4SLinus Torvalds .put = snd_ac97_cmedia_spdif_playback_source_put, 30211da177e4SLinus Torvalds }, 30221da177e4SLinus Torvalds /* BIT 2: IG_SPIV */ 30231da177e4SLinus Torvalds AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9739_SPDIF_CTRL, 2, 1, 0), 30241da177e4SLinus Torvalds /* BIT 3: SPI2F */ 30251da177e4SLinus Torvalds AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9739_SPDIF_CTRL, 3, 1, 0), 30261da177e4SLinus Torvalds /* BIT 4: SPI2SDI */ 30271da177e4SLinus Torvalds AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9739_SPDIF_CTRL, 4, 1, 0), 30281da177e4SLinus Torvalds /* BIT 8: SPD32 - 32bit SPDIF - not supported yet */ 30291da177e4SLinus Torvalds }; 30301da177e4SLinus Torvalds 3031ee42381eSTakashi Iwai static void cm9739_update_jacks(struct snd_ac97 *ac97) 30321da177e4SLinus Torvalds { 3033831466f4SRandy Cushman /* shared Line-In / Surround Out */ 3034eb8caf30STakashi Iwai snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 1 << 10, 3035831466f4SRandy Cushman is_shared_surrout(ac97) ? (1 << 10) : 0); 3036831466f4SRandy Cushman /* shared Mic In / Center/LFE Out **/ 3037eb8caf30STakashi Iwai snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 0x3000, 3038831466f4SRandy Cushman is_shared_clfeout(ac97) ? 0x1000 : 0x2000); 30391da177e4SLinus Torvalds } 30401da177e4SLinus Torvalds 3041ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_cm9739_controls[] = { 3042eb8caf30STakashi Iwai AC97_SURROUND_JACK_MODE_CTL, 3043eb8caf30STakashi Iwai AC97_CHANNEL_MODE_CTL, 30441da177e4SLinus Torvalds }; 30451da177e4SLinus Torvalds 3046ee42381eSTakashi Iwai static int patch_cm9739_specific(struct snd_ac97 * ac97) 30471da177e4SLinus Torvalds { 30481da177e4SLinus Torvalds return patch_build_controls(ac97, snd_ac97_cm9739_controls, ARRAY_SIZE(snd_ac97_cm9739_controls)); 30491da177e4SLinus Torvalds } 30501da177e4SLinus Torvalds 3051ee42381eSTakashi Iwai static int patch_cm9739_post_spdif(struct snd_ac97 * ac97) 30521da177e4SLinus Torvalds { 30531da177e4SLinus Torvalds return patch_build_controls(ac97, snd_ac97_cm9739_controls_spdif, ARRAY_SIZE(snd_ac97_cm9739_controls_spdif)); 30541da177e4SLinus Torvalds } 30551da177e4SLinus Torvalds 3056*3e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_cm9739_ops = { 30571da177e4SLinus Torvalds .build_specific = patch_cm9739_specific, 3058eb8caf30STakashi Iwai .build_post_spdif = patch_cm9739_post_spdif, 3059eb8caf30STakashi Iwai .update_jacks = cm9739_update_jacks 30601da177e4SLinus Torvalds }; 30611da177e4SLinus Torvalds 3062ac519028STakashi Iwai static int patch_cm9739(struct snd_ac97 * ac97) 30631da177e4SLinus Torvalds { 30641da177e4SLinus Torvalds unsigned short val; 30651da177e4SLinus Torvalds 30661da177e4SLinus Torvalds ac97->build_ops = &patch_cm9739_ops; 30671da177e4SLinus Torvalds 30681da177e4SLinus Torvalds /* CM9739/A has no Master and PCM volume although the register reacts */ 30691da177e4SLinus Torvalds ac97->flags |= AC97_HAS_NO_MASTER_VOL | AC97_HAS_NO_PCM_VOL; 30701da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_MASTER, 0x8000); 30711da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_PCM, 0x8000); 30721da177e4SLinus Torvalds 30731da177e4SLinus Torvalds /* check spdif */ 30741da177e4SLinus Torvalds val = snd_ac97_read(ac97, AC97_EXTENDED_STATUS); 30751da177e4SLinus Torvalds if (val & AC97_EA_SPCV) { 30761da177e4SLinus Torvalds /* enable spdif in */ 30771da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL, 30781da177e4SLinus Torvalds snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) | 0x01); 30791da177e4SLinus Torvalds ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */ 30801da177e4SLinus Torvalds } else { 30811da177e4SLinus Torvalds ac97->ext_id &= ~AC97_EI_SPDIF; /* disable extended-id */ 30821da177e4SLinus Torvalds ac97->rates[AC97_RATES_SPDIF] = 0; 30831da177e4SLinus Torvalds } 30841da177e4SLinus Torvalds 30851da177e4SLinus Torvalds /* set-up multi channel */ 30861da177e4SLinus Torvalds /* bit 14: 0 = SPDIF, 1 = EAPD */ 30871da177e4SLinus Torvalds /* bit 13: enable internal vref output for mic */ 30881da177e4SLinus Torvalds /* bit 12: disable center/lfe (swithable) */ 30891da177e4SLinus Torvalds /* bit 10: disable surround/line (switchable) */ 30901da177e4SLinus Torvalds /* bit 9: mix 2 surround off */ 30911da177e4SLinus Torvalds /* bit 4: undocumented; 0 mutes the CM9739A, which defaults to 1 */ 30921da177e4SLinus Torvalds /* bit 3: undocumented; surround? */ 30931da177e4SLinus Torvalds /* bit 0: dB */ 30941da177e4SLinus Torvalds val = snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) & (1 << 4); 30951da177e4SLinus Torvalds val |= (1 << 3); 30961da177e4SLinus Torvalds val |= (1 << 13); 30971da177e4SLinus Torvalds if (! (ac97->ext_id & AC97_EI_SPDIF)) 30981da177e4SLinus Torvalds val |= (1 << 14); 30991da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, val); 31001da177e4SLinus Torvalds 31011da177e4SLinus Torvalds /* FIXME: set up GPIO */ 31021da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x70, 0x0100); 31031da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x72, 0x0020); 31041da177e4SLinus Torvalds /* Special exception for ASUS W1000/CMI9739. It does not have an SPDIF in. */ 31051da177e4SLinus Torvalds if (ac97->pci && 31061da177e4SLinus Torvalds ac97->subsystem_vendor == 0x1043 && 31071da177e4SLinus Torvalds ac97->subsystem_device == 0x1843) { 31081da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL, 31091da177e4SLinus Torvalds snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) & ~0x01); 31101da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, 31111da177e4SLinus Torvalds snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) | (1 << 14)); 31121da177e4SLinus Torvalds } 31131da177e4SLinus Torvalds 31141da177e4SLinus Torvalds return 0; 31151da177e4SLinus Torvalds } 31161da177e4SLinus Torvalds 31171da177e4SLinus Torvalds #define AC97_CM9761_MULTI_CHAN 0x64 31185f0dccf8STakashi Iwai #define AC97_CM9761_FUNC 0x66 31191da177e4SLinus Torvalds #define AC97_CM9761_SPDIF_CTRL 0x6c 31201da177e4SLinus Torvalds 3121ee42381eSTakashi Iwai static void cm9761_update_jacks(struct snd_ac97 *ac97) 31221da177e4SLinus Torvalds { 31234525c9f3STakashi Iwai /* FIXME: check the bits for each model 31244525c9f3STakashi Iwai * model 83 is confirmed to work 31254525c9f3STakashi Iwai */ 31264525c9f3STakashi Iwai static unsigned short surr_on[3][2] = { 31274525c9f3STakashi Iwai { 0x0008, 0x0000 }, /* 9761-78 & 82 */ 31284525c9f3STakashi Iwai { 0x0000, 0x0008 }, /* 9761-82 rev.B */ 31294525c9f3STakashi Iwai { 0x0000, 0x0008 }, /* 9761-83 */ 31301da177e4SLinus Torvalds }; 31314525c9f3STakashi Iwai static unsigned short clfe_on[3][2] = { 31324525c9f3STakashi Iwai { 0x0000, 0x1000 }, /* 9761-78 & 82 */ 31334525c9f3STakashi Iwai { 0x1000, 0x0000 }, /* 9761-82 rev.B */ 31344525c9f3STakashi Iwai { 0x0000, 0x1000 }, /* 9761-83 */ 31351da177e4SLinus Torvalds }; 31364525c9f3STakashi Iwai static unsigned short surr_shared[3][2] = { 31374525c9f3STakashi Iwai { 0x0000, 0x0400 }, /* 9761-78 & 82 */ 31384525c9f3STakashi Iwai { 0x0000, 0x0400 }, /* 9761-82 rev.B */ 31394525c9f3STakashi Iwai { 0x0000, 0x0400 }, /* 9761-83 */ 31404525c9f3STakashi Iwai }; 31414525c9f3STakashi Iwai static unsigned short clfe_shared[3][2] = { 31424525c9f3STakashi Iwai { 0x2000, 0x0880 }, /* 9761-78 & 82 */ 31434525c9f3STakashi Iwai { 0x0000, 0x2880 }, /* 9761-82 rev.B */ 31444525c9f3STakashi Iwai { 0x2000, 0x0800 }, /* 9761-83 */ 31454525c9f3STakashi Iwai }; 31464525c9f3STakashi Iwai unsigned short val = 0; 3147eb8caf30STakashi Iwai 31484525c9f3STakashi Iwai val |= surr_on[ac97->spec.dev_flags][is_surround_on(ac97)]; 31494525c9f3STakashi Iwai val |= clfe_on[ac97->spec.dev_flags][is_clfe_on(ac97)]; 3150831466f4SRandy Cushman val |= surr_shared[ac97->spec.dev_flags][is_shared_surrout(ac97)]; 3151831466f4SRandy Cushman val |= clfe_shared[ac97->spec.dev_flags][is_shared_clfeout(ac97)]; 31524525c9f3STakashi Iwai 31534525c9f3STakashi Iwai snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x3c88, val); 31541da177e4SLinus Torvalds } 31551da177e4SLinus Torvalds 3156ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_cm9761_controls[] = { 3157eb8caf30STakashi Iwai AC97_SURROUND_JACK_MODE_CTL, 3158eb8caf30STakashi Iwai AC97_CHANNEL_MODE_CTL, 31591da177e4SLinus Torvalds }; 31601da177e4SLinus Torvalds 3161ee42381eSTakashi Iwai static int cm9761_spdif_out_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 31625f0dccf8STakashi Iwai { 31635f0dccf8STakashi Iwai static char *texts[] = { "AC-Link", "ADC", "SPDIF-In" }; 31645f0dccf8STakashi Iwai 31655f0dccf8STakashi Iwai uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 31665f0dccf8STakashi Iwai uinfo->count = 1; 31675f0dccf8STakashi Iwai uinfo->value.enumerated.items = 3; 31685f0dccf8STakashi Iwai if (uinfo->value.enumerated.item > 2) 31695f0dccf8STakashi Iwai uinfo->value.enumerated.item = 2; 31705f0dccf8STakashi Iwai strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 31715f0dccf8STakashi Iwai return 0; 31725f0dccf8STakashi Iwai } 31735f0dccf8STakashi Iwai 3174ee42381eSTakashi Iwai static int cm9761_spdif_out_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 31755f0dccf8STakashi Iwai { 3176ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 31775f0dccf8STakashi Iwai 31785f0dccf8STakashi Iwai if (ac97->regs[AC97_CM9761_FUNC] & 0x1) 31795f0dccf8STakashi Iwai ucontrol->value.enumerated.item[0] = 2; /* SPDIF-loopback */ 31805f0dccf8STakashi Iwai else if (ac97->regs[AC97_CM9761_SPDIF_CTRL] & 0x2) 31815f0dccf8STakashi Iwai ucontrol->value.enumerated.item[0] = 1; /* ADC loopback */ 31825f0dccf8STakashi Iwai else 31835f0dccf8STakashi Iwai ucontrol->value.enumerated.item[0] = 0; /* AC-link */ 31845f0dccf8STakashi Iwai return 0; 31855f0dccf8STakashi Iwai } 31865f0dccf8STakashi Iwai 3187ee42381eSTakashi Iwai static int cm9761_spdif_out_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 31885f0dccf8STakashi Iwai { 3189ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 31905f0dccf8STakashi Iwai 31915f0dccf8STakashi Iwai if (ucontrol->value.enumerated.item[0] == 2) 31925f0dccf8STakashi Iwai return snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0x1); 31935f0dccf8STakashi Iwai snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0); 31945f0dccf8STakashi Iwai return snd_ac97_update_bits(ac97, AC97_CM9761_SPDIF_CTRL, 0x2, 31955f0dccf8STakashi Iwai ucontrol->value.enumerated.item[0] == 1 ? 0x2 : 0); 31965f0dccf8STakashi Iwai } 31975f0dccf8STakashi Iwai 31985f0dccf8STakashi Iwai static const char *cm9761_dac_clock[] = { "AC-Link", "SPDIF-In", "Both" }; 31995f0dccf8STakashi Iwai static const struct ac97_enum cm9761_dac_clock_enum = 32005f0dccf8STakashi Iwai AC97_ENUM_SINGLE(AC97_CM9761_SPDIF_CTRL, 9, 3, cm9761_dac_clock); 32015f0dccf8STakashi Iwai 3202ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_cm9761_controls_spdif[] = { 32035f0dccf8STakashi Iwai { /* BIT 1: SPDIFS */ 32045f0dccf8STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 32055f0dccf8STakashi Iwai .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source", 32065f0dccf8STakashi Iwai .info = cm9761_spdif_out_source_info, 32075f0dccf8STakashi Iwai .get = cm9761_spdif_out_source_get, 32085f0dccf8STakashi Iwai .put = cm9761_spdif_out_source_put, 32095f0dccf8STakashi Iwai }, 32105f0dccf8STakashi Iwai /* BIT 2: IG_SPIV */ 32115f0dccf8STakashi Iwai AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9761_SPDIF_CTRL, 2, 1, 0), 32125f0dccf8STakashi Iwai /* BIT 3: SPI2F */ 32135f0dccf8STakashi Iwai AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9761_SPDIF_CTRL, 3, 1, 0), 32145f0dccf8STakashi Iwai /* BIT 4: SPI2SDI */ 32155f0dccf8STakashi Iwai AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9761_SPDIF_CTRL, 4, 1, 0), 32165f0dccf8STakashi Iwai /* BIT 9-10: DAC_CTL */ 32175f0dccf8STakashi Iwai AC97_ENUM("DAC Clock Source", cm9761_dac_clock_enum), 32185f0dccf8STakashi Iwai }; 32195f0dccf8STakashi Iwai 3220ee42381eSTakashi Iwai static int patch_cm9761_post_spdif(struct snd_ac97 * ac97) 32215f0dccf8STakashi Iwai { 32225f0dccf8STakashi Iwai return patch_build_controls(ac97, snd_ac97_cm9761_controls_spdif, ARRAY_SIZE(snd_ac97_cm9761_controls_spdif)); 32235f0dccf8STakashi Iwai } 32245f0dccf8STakashi Iwai 3225ee42381eSTakashi Iwai static int patch_cm9761_specific(struct snd_ac97 * ac97) 32261da177e4SLinus Torvalds { 32271da177e4SLinus Torvalds return patch_build_controls(ac97, snd_ac97_cm9761_controls, ARRAY_SIZE(snd_ac97_cm9761_controls)); 32281da177e4SLinus Torvalds } 32291da177e4SLinus Torvalds 3230*3e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_cm9761_ops = { 32311da177e4SLinus Torvalds .build_specific = patch_cm9761_specific, 3232eb8caf30STakashi Iwai .build_post_spdif = patch_cm9761_post_spdif, 3233eb8caf30STakashi Iwai .update_jacks = cm9761_update_jacks 32341da177e4SLinus Torvalds }; 32351da177e4SLinus Torvalds 3236ac519028STakashi Iwai static int patch_cm9761(struct snd_ac97 *ac97) 32371da177e4SLinus Torvalds { 32381da177e4SLinus Torvalds unsigned short val; 32391da177e4SLinus Torvalds 32401da177e4SLinus Torvalds /* CM9761 has no PCM volume although the register reacts */ 32411da177e4SLinus Torvalds /* Master volume seems to have _some_ influence on the analog 32421da177e4SLinus Torvalds * input sounds 32431da177e4SLinus Torvalds */ 32441da177e4SLinus Torvalds ac97->flags |= /*AC97_HAS_NO_MASTER_VOL |*/ AC97_HAS_NO_PCM_VOL; 32451da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_MASTER, 0x8808); 32461da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_PCM, 0x8808); 32471da177e4SLinus Torvalds 32484525c9f3STakashi Iwai ac97->spec.dev_flags = 0; /* 1 = model 82 revision B, 2 = model 83 */ 32491da177e4SLinus Torvalds if (ac97->id == AC97_ID_CM9761_82) { 32501da177e4SLinus Torvalds unsigned short tmp; 32511da177e4SLinus Torvalds /* check page 1, reg 0x60 */ 32521da177e4SLinus Torvalds val = snd_ac97_read(ac97, AC97_INT_PAGING); 32531da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_INT_PAGING, (val & ~0x0f) | 0x01); 32541da177e4SLinus Torvalds tmp = snd_ac97_read(ac97, 0x60); 32551da177e4SLinus Torvalds ac97->spec.dev_flags = tmp & 1; /* revision B? */ 32561da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_INT_PAGING, val); 32574525c9f3STakashi Iwai } else if (ac97->id == AC97_ID_CM9761_83) 32584525c9f3STakashi Iwai ac97->spec.dev_flags = 2; 32591da177e4SLinus Torvalds 32601da177e4SLinus Torvalds ac97->build_ops = &patch_cm9761_ops; 32611da177e4SLinus Torvalds 32621da177e4SLinus Torvalds /* enable spdif */ 32631da177e4SLinus Torvalds /* force the SPDIF bit in ext_id - codec doesn't set this bit! */ 32641da177e4SLinus Torvalds ac97->ext_id |= AC97_EI_SPDIF; 32651da177e4SLinus Torvalds /* to be sure: we overwrite the ext status bits */ 32661da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, 0x05c0); 32671da177e4SLinus Torvalds /* Don't set 0x0200 here. This results in the silent analog output */ 32685f0dccf8STakashi Iwai snd_ac97_write_cache(ac97, AC97_CM9761_SPDIF_CTRL, 0x0001); /* enable spdif-in */ 32691da177e4SLinus Torvalds ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */ 32701da177e4SLinus Torvalds 32711da177e4SLinus Torvalds /* set-up multi channel */ 32721da177e4SLinus Torvalds /* bit 15: pc master beep off 32735f0dccf8STakashi Iwai * bit 14: pin47 = EAPD/SPDIF 32741da177e4SLinus Torvalds * bit 13: vref ctl [= cm9739] 32755f0dccf8STakashi Iwai * bit 12: CLFE control (reverted on rev B) 32765f0dccf8STakashi Iwai * bit 11: Mic/center share (reverted on rev B) 32775f0dccf8STakashi Iwai * bit 10: suddound/line share 32785f0dccf8STakashi Iwai * bit 9: Analog-in mix -> surround 32795f0dccf8STakashi Iwai * bit 8: Analog-in mix -> CLFE 32805f0dccf8STakashi Iwai * bit 7: Mic/LFE share (mic/center/lfe) 32815f0dccf8STakashi Iwai * bit 5: vref select (9761A) 32825f0dccf8STakashi Iwai * bit 4: front control 32835f0dccf8STakashi Iwai * bit 3: surround control (revereted with rev B) 32845f0dccf8STakashi Iwai * bit 2: front mic 32855f0dccf8STakashi Iwai * bit 1: stereo mic 32865f0dccf8STakashi Iwai * bit 0: mic boost level (0=20dB, 1=30dB) 32871da177e4SLinus Torvalds */ 32881da177e4SLinus Torvalds 32891da177e4SLinus Torvalds #if 0 32901da177e4SLinus Torvalds if (ac97->spec.dev_flags) 32911da177e4SLinus Torvalds val = 0x0214; 32921da177e4SLinus Torvalds else 32931da177e4SLinus Torvalds val = 0x321c; 32941da177e4SLinus Torvalds #endif 32951da177e4SLinus Torvalds val = snd_ac97_read(ac97, AC97_CM9761_MULTI_CHAN); 32961da177e4SLinus Torvalds val |= (1 << 4); /* front on */ 32971da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_CM9761_MULTI_CHAN, val); 32981da177e4SLinus Torvalds 32991da177e4SLinus Torvalds /* FIXME: set up GPIO */ 33001da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x70, 0x0100); 33011da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x72, 0x0020); 33021da177e4SLinus Torvalds 33031da177e4SLinus Torvalds return 0; 33041da177e4SLinus Torvalds } 33051da177e4SLinus Torvalds 33065f0dccf8STakashi Iwai #define AC97_CM9780_SIDE 0x60 33075f0dccf8STakashi Iwai #define AC97_CM9780_JACK 0x62 33085f0dccf8STakashi Iwai #define AC97_CM9780_MIXER 0x64 33095f0dccf8STakashi Iwai #define AC97_CM9780_MULTI_CHAN 0x66 33105f0dccf8STakashi Iwai #define AC97_CM9780_SPDIF 0x6c 33115f0dccf8STakashi Iwai 33125f0dccf8STakashi Iwai static const char *cm9780_ch_select[] = { "Front", "Side", "Center/LFE", "Rear" }; 33135f0dccf8STakashi Iwai static const struct ac97_enum cm9780_ch_select_enum = 33145f0dccf8STakashi Iwai AC97_ENUM_SINGLE(AC97_CM9780_MULTI_CHAN, 6, 4, cm9780_ch_select); 3315ee42381eSTakashi Iwai static const struct snd_kcontrol_new cm9780_controls[] = { 33165f0dccf8STakashi Iwai AC97_DOUBLE("Side Playback Switch", AC97_CM9780_SIDE, 15, 7, 1, 1), 33175f0dccf8STakashi Iwai AC97_DOUBLE("Side Playback Volume", AC97_CM9780_SIDE, 8, 0, 31, 0), 33185f0dccf8STakashi Iwai AC97_ENUM("Side Playback Route", cm9780_ch_select_enum), 33195f0dccf8STakashi Iwai }; 33205f0dccf8STakashi Iwai 3321ee42381eSTakashi Iwai static int patch_cm9780_specific(struct snd_ac97 *ac97) 33225f0dccf8STakashi Iwai { 33235f0dccf8STakashi Iwai return patch_build_controls(ac97, cm9780_controls, ARRAY_SIZE(cm9780_controls)); 33245f0dccf8STakashi Iwai } 33255f0dccf8STakashi Iwai 3326*3e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_cm9780_ops = { 33275f0dccf8STakashi Iwai .build_specific = patch_cm9780_specific, 33285f0dccf8STakashi Iwai .build_post_spdif = patch_cm9761_post_spdif /* identical with CM9761 */ 33295f0dccf8STakashi Iwai }; 33305f0dccf8STakashi Iwai 3331ac519028STakashi Iwai static int patch_cm9780(struct snd_ac97 *ac97) 33325f0dccf8STakashi Iwai { 33335f0dccf8STakashi Iwai unsigned short val; 33345f0dccf8STakashi Iwai 33355f0dccf8STakashi Iwai ac97->build_ops = &patch_cm9780_ops; 33365f0dccf8STakashi Iwai 33375f0dccf8STakashi Iwai /* enable spdif */ 33385f0dccf8STakashi Iwai if (ac97->ext_id & AC97_EI_SPDIF) { 33395f0dccf8STakashi Iwai ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */ 33405f0dccf8STakashi Iwai val = snd_ac97_read(ac97, AC97_CM9780_SPDIF); 33415f0dccf8STakashi Iwai val |= 0x1; /* SPDI_EN */ 33425f0dccf8STakashi Iwai snd_ac97_write_cache(ac97, AC97_CM9780_SPDIF, val); 33435f0dccf8STakashi Iwai } 33445f0dccf8STakashi Iwai 33455f0dccf8STakashi Iwai return 0; 33465f0dccf8STakashi Iwai } 33471da177e4SLinus Torvalds 33481da177e4SLinus Torvalds /* 33491da177e4SLinus Torvalds * VIA VT1616 codec 33501da177e4SLinus Torvalds */ 3351ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_vt1616[] = { 33521da177e4SLinus Torvalds AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0), 33531da177e4SLinus Torvalds AC97_SINGLE("Alternate Level to Surround Out", 0x5a, 15, 1, 0), 33541da177e4SLinus Torvalds AC97_SINGLE("Downmix LFE and Center to Front", 0x5a, 12, 1, 0), 33551da177e4SLinus Torvalds AC97_SINGLE("Downmix Surround to Front", 0x5a, 11, 1, 0), 33561da177e4SLinus Torvalds }; 33571da177e4SLinus Torvalds 335887af38daSDaniel Jacobowitz static const char *slave_vols_vt1616[] = { 335987af38daSDaniel Jacobowitz "Front Playback Volume", 336087af38daSDaniel Jacobowitz "Surround Playback Volume", 336187af38daSDaniel Jacobowitz "Center Playback Volume", 336287af38daSDaniel Jacobowitz "LFE Playback Volume", 336387af38daSDaniel Jacobowitz NULL 336487af38daSDaniel Jacobowitz }; 336587af38daSDaniel Jacobowitz 336687af38daSDaniel Jacobowitz static const char *slave_sws_vt1616[] = { 336787af38daSDaniel Jacobowitz "Front Playback Switch", 336887af38daSDaniel Jacobowitz "Surround Playback Switch", 336987af38daSDaniel Jacobowitz "Center Playback Switch", 337087af38daSDaniel Jacobowitz "LFE Playback Switch", 337187af38daSDaniel Jacobowitz NULL 337287af38daSDaniel Jacobowitz }; 337387af38daSDaniel Jacobowitz 337487af38daSDaniel Jacobowitz /* find a mixer control element with the given name */ 337587af38daSDaniel Jacobowitz static struct snd_kcontrol *snd_ac97_find_mixer_ctl(struct snd_ac97 *ac97, 337687af38daSDaniel Jacobowitz const char *name) 337787af38daSDaniel Jacobowitz { 337887af38daSDaniel Jacobowitz struct snd_ctl_elem_id id; 337987af38daSDaniel Jacobowitz memset(&id, 0, sizeof(id)); 338087af38daSDaniel Jacobowitz id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 338187af38daSDaniel Jacobowitz strcpy(id.name, name); 338287af38daSDaniel Jacobowitz return snd_ctl_find_id(ac97->bus->card, &id); 338387af38daSDaniel Jacobowitz } 338487af38daSDaniel Jacobowitz 338587af38daSDaniel Jacobowitz /* create a virtual master control and add slaves */ 338613c2108dSAdrian Bunk static int snd_ac97_add_vmaster(struct snd_ac97 *ac97, char *name, 338787af38daSDaniel Jacobowitz const unsigned int *tlv, const char **slaves) 338887af38daSDaniel Jacobowitz { 338987af38daSDaniel Jacobowitz struct snd_kcontrol *kctl; 339087af38daSDaniel Jacobowitz const char **s; 339187af38daSDaniel Jacobowitz int err; 339287af38daSDaniel Jacobowitz 339387af38daSDaniel Jacobowitz kctl = snd_ctl_make_virtual_master(name, tlv); 339487af38daSDaniel Jacobowitz if (!kctl) 339587af38daSDaniel Jacobowitz return -ENOMEM; 339687af38daSDaniel Jacobowitz err = snd_ctl_add(ac97->bus->card, kctl); 339787af38daSDaniel Jacobowitz if (err < 0) 339887af38daSDaniel Jacobowitz return err; 339987af38daSDaniel Jacobowitz 340087af38daSDaniel Jacobowitz for (s = slaves; *s; s++) { 340187af38daSDaniel Jacobowitz struct snd_kcontrol *sctl; 340287af38daSDaniel Jacobowitz 340387af38daSDaniel Jacobowitz sctl = snd_ac97_find_mixer_ctl(ac97, *s); 340487af38daSDaniel Jacobowitz if (!sctl) { 340587af38daSDaniel Jacobowitz snd_printdd("Cannot find slave %s, skipped\n", *s); 340687af38daSDaniel Jacobowitz continue; 340787af38daSDaniel Jacobowitz } 340887af38daSDaniel Jacobowitz err = snd_ctl_add_slave(kctl, sctl); 340987af38daSDaniel Jacobowitz if (err < 0) 341087af38daSDaniel Jacobowitz return err; 341187af38daSDaniel Jacobowitz } 341287af38daSDaniel Jacobowitz return 0; 341387af38daSDaniel Jacobowitz } 341487af38daSDaniel Jacobowitz 3415ee42381eSTakashi Iwai static int patch_vt1616_specific(struct snd_ac97 * ac97) 34161da177e4SLinus Torvalds { 341787af38daSDaniel Jacobowitz struct snd_kcontrol *kctl; 34181da177e4SLinus Torvalds int err; 34191da177e4SLinus Torvalds 34201da177e4SLinus Torvalds if (snd_ac97_try_bit(ac97, 0x5a, 9)) 34211da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[0], 1)) < 0) 34221da177e4SLinus Torvalds return err; 34231da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[1], ARRAY_SIZE(snd_ac97_controls_vt1616) - 1)) < 0) 34241da177e4SLinus Torvalds return err; 342587af38daSDaniel Jacobowitz 342687af38daSDaniel Jacobowitz /* There is already a misnamed master switch. Rename it. */ 342787af38daSDaniel Jacobowitz kctl = snd_ac97_find_mixer_ctl(ac97, "Master Playback Volume"); 342887af38daSDaniel Jacobowitz if (!kctl) 342987af38daSDaniel Jacobowitz return -EINVAL; 343087af38daSDaniel Jacobowitz 343187af38daSDaniel Jacobowitz snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Front Playback"); 343287af38daSDaniel Jacobowitz 343387af38daSDaniel Jacobowitz err = snd_ac97_add_vmaster(ac97, "Master Playback Volume", 343487af38daSDaniel Jacobowitz kctl->tlv.p, slave_vols_vt1616); 343587af38daSDaniel Jacobowitz if (err < 0) 343687af38daSDaniel Jacobowitz return err; 343787af38daSDaniel Jacobowitz 343887af38daSDaniel Jacobowitz err = snd_ac97_add_vmaster(ac97, "Master Playback Switch", 343987af38daSDaniel Jacobowitz NULL, slave_sws_vt1616); 344087af38daSDaniel Jacobowitz if (err < 0) 344187af38daSDaniel Jacobowitz return err; 344287af38daSDaniel Jacobowitz 34431da177e4SLinus Torvalds return 0; 34441da177e4SLinus Torvalds } 34451da177e4SLinus Torvalds 3446*3e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_vt1616_ops = { 34471da177e4SLinus Torvalds .build_specific = patch_vt1616_specific 34481da177e4SLinus Torvalds }; 34491da177e4SLinus Torvalds 3450ac519028STakashi Iwai static int patch_vt1616(struct snd_ac97 * ac97) 34511da177e4SLinus Torvalds { 34521da177e4SLinus Torvalds ac97->build_ops = &patch_vt1616_ops; 34531da177e4SLinus Torvalds return 0; 34541da177e4SLinus Torvalds } 34551da177e4SLinus Torvalds 3456eb8caf30STakashi Iwai /* 34574b499486SPhilip Prindeville * VT1617A codec 34584b499486SPhilip Prindeville */ 3459e9024cccSJohn Utz 3460e9024cccSJohn Utz /* 3461e9024cccSJohn Utz * unfortunately, the vt1617a stashes the twiddlers required for 34629e285e1aSJohn L. Utz III * noodling the i/o jacks on 2 different regs. that means that we can't 3463e9024cccSJohn Utz * use the easy way provided by AC97_ENUM_DOUBLE() we have to write 3464e9024cccSJohn Utz * are own funcs. 3465e9024cccSJohn Utz * 3466e9024cccSJohn Utz * NB: this is absolutely and utterly different from the vt1618. dunno 3467e9024cccSJohn Utz * about the 1616. 3468e9024cccSJohn Utz */ 3469e9024cccSJohn Utz 3470e9024cccSJohn Utz /* copied from ac97_surround_jack_mode_info() */ 3471e9024cccSJohn Utz static int snd_ac97_vt1617a_smart51_info(struct snd_kcontrol *kcontrol, 3472e9024cccSJohn Utz struct snd_ctl_elem_info *uinfo) 34734b499486SPhilip Prindeville { 3474e9024cccSJohn Utz /* ordering in this list reflects vt1617a docs for Reg 20 and 3475e9024cccSJohn Utz * 7a and Table 6 that lays out the matrix NB WRT Table6: SM51 3476e9024cccSJohn Utz * is SM51EN *AND* it's Bit14, not Bit15 so the table is very 3477e9024cccSJohn Utz * counter-intuitive */ 3478e9024cccSJohn Utz 3479e9024cccSJohn Utz static const char* texts[] = { "LineIn Mic1", "LineIn Mic1 Mic3", 3480e9024cccSJohn Utz "Surr LFE/C Mic3", "LineIn LFE/C Mic3", 3481e9024cccSJohn Utz "LineIn Mic2", "LineIn Mic2 Mic1", 3482e9024cccSJohn Utz "Surr LFE Mic1", "Surr LFE Mic1 Mic2"}; 3483e9024cccSJohn Utz return ac97_enum_text_info(kcontrol, uinfo, texts, 8); 3484e9024cccSJohn Utz } 3485e9024cccSJohn Utz 3486e9024cccSJohn Utz static int snd_ac97_vt1617a_smart51_get(struct snd_kcontrol *kcontrol, 3487e9024cccSJohn Utz struct snd_ctl_elem_value *ucontrol) 3488e9024cccSJohn Utz { 3489e9024cccSJohn Utz ushort usSM51, usMS; 3490e9024cccSJohn Utz 3491e9024cccSJohn Utz struct snd_ac97 *pac97; 3492e9024cccSJohn Utz 3493e9024cccSJohn Utz pac97 = snd_kcontrol_chip(kcontrol); /* grab codec handle */ 3494e9024cccSJohn Utz 34959e285e1aSJohn L. Utz III /* grab our desired bits, then mash them together in a manner 3496e9024cccSJohn Utz * consistent with Table 6 on page 17 in the 1617a docs */ 3497e9024cccSJohn Utz 3498e9024cccSJohn Utz usSM51 = snd_ac97_read(pac97, 0x7a) >> 14; 3499e9024cccSJohn Utz usMS = snd_ac97_read(pac97, 0x20) >> 8; 3500e9024cccSJohn Utz 3501e9024cccSJohn Utz ucontrol->value.enumerated.item[0] = (usSM51 << 1) + usMS; 3502e9024cccSJohn Utz 3503e9024cccSJohn Utz return 0; 3504e9024cccSJohn Utz } 3505e9024cccSJohn Utz 3506e9024cccSJohn Utz static int snd_ac97_vt1617a_smart51_put(struct snd_kcontrol *kcontrol, 3507e9024cccSJohn Utz struct snd_ctl_elem_value *ucontrol) 3508e9024cccSJohn Utz { 3509e9024cccSJohn Utz ushort usSM51, usMS, usReg; 3510e9024cccSJohn Utz 3511e9024cccSJohn Utz struct snd_ac97 *pac97; 3512e9024cccSJohn Utz 3513e9024cccSJohn Utz pac97 = snd_kcontrol_chip(kcontrol); /* grab codec handle */ 3514e9024cccSJohn Utz 3515e9024cccSJohn Utz usSM51 = ucontrol->value.enumerated.item[0] >> 1; 3516e9024cccSJohn Utz usMS = ucontrol->value.enumerated.item[0] & 1; 3517e9024cccSJohn Utz 3518e9024cccSJohn Utz /* push our values into the register - consider that things will be left 3519e9024cccSJohn Utz * in a funky state if the write fails */ 3520e9024cccSJohn Utz 3521e9024cccSJohn Utz usReg = snd_ac97_read(pac97, 0x7a); 3522e9024cccSJohn Utz snd_ac97_write_cache(pac97, 0x7a, (usReg & 0x3FFF) + (usSM51 << 14)); 3523e9024cccSJohn Utz usReg = snd_ac97_read(pac97, 0x20); 3524e9024cccSJohn Utz snd_ac97_write_cache(pac97, 0x20, (usReg & 0xFEFF) + (usMS << 8)); 3525e9024cccSJohn Utz 3526e9024cccSJohn Utz return 0; 3527e9024cccSJohn Utz } 3528e9024cccSJohn Utz 3529e9024cccSJohn Utz static const struct snd_kcontrol_new snd_ac97_controls_vt1617a[] = { 3530e9024cccSJohn Utz 3531e9024cccSJohn Utz AC97_SINGLE("Center/LFE Exchange", 0x5a, 8, 1, 0), 3532e9024cccSJohn Utz /* 3533e9024cccSJohn Utz * These are used to enable/disable surround sound on motherboards 3534e9024cccSJohn Utz * that have 3 bidirectional analog jacks 3535e9024cccSJohn Utz */ 3536e9024cccSJohn Utz { 3537e9024cccSJohn Utz .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 3538e9024cccSJohn Utz .name = "Smart 5.1 Select", 3539e9024cccSJohn Utz .info = snd_ac97_vt1617a_smart51_info, 3540e9024cccSJohn Utz .get = snd_ac97_vt1617a_smart51_get, 3541e9024cccSJohn Utz .put = snd_ac97_vt1617a_smart51_put, 3542e9024cccSJohn Utz }, 3543e9024cccSJohn Utz }; 3544e9024cccSJohn Utz 3545b03671a8SHarvey Harrison static int patch_vt1617a(struct snd_ac97 * ac97) 3546e9024cccSJohn Utz { 3547e9024cccSJohn Utz int err = 0; 35482e75d050STakashi Iwai int val; 3549e9024cccSJohn Utz 3550e9024cccSJohn Utz /* we choose to not fail out at this point, but we tell the 3551e9024cccSJohn Utz caller when we return */ 3552e9024cccSJohn Utz 3553e9024cccSJohn Utz err = patch_build_controls(ac97, &snd_ac97_controls_vt1617a[0], 3554e9024cccSJohn Utz ARRAY_SIZE(snd_ac97_controls_vt1617a)); 3555e9024cccSJohn Utz 3556e9024cccSJohn Utz /* bring analog power consumption to normal by turning off the 3557e9024cccSJohn Utz * headphone amplifier, like WinXP driver for EPIA SP 35589f458e7fSAndrey Liakhovets */ 35592e75d050STakashi Iwai /* We need to check the bit before writing it. 35602e75d050STakashi Iwai * On some (many?) hardwares, setting bit actually clears it! 35612e75d050STakashi Iwai */ 35622e75d050STakashi Iwai val = snd_ac97_read(ac97, 0x5c); 35632e75d050STakashi Iwai if (!(val & 0x20)) 35649f458e7fSAndrey Liakhovets snd_ac97_write_cache(ac97, 0x5c, 0x20); 35652e75d050STakashi Iwai 35664b499486SPhilip Prindeville ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */ 35674b499486SPhilip Prindeville ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000; 35689f428175SDaniel Jacobowitz ac97->build_ops = &patch_vt1616_ops; 3569e9024cccSJohn Utz 3570e9024cccSJohn Utz return err; 35714b499486SPhilip Prindeville } 35724b499486SPhilip Prindeville 35739e285e1aSJohn L. Utz III /* VIA VT1618 8 CHANNEL AC97 CODEC 35749e285e1aSJohn L. Utz III * 35759e285e1aSJohn L. Utz III * VIA implements 'Smart 5.1' completely differently on the 1618 than 35769e285e1aSJohn L. Utz III * it does on the 1617a. awesome! They seem to have sourced this 35779e285e1aSJohn L. Utz III * particular revision of the technology from somebody else, it's 35789e285e1aSJohn L. Utz III * called Universal Audio Jack and it shows up on some other folk's chips 35799e285e1aSJohn L. Utz III * as well. 35809e285e1aSJohn L. Utz III * 35819e285e1aSJohn L. Utz III * ordering in this list reflects vt1618 docs for Reg 60h and 35829e285e1aSJohn L. Utz III * the block diagram, DACs are as follows: 35839e285e1aSJohn L. Utz III * 35849e285e1aSJohn L. Utz III * OUT_O -> Front, 35859e285e1aSJohn L. Utz III * OUT_1 -> Surround, 35869e285e1aSJohn L. Utz III * OUT_2 -> C/LFE 35879e285e1aSJohn L. Utz III * 35889e285e1aSJohn L. Utz III * Unlike the 1617a, each OUT has a consistent set of mappings 35899e285e1aSJohn L. Utz III * for all bitpatterns other than 00: 35909e285e1aSJohn L. Utz III * 35919e285e1aSJohn L. Utz III * 01 Unmixed Output 35929e285e1aSJohn L. Utz III * 10 Line In 35939e285e1aSJohn L. Utz III * 11 Mic In 35949e285e1aSJohn L. Utz III * 35959e285e1aSJohn L. Utz III * Special Case of 00: 35969e285e1aSJohn L. Utz III * 35979e285e1aSJohn L. Utz III * OUT_0 Mixed Output 35989e285e1aSJohn L. Utz III * OUT_1 Reserved 35999e285e1aSJohn L. Utz III * OUT_2 Reserved 36009e285e1aSJohn L. Utz III * 36019e285e1aSJohn L. Utz III * I have no idea what the hell Reserved does, but on an MSI 36029e285e1aSJohn L. Utz III * CN700T, i have to set it to get 5.1 output - YMMV, bad 36039e285e1aSJohn L. Utz III * shit may happen. 36049e285e1aSJohn L. Utz III * 36059e285e1aSJohn L. Utz III * If other chips use Universal Audio Jack, then this code might be applicable 36069e285e1aSJohn L. Utz III * to them. 36079e285e1aSJohn L. Utz III */ 36089e285e1aSJohn L. Utz III 36099e285e1aSJohn L. Utz III struct vt1618_uaj_item { 36109e285e1aSJohn L. Utz III unsigned short mask; 36119e285e1aSJohn L. Utz III unsigned short shift; 36129e285e1aSJohn L. Utz III const char *items[4]; 36139e285e1aSJohn L. Utz III }; 36149e285e1aSJohn L. Utz III 36159e285e1aSJohn L. Utz III /* This list reflects the vt1618 docs for Vendor Defined Register 0x60. */ 36169e285e1aSJohn L. Utz III 36179e285e1aSJohn L. Utz III static struct vt1618_uaj_item vt1618_uaj[3] = { 36189e285e1aSJohn L. Utz III { 36199e285e1aSJohn L. Utz III /* speaker jack */ 36209e285e1aSJohn L. Utz III .mask = 0x03, 36219e285e1aSJohn L. Utz III .shift = 0, 36229e285e1aSJohn L. Utz III .items = { 36239e285e1aSJohn L. Utz III "Speaker Out", "DAC Unmixed Out", "Line In", "Mic In" 36249e285e1aSJohn L. Utz III } 36259e285e1aSJohn L. Utz III }, 36269e285e1aSJohn L. Utz III { 36279e285e1aSJohn L. Utz III /* line jack */ 36289e285e1aSJohn L. Utz III .mask = 0x0c, 36299e285e1aSJohn L. Utz III .shift = 2, 36309e285e1aSJohn L. Utz III .items = { 36319e285e1aSJohn L. Utz III "Surround Out", "DAC Unmixed Out", "Line In", "Mic In" 36329e285e1aSJohn L. Utz III } 36339e285e1aSJohn L. Utz III }, 36349e285e1aSJohn L. Utz III { 36359e285e1aSJohn L. Utz III /* mic jack */ 36369e285e1aSJohn L. Utz III .mask = 0x30, 36379e285e1aSJohn L. Utz III .shift = 4, 36389e285e1aSJohn L. Utz III .items = { 36399e285e1aSJohn L. Utz III "Center LFE Out", "DAC Unmixed Out", "Line In", "Mic In" 36409e285e1aSJohn L. Utz III }, 36419e285e1aSJohn L. Utz III }, 36429e285e1aSJohn L. Utz III }; 36439e285e1aSJohn L. Utz III 36449e285e1aSJohn L. Utz III static int snd_ac97_vt1618_UAJ_info(struct snd_kcontrol *kcontrol, 36459e285e1aSJohn L. Utz III struct snd_ctl_elem_info *uinfo) 36469e285e1aSJohn L. Utz III { 36479e285e1aSJohn L. Utz III return ac97_enum_text_info(kcontrol, uinfo, 36489e285e1aSJohn L. Utz III vt1618_uaj[kcontrol->private_value].items, 36499e285e1aSJohn L. Utz III 4); 36509e285e1aSJohn L. Utz III } 36519e285e1aSJohn L. Utz III 36529e285e1aSJohn L. Utz III /* All of the vt1618 Universal Audio Jack twiddlers are on 36539e285e1aSJohn L. Utz III * Vendor Defined Register 0x60, page 0. The bits, and thus 36549e285e1aSJohn L. Utz III * the mask, are the only thing that changes 36559e285e1aSJohn L. Utz III */ 36569e285e1aSJohn L. Utz III static int snd_ac97_vt1618_UAJ_get(struct snd_kcontrol *kcontrol, 36579e285e1aSJohn L. Utz III struct snd_ctl_elem_value *ucontrol) 36589e285e1aSJohn L. Utz III { 36599e285e1aSJohn L. Utz III unsigned short datpag, uaj; 36609e285e1aSJohn L. Utz III struct snd_ac97 *pac97 = snd_kcontrol_chip(kcontrol); 36619e285e1aSJohn L. Utz III 36629e285e1aSJohn L. Utz III mutex_lock(&pac97->page_mutex); 36639e285e1aSJohn L. Utz III 36649e285e1aSJohn L. Utz III datpag = snd_ac97_read(pac97, AC97_INT_PAGING) & AC97_PAGE_MASK; 36659e285e1aSJohn L. Utz III snd_ac97_update_bits(pac97, AC97_INT_PAGING, AC97_PAGE_MASK, 0); 36669e285e1aSJohn L. Utz III 36679e285e1aSJohn L. Utz III uaj = snd_ac97_read(pac97, 0x60) & 36689e285e1aSJohn L. Utz III vt1618_uaj[kcontrol->private_value].mask; 36699e285e1aSJohn L. Utz III 36709e285e1aSJohn L. Utz III snd_ac97_update_bits(pac97, AC97_INT_PAGING, AC97_PAGE_MASK, datpag); 36719e285e1aSJohn L. Utz III mutex_unlock(&pac97->page_mutex); 36729e285e1aSJohn L. Utz III 36739e285e1aSJohn L. Utz III ucontrol->value.enumerated.item[0] = uaj >> 36749e285e1aSJohn L. Utz III vt1618_uaj[kcontrol->private_value].shift; 36759e285e1aSJohn L. Utz III 36769e285e1aSJohn L. Utz III return 0; 36779e285e1aSJohn L. Utz III } 36789e285e1aSJohn L. Utz III 36799e285e1aSJohn L. Utz III static int snd_ac97_vt1618_UAJ_put(struct snd_kcontrol *kcontrol, 36809e285e1aSJohn L. Utz III struct snd_ctl_elem_value *ucontrol) 36819e285e1aSJohn L. Utz III { 36829e285e1aSJohn L. Utz III return ac97_update_bits_page(snd_kcontrol_chip(kcontrol), 0x60, 36839e285e1aSJohn L. Utz III vt1618_uaj[kcontrol->private_value].mask, 36849e285e1aSJohn L. Utz III ucontrol->value.enumerated.item[0]<< 36859e285e1aSJohn L. Utz III vt1618_uaj[kcontrol->private_value].shift, 36869e285e1aSJohn L. Utz III 0); 36879e285e1aSJohn L. Utz III } 36889e285e1aSJohn L. Utz III 36899e285e1aSJohn L. Utz III /* config aux in jack - not found on 3 jack motherboards or soundcards */ 36909e285e1aSJohn L. Utz III 36919e285e1aSJohn L. Utz III static int snd_ac97_vt1618_aux_info(struct snd_kcontrol *kcontrol, 36929e285e1aSJohn L. Utz III struct snd_ctl_elem_info *uinfo) 36939e285e1aSJohn L. Utz III { 36949e285e1aSJohn L. Utz III static const char *txt_aux[] = {"Aux In", "Back Surr Out"}; 36959e285e1aSJohn L. Utz III 36969e285e1aSJohn L. Utz III return ac97_enum_text_info(kcontrol, uinfo, txt_aux, 2); 36979e285e1aSJohn L. Utz III } 36989e285e1aSJohn L. Utz III 36999e285e1aSJohn L. Utz III static int snd_ac97_vt1618_aux_get(struct snd_kcontrol *kcontrol, 37009e285e1aSJohn L. Utz III struct snd_ctl_elem_value *ucontrol) 37019e285e1aSJohn L. Utz III { 37029e285e1aSJohn L. Utz III ucontrol->value.enumerated.item[0] = 37039e285e1aSJohn L. Utz III (snd_ac97_read(snd_kcontrol_chip(kcontrol), 0x5c) & 0x0008)>>3; 37049e285e1aSJohn L. Utz III return 0; 37059e285e1aSJohn L. Utz III } 37069e285e1aSJohn L. Utz III 37079e285e1aSJohn L. Utz III static int snd_ac97_vt1618_aux_put(struct snd_kcontrol *kcontrol, 37089e285e1aSJohn L. Utz III struct snd_ctl_elem_value *ucontrol) 37099e285e1aSJohn L. Utz III { 37109e285e1aSJohn L. Utz III /* toggle surround rear dac power */ 37119e285e1aSJohn L. Utz III 37129e285e1aSJohn L. Utz III snd_ac97_update_bits(snd_kcontrol_chip(kcontrol), 0x5c, 0x0008, 37139e285e1aSJohn L. Utz III ucontrol->value.enumerated.item[0] << 3); 37149e285e1aSJohn L. Utz III 37159e285e1aSJohn L. Utz III /* toggle aux in surround rear out jack */ 37169e285e1aSJohn L. Utz III 37179e285e1aSJohn L. Utz III return snd_ac97_update_bits(snd_kcontrol_chip(kcontrol), 0x76, 0x0008, 37189e285e1aSJohn L. Utz III ucontrol->value.enumerated.item[0] << 3); 37199e285e1aSJohn L. Utz III } 37209e285e1aSJohn L. Utz III 37219e285e1aSJohn L. Utz III static const struct snd_kcontrol_new snd_ac97_controls_vt1618[] = { 37229e285e1aSJohn L. Utz III AC97_SINGLE("Exchange Center/LFE", 0x5a, 8, 1, 0), 37239e285e1aSJohn L. Utz III AC97_SINGLE("DC Offset", 0x5a, 10, 1, 0), 37249e285e1aSJohn L. Utz III AC97_SINGLE("Soft Mute", 0x5c, 0, 1, 1), 37259e285e1aSJohn L. Utz III AC97_SINGLE("Headphone Amp", 0x5c, 5, 1, 1), 37269e285e1aSJohn L. Utz III AC97_DOUBLE("Back Surr Volume", 0x5e, 8, 0, 31, 1), 37279e285e1aSJohn L. Utz III AC97_SINGLE("Back Surr Switch", 0x5e, 15, 1, 1), 37289e285e1aSJohn L. Utz III { 37299e285e1aSJohn L. Utz III .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 37309e285e1aSJohn L. Utz III .name = "Speaker Jack Mode", 37319e285e1aSJohn L. Utz III .info = snd_ac97_vt1618_UAJ_info, 37329e285e1aSJohn L. Utz III .get = snd_ac97_vt1618_UAJ_get, 37339e285e1aSJohn L. Utz III .put = snd_ac97_vt1618_UAJ_put, 37349e285e1aSJohn L. Utz III .private_value = 0 37359e285e1aSJohn L. Utz III }, 37369e285e1aSJohn L. Utz III { 37379e285e1aSJohn L. Utz III .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 37389e285e1aSJohn L. Utz III .name = "Line Jack Mode", 37399e285e1aSJohn L. Utz III .info = snd_ac97_vt1618_UAJ_info, 37409e285e1aSJohn L. Utz III .get = snd_ac97_vt1618_UAJ_get, 37419e285e1aSJohn L. Utz III .put = snd_ac97_vt1618_UAJ_put, 37429e285e1aSJohn L. Utz III .private_value = 1 37439e285e1aSJohn L. Utz III }, 37449e285e1aSJohn L. Utz III { 37459e285e1aSJohn L. Utz III .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 37469e285e1aSJohn L. Utz III .name = "Mic Jack Mode", 37479e285e1aSJohn L. Utz III .info = snd_ac97_vt1618_UAJ_info, 37489e285e1aSJohn L. Utz III .get = snd_ac97_vt1618_UAJ_get, 37499e285e1aSJohn L. Utz III .put = snd_ac97_vt1618_UAJ_put, 37509e285e1aSJohn L. Utz III .private_value = 2 37519e285e1aSJohn L. Utz III }, 37529e285e1aSJohn L. Utz III { 37539e285e1aSJohn L. Utz III .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 37549e285e1aSJohn L. Utz III .name = "Aux Jack Mode", 37559e285e1aSJohn L. Utz III .info = snd_ac97_vt1618_aux_info, 37569e285e1aSJohn L. Utz III .get = snd_ac97_vt1618_aux_get, 37579e285e1aSJohn L. Utz III .put = snd_ac97_vt1618_aux_put, 37589e285e1aSJohn L. Utz III } 37599e285e1aSJohn L. Utz III }; 37609e285e1aSJohn L. Utz III 3761b03671a8SHarvey Harrison static int patch_vt1618(struct snd_ac97 *ac97) 37629e285e1aSJohn L. Utz III { 37639e285e1aSJohn L. Utz III return patch_build_controls(ac97, snd_ac97_controls_vt1618, 37649e285e1aSJohn L. Utz III ARRAY_SIZE(snd_ac97_controls_vt1618)); 37659e285e1aSJohn L. Utz III } 37669e285e1aSJohn L. Utz III 37674b499486SPhilip Prindeville /* 3768eb8caf30STakashi Iwai */ 3769ee42381eSTakashi Iwai static void it2646_update_jacks(struct snd_ac97 *ac97) 3770eb8caf30STakashi Iwai { 3771831466f4SRandy Cushman /* shared Line-In / Surround Out */ 3772eb8caf30STakashi Iwai snd_ac97_update_bits(ac97, 0x76, 1 << 9, 3773831466f4SRandy Cushman is_shared_surrout(ac97) ? (1<<9) : 0); 3774831466f4SRandy Cushman /* shared Mic / Center/LFE Out */ 3775eb8caf30STakashi Iwai snd_ac97_update_bits(ac97, 0x76, 1 << 10, 3776831466f4SRandy Cushman is_shared_clfeout(ac97) ? (1<<10) : 0); 3777eb8caf30STakashi Iwai } 3778eb8caf30STakashi Iwai 3779ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_it2646[] = { 3780eb8caf30STakashi Iwai AC97_SURROUND_JACK_MODE_CTL, 3781eb8caf30STakashi Iwai AC97_CHANNEL_MODE_CTL, 37821da177e4SLinus Torvalds }; 37831da177e4SLinus Torvalds 3784ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_spdif_controls_it2646[] = { 378510e8d78aSClemens Ladisch AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 0x76, 11, 1, 0), 37861da177e4SLinus Torvalds AC97_SINGLE("Analog to IEC958 Output", 0x76, 12, 1, 0), 37871da177e4SLinus Torvalds AC97_SINGLE("IEC958 Input Monitor", 0x76, 13, 1, 0), 37881da177e4SLinus Torvalds }; 37891da177e4SLinus Torvalds 3790ee42381eSTakashi Iwai static int patch_it2646_specific(struct snd_ac97 * ac97) 37911da177e4SLinus Torvalds { 37921da177e4SLinus Torvalds int err; 37931da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, snd_ac97_controls_it2646, ARRAY_SIZE(snd_ac97_controls_it2646))) < 0) 37941da177e4SLinus Torvalds return err; 37951da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_it2646, ARRAY_SIZE(snd_ac97_spdif_controls_it2646))) < 0) 37961da177e4SLinus Torvalds return err; 37971da177e4SLinus Torvalds return 0; 37981da177e4SLinus Torvalds } 37991da177e4SLinus Torvalds 3800*3e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_it2646_ops = { 3801eb8caf30STakashi Iwai .build_specific = patch_it2646_specific, 3802eb8caf30STakashi Iwai .update_jacks = it2646_update_jacks 38031da177e4SLinus Torvalds }; 38041da177e4SLinus Torvalds 3805ac519028STakashi Iwai static int patch_it2646(struct snd_ac97 * ac97) 38061da177e4SLinus Torvalds { 38071da177e4SLinus Torvalds ac97->build_ops = &patch_it2646_ops; 38081da177e4SLinus Torvalds /* full DAC volume */ 38091da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x5E, 0x0808); 38101da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x7A, 0x0808); 38111da177e4SLinus Torvalds return 0; 38121da177e4SLinus Torvalds } 38131da177e4SLinus Torvalds 381487d61c29SSasha Khapyorsky /* 381587d61c29SSasha Khapyorsky * Si3036 codec 381687d61c29SSasha Khapyorsky */ 381787d61c29SSasha Khapyorsky 38181da177e4SLinus Torvalds #define AC97_SI3036_CHIP_ID 0x5a 381987d61c29SSasha Khapyorsky #define AC97_SI3036_LINE_CFG 0x5c 382087d61c29SSasha Khapyorsky 3821ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_si3036[] = { 382287d61c29SSasha Khapyorsky AC97_DOUBLE("Modem Speaker Volume", 0x5c, 14, 12, 3, 1) 382387d61c29SSasha Khapyorsky }; 382487d61c29SSasha Khapyorsky 3825ee42381eSTakashi Iwai static int patch_si3036_specific(struct snd_ac97 * ac97) 382687d61c29SSasha Khapyorsky { 382727bcaa69SSasha Khapyorsky int idx, err; 382827bcaa69SSasha Khapyorsky for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_si3036); idx++) 382927bcaa69SSasha Khapyorsky if ((err = snd_ctl_add(ac97->bus->card, snd_ctl_new1(&snd_ac97_controls_si3036[idx], ac97))) < 0) 383027bcaa69SSasha Khapyorsky return err; 383127bcaa69SSasha Khapyorsky return 0; 383287d61c29SSasha Khapyorsky } 383387d61c29SSasha Khapyorsky 3834*3e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_si3036_ops = { 383587d61c29SSasha Khapyorsky .build_specific = patch_si3036_specific, 383687d61c29SSasha Khapyorsky }; 38371da177e4SLinus Torvalds 3838ac519028STakashi Iwai static int mpatch_si3036(struct snd_ac97 * ac97) 38391da177e4SLinus Torvalds { 384087d61c29SSasha Khapyorsky ac97->build_ops = &patch_si3036_ops; 38411da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x5c, 0xf210 ); 38421da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x68, 0); 38431da177e4SLinus Torvalds return 0; 38441da177e4SLinus Torvalds } 3845ba22429dSCharl Coetzee 3846ba22429dSCharl Coetzee /* 3847ba22429dSCharl Coetzee * LM 4550 Codec 3848ba22429dSCharl Coetzee * 3849ba22429dSCharl Coetzee * We use a static resolution table since LM4550 codec cannot be 3850ba22429dSCharl Coetzee * properly autoprobed to determine the resolution via 3851ba22429dSCharl Coetzee * check_volume_resolution(). 3852ba22429dSCharl Coetzee */ 3853ba22429dSCharl Coetzee 3854ba22429dSCharl Coetzee static struct snd_ac97_res_table lm4550_restbl[] = { 3855ba22429dSCharl Coetzee { AC97_MASTER, 0x1f1f }, 3856ba22429dSCharl Coetzee { AC97_HEADPHONE, 0x1f1f }, 3857ba22429dSCharl Coetzee { AC97_MASTER_MONO, 0x001f }, 3858ba22429dSCharl Coetzee { AC97_PC_BEEP, 0x001f }, /* LSB is ignored */ 3859ba22429dSCharl Coetzee { AC97_PHONE, 0x001f }, 3860ba22429dSCharl Coetzee { AC97_MIC, 0x001f }, 3861ba22429dSCharl Coetzee { AC97_LINE, 0x1f1f }, 3862ba22429dSCharl Coetzee { AC97_CD, 0x1f1f }, 3863ba22429dSCharl Coetzee { AC97_VIDEO, 0x1f1f }, 3864ba22429dSCharl Coetzee { AC97_AUX, 0x1f1f }, 3865ba22429dSCharl Coetzee { AC97_PCM, 0x1f1f }, 3866ba22429dSCharl Coetzee { AC97_REC_GAIN, 0x0f0f }, 3867ba22429dSCharl Coetzee { } /* terminator */ 3868ba22429dSCharl Coetzee }; 3869ba22429dSCharl Coetzee 3870ac519028STakashi Iwai static int patch_lm4550(struct snd_ac97 *ac97) 3871ba22429dSCharl Coetzee { 3872ba22429dSCharl Coetzee ac97->res_table = lm4550_restbl; 3873ba22429dSCharl Coetzee return 0; 3874ba22429dSCharl Coetzee } 387582466ad7SMike Rapoport 387682466ad7SMike Rapoport /* 387782466ad7SMike Rapoport * UCB1400 codec (http://www.semiconductors.philips.com/acrobat_download/datasheets/UCB1400-02.pdf) 387882466ad7SMike Rapoport */ 387982466ad7SMike Rapoport static const struct snd_kcontrol_new snd_ac97_controls_ucb1400[] = { 388082466ad7SMike Rapoport /* enable/disable headphone driver which allows direct connection to 388182466ad7SMike Rapoport stereo headphone without the use of external DC blocking 388282466ad7SMike Rapoport capacitors */ 388382466ad7SMike Rapoport AC97_SINGLE("Headphone Driver", 0x6a, 6, 1, 0), 388482466ad7SMike Rapoport /* Filter used to compensate the DC offset is added in the ADC to remove idle 388582466ad7SMike Rapoport tones from the audio band. */ 388682466ad7SMike Rapoport AC97_SINGLE("DC Filter", 0x6a, 4, 1, 0), 388782466ad7SMike Rapoport /* Control smart-low-power mode feature. Allows automatic power down 388882466ad7SMike Rapoport of unused blocks in the ADC analog front end and the PLL. */ 388982466ad7SMike Rapoport AC97_SINGLE("Smart Low Power Mode", 0x6c, 4, 3, 0), 389082466ad7SMike Rapoport }; 389182466ad7SMike Rapoport 389282466ad7SMike Rapoport static int patch_ucb1400_specific(struct snd_ac97 * ac97) 389382466ad7SMike Rapoport { 389482466ad7SMike Rapoport int idx, err; 389582466ad7SMike Rapoport for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_ucb1400); idx++) 389682466ad7SMike Rapoport if ((err = snd_ctl_add(ac97->bus->card, snd_ctl_new1(&snd_ac97_controls_ucb1400[idx], ac97))) < 0) 389782466ad7SMike Rapoport return err; 389882466ad7SMike Rapoport return 0; 389982466ad7SMike Rapoport } 390082466ad7SMike Rapoport 3901*3e8b3b90SHanno Boeck static const struct snd_ac97_build_ops patch_ucb1400_ops = { 390282466ad7SMike Rapoport .build_specific = patch_ucb1400_specific, 390382466ad7SMike Rapoport }; 390482466ad7SMike Rapoport 3905ac519028STakashi Iwai static int patch_ucb1400(struct snd_ac97 * ac97) 390682466ad7SMike Rapoport { 390782466ad7SMike Rapoport ac97->build_ops = &patch_ucb1400_ops; 390882466ad7SMike Rapoport /* enable headphone driver and smart low power mode by default */ 390925552e87SMike Rapoport snd_ac97_write_cache(ac97, 0x6a, 0x0050); 391025552e87SMike Rapoport snd_ac97_write_cache(ac97, 0x6c, 0x0030); 391182466ad7SMike Rapoport return 0; 391282466ad7SMike Rapoport } 3913