11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * Copyright (c) by Jaroslav Kysela <perex@suse.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 { 117eb8caf30STakashi Iwai static const char *texts[] = { "2ch", "4ch", "6ch" }; 118eb8caf30STakashi Iwai if (kcontrol->private_value) 119eb8caf30STakashi Iwai return ac97_enum_text_info(kcontrol, uinfo, texts, 2); /* 4ch only */ 120eb8caf30STakashi Iwai return ac97_enum_text_info(kcontrol, uinfo, texts, 3); 121eb8caf30STakashi Iwai } 122eb8caf30STakashi Iwai 123ee42381eSTakashi Iwai static int ac97_channel_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 124eb8caf30STakashi Iwai { 125ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 126eb8caf30STakashi Iwai 127eb8caf30STakashi Iwai ucontrol->value.enumerated.item[0] = ac97->channel_mode; 128eb8caf30STakashi Iwai return 0; 129eb8caf30STakashi Iwai } 130eb8caf30STakashi Iwai 131ee42381eSTakashi Iwai static int ac97_channel_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 132eb8caf30STakashi Iwai { 133ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 134eb8caf30STakashi Iwai unsigned char mode = ucontrol->value.enumerated.item[0]; 135eb8caf30STakashi Iwai 136eb8caf30STakashi Iwai if (mode != ac97->channel_mode) { 137eb8caf30STakashi Iwai ac97->channel_mode = mode; 138eb8caf30STakashi Iwai if (ac97->build_ops->update_jacks) 139eb8caf30STakashi Iwai ac97->build_ops->update_jacks(ac97); 140eb8caf30STakashi Iwai return 1; 141eb8caf30STakashi Iwai } 142eb8caf30STakashi Iwai return 0; 143eb8caf30STakashi Iwai } 144eb8caf30STakashi Iwai 145eb8caf30STakashi Iwai #define AC97_SURROUND_JACK_MODE_CTL \ 146eb8caf30STakashi Iwai { \ 147eb8caf30STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 148eb8caf30STakashi Iwai .name = "Surround Jack Mode", \ 149eb8caf30STakashi Iwai .info = ac97_surround_jack_mode_info, \ 150eb8caf30STakashi Iwai .get = ac97_surround_jack_mode_get, \ 151eb8caf30STakashi Iwai .put = ac97_surround_jack_mode_put, \ 152eb8caf30STakashi Iwai } 153eb8caf30STakashi Iwai #define AC97_CHANNEL_MODE_CTL \ 154eb8caf30STakashi Iwai { \ 155eb8caf30STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 156eb8caf30STakashi Iwai .name = "Channel Mode", \ 157eb8caf30STakashi Iwai .info = ac97_channel_mode_info, \ 158eb8caf30STakashi Iwai .get = ac97_channel_mode_get, \ 159eb8caf30STakashi Iwai .put = ac97_channel_mode_put, \ 160eb8caf30STakashi Iwai } 161eb8caf30STakashi Iwai #define AC97_CHANNEL_MODE_4CH_CTL \ 162eb8caf30STakashi Iwai { \ 163eb8caf30STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 164eb8caf30STakashi Iwai .name = "Channel Mode", \ 165eb8caf30STakashi Iwai .info = ac97_channel_mode_info, \ 166eb8caf30STakashi Iwai .get = ac97_channel_mode_get, \ 167eb8caf30STakashi Iwai .put = ac97_channel_mode_put, \ 168eb8caf30STakashi Iwai .private_value = 1, \ 169eb8caf30STakashi Iwai } 170eb8caf30STakashi Iwai 171ee42381eSTakashi Iwai static inline int is_surround_on(struct snd_ac97 *ac97) 1724525c9f3STakashi Iwai { 1734525c9f3STakashi Iwai return ac97->channel_mode >= 1; 1744525c9f3STakashi Iwai } 1754525c9f3STakashi Iwai 176ee42381eSTakashi Iwai static inline int is_clfe_on(struct snd_ac97 *ac97) 1774525c9f3STakashi Iwai { 178eb9b4142STakashi Iwai return ac97->channel_mode >= 2; 1794525c9f3STakashi Iwai } 1804525c9f3STakashi Iwai 181831466f4SRandy Cushman /* system has shared jacks with surround out enabled */ 182831466f4SRandy Cushman static inline int is_shared_surrout(struct snd_ac97 *ac97) 183eb8caf30STakashi Iwai { 1844525c9f3STakashi Iwai return !ac97->indep_surround && is_surround_on(ac97); 185eb8caf30STakashi Iwai } 186eb8caf30STakashi Iwai 187831466f4SRandy Cushman /* system has shared jacks with center/lfe out enabled */ 188831466f4SRandy Cushman static inline int is_shared_clfeout(struct snd_ac97 *ac97) 189eb8caf30STakashi Iwai { 1904525c9f3STakashi Iwai return !ac97->indep_surround && is_clfe_on(ac97); 191eb8caf30STakashi Iwai } 192eb8caf30STakashi Iwai 193831466f4SRandy Cushman /* system has shared jacks with line in enabled */ 194831466f4SRandy Cushman static inline int is_shared_linein(struct snd_ac97 *ac97) 195831466f4SRandy Cushman { 196831466f4SRandy Cushman return !ac97->indep_surround && !is_surround_on(ac97); 197831466f4SRandy Cushman } 198831466f4SRandy Cushman 199831466f4SRandy Cushman /* system has shared jacks with mic in enabled */ 200831466f4SRandy Cushman static inline int is_shared_micin(struct snd_ac97 *ac97) 201831466f4SRandy Cushman { 202831466f4SRandy Cushman return !ac97->indep_surround && !is_clfe_on(ac97); 203831466f4SRandy Cushman } 204831466f4SRandy Cushman 205eb8caf30STakashi Iwai 2061da177e4SLinus Torvalds /* The following snd_ac97_ymf753_... items added by David Shust (dshust@shustring.com) */ 2071da177e4SLinus Torvalds 2081da177e4SLinus Torvalds /* It is possible to indicate to the Yamaha YMF753 the type of speakers being used. */ 209ee42381eSTakashi Iwai static int snd_ac97_ymf753_info_speaker(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 2101da177e4SLinus Torvalds { 2111da177e4SLinus Torvalds static char *texts[3] = { 2121da177e4SLinus Torvalds "Standard", "Small", "Smaller" 2131da177e4SLinus Torvalds }; 2141da177e4SLinus Torvalds 2151da177e4SLinus Torvalds uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2161da177e4SLinus Torvalds uinfo->count = 1; 2171da177e4SLinus Torvalds uinfo->value.enumerated.items = 3; 2181da177e4SLinus Torvalds if (uinfo->value.enumerated.item > 2) 2191da177e4SLinus Torvalds uinfo->value.enumerated.item = 2; 2201da177e4SLinus Torvalds strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 2211da177e4SLinus Torvalds return 0; 2221da177e4SLinus Torvalds } 2231da177e4SLinus Torvalds 224ee42381eSTakashi Iwai static int snd_ac97_ymf753_get_speaker(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2251da177e4SLinus Torvalds { 226ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 2271da177e4SLinus Torvalds unsigned short val; 2281da177e4SLinus Torvalds 2291da177e4SLinus Torvalds val = ac97->regs[AC97_YMF753_3D_MODE_SEL]; 2301da177e4SLinus Torvalds val = (val >> 10) & 3; 2311da177e4SLinus Torvalds if (val > 0) /* 0 = invalid */ 2321da177e4SLinus Torvalds val--; 2331da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = val; 2341da177e4SLinus Torvalds return 0; 2351da177e4SLinus Torvalds } 2361da177e4SLinus Torvalds 237ee42381eSTakashi Iwai static int snd_ac97_ymf753_put_speaker(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2381da177e4SLinus Torvalds { 239ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 2401da177e4SLinus Torvalds unsigned short val; 2411da177e4SLinus Torvalds 2421da177e4SLinus Torvalds if (ucontrol->value.enumerated.item[0] > 2) 2431da177e4SLinus Torvalds return -EINVAL; 2441da177e4SLinus Torvalds val = (ucontrol->value.enumerated.item[0] + 1) << 10; 2451da177e4SLinus Torvalds return snd_ac97_update(ac97, AC97_YMF753_3D_MODE_SEL, val); 2461da177e4SLinus Torvalds } 2471da177e4SLinus Torvalds 248ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ymf753_controls_speaker = 2491da177e4SLinus Torvalds { 2501da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2511da177e4SLinus Torvalds .name = "3D Control - Speaker", 2521da177e4SLinus Torvalds .info = snd_ac97_ymf753_info_speaker, 2531da177e4SLinus Torvalds .get = snd_ac97_ymf753_get_speaker, 2541da177e4SLinus Torvalds .put = snd_ac97_ymf753_put_speaker, 2551da177e4SLinus Torvalds }; 2561da177e4SLinus Torvalds 2571da177e4SLinus Torvalds /* It is possible to indicate to the Yamaha YMF753 the source to direct to the S/PDIF output. */ 258ee42381eSTakashi Iwai static int snd_ac97_ymf753_spdif_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 2591da177e4SLinus Torvalds { 2601da177e4SLinus Torvalds static char *texts[2] = { "AC-Link", "A/D Converter" }; 2611da177e4SLinus Torvalds 2621da177e4SLinus Torvalds uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2631da177e4SLinus Torvalds uinfo->count = 1; 2641da177e4SLinus Torvalds uinfo->value.enumerated.items = 2; 2651da177e4SLinus Torvalds if (uinfo->value.enumerated.item > 1) 2661da177e4SLinus Torvalds uinfo->value.enumerated.item = 1; 2671da177e4SLinus Torvalds strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 2681da177e4SLinus Torvalds return 0; 2691da177e4SLinus Torvalds } 2701da177e4SLinus Torvalds 271ee42381eSTakashi Iwai static int snd_ac97_ymf753_spdif_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2721da177e4SLinus Torvalds { 273ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 2741da177e4SLinus Torvalds unsigned short val; 2751da177e4SLinus Torvalds 2761da177e4SLinus Torvalds val = ac97->regs[AC97_YMF753_DIT_CTRL2]; 2771da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = (val >> 1) & 1; 2781da177e4SLinus Torvalds return 0; 2791da177e4SLinus Torvalds } 2801da177e4SLinus Torvalds 281ee42381eSTakashi Iwai static int snd_ac97_ymf753_spdif_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2821da177e4SLinus Torvalds { 283ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 2841da177e4SLinus Torvalds unsigned short val; 2851da177e4SLinus Torvalds 2861da177e4SLinus Torvalds if (ucontrol->value.enumerated.item[0] > 1) 2871da177e4SLinus Torvalds return -EINVAL; 2881da177e4SLinus Torvalds val = ucontrol->value.enumerated.item[0] << 1; 2891da177e4SLinus Torvalds return snd_ac97_update_bits(ac97, AC97_YMF753_DIT_CTRL2, 0x0002, val); 2901da177e4SLinus Torvalds } 2911da177e4SLinus Torvalds 2921da177e4SLinus Torvalds /* The AC'97 spec states that the S/PDIF signal is to be output at pin 48. 2931da177e4SLinus Torvalds The YMF753 will output the S/PDIF signal to pin 43, 47 (EAPD), or 48. 2941da177e4SLinus Torvalds By default, no output pin is selected, and the S/PDIF signal is not output. 2951da177e4SLinus Torvalds There is also a bit to mute S/PDIF output in a vendor-specific register. */ 296ee42381eSTakashi Iwai static int snd_ac97_ymf753_spdif_output_pin_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 2971da177e4SLinus Torvalds { 2981da177e4SLinus Torvalds static char *texts[3] = { "Disabled", "Pin 43", "Pin 48" }; 2991da177e4SLinus Torvalds 3001da177e4SLinus Torvalds uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 3011da177e4SLinus Torvalds uinfo->count = 1; 3021da177e4SLinus Torvalds uinfo->value.enumerated.items = 3; 3031da177e4SLinus Torvalds if (uinfo->value.enumerated.item > 2) 3041da177e4SLinus Torvalds uinfo->value.enumerated.item = 2; 3051da177e4SLinus Torvalds strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 3061da177e4SLinus Torvalds return 0; 3071da177e4SLinus Torvalds } 3081da177e4SLinus Torvalds 309ee42381eSTakashi Iwai static int snd_ac97_ymf753_spdif_output_pin_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 3101da177e4SLinus Torvalds { 311ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 3121da177e4SLinus Torvalds unsigned short val; 3131da177e4SLinus Torvalds 3141da177e4SLinus Torvalds val = ac97->regs[AC97_YMF753_DIT_CTRL2]; 3151da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = (val & 0x0008) ? 2 : (val & 0x0020) ? 1 : 0; 3161da177e4SLinus Torvalds return 0; 3171da177e4SLinus Torvalds } 3181da177e4SLinus Torvalds 319ee42381eSTakashi Iwai static int snd_ac97_ymf753_spdif_output_pin_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 3201da177e4SLinus Torvalds { 321ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 3221da177e4SLinus Torvalds unsigned short val; 3231da177e4SLinus Torvalds 3241da177e4SLinus Torvalds if (ucontrol->value.enumerated.item[0] > 2) 3251da177e4SLinus Torvalds return -EINVAL; 3261da177e4SLinus Torvalds val = (ucontrol->value.enumerated.item[0] == 2) ? 0x0008 : 3271da177e4SLinus Torvalds (ucontrol->value.enumerated.item[0] == 1) ? 0x0020 : 0; 3281da177e4SLinus Torvalds return snd_ac97_update_bits(ac97, AC97_YMF753_DIT_CTRL2, 0x0028, val); 3291da177e4SLinus Torvalds /* The following can be used to direct S/PDIF output to pin 47 (EAPD). 3301da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x62, snd_ac97_read(ac97, 0x62) | 0x0008); */ 3311da177e4SLinus Torvalds } 3321da177e4SLinus Torvalds 333ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ymf753_controls_spdif[3] = { 3341da177e4SLinus Torvalds { 3351da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 3361da177e4SLinus Torvalds .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source", 3371da177e4SLinus Torvalds .info = snd_ac97_ymf753_spdif_source_info, 3381da177e4SLinus Torvalds .get = snd_ac97_ymf753_spdif_source_get, 3391da177e4SLinus Torvalds .put = snd_ac97_ymf753_spdif_source_put, 3401da177e4SLinus Torvalds }, 3411da177e4SLinus Torvalds { 3421da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 3431da177e4SLinus Torvalds .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Output Pin", 3441da177e4SLinus Torvalds .info = snd_ac97_ymf753_spdif_output_pin_info, 3451da177e4SLinus Torvalds .get = snd_ac97_ymf753_spdif_output_pin_get, 3461da177e4SLinus Torvalds .put = snd_ac97_ymf753_spdif_output_pin_put, 3471da177e4SLinus Torvalds }, 3481da177e4SLinus Torvalds AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",NONE,NONE) "Mute", AC97_YMF753_DIT_CTRL2, 2, 1, 1) 3491da177e4SLinus Torvalds }; 3501da177e4SLinus Torvalds 351ee42381eSTakashi Iwai static int patch_yamaha_ymf753_3d(struct snd_ac97 * ac97) 3521da177e4SLinus Torvalds { 353ee42381eSTakashi Iwai struct snd_kcontrol *kctl; 3541da177e4SLinus Torvalds int err; 3551da177e4SLinus Torvalds 3561da177e4SLinus Torvalds if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0) 3571da177e4SLinus Torvalds return err; 3581da177e4SLinus Torvalds strcpy(kctl->id.name, "3D Control - Wide"); 3591da177e4SLinus Torvalds kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 9, 7, 0); 3601da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000); 3611da177e4SLinus Torvalds if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&snd_ac97_ymf753_controls_speaker, ac97))) < 0) 3621da177e4SLinus Torvalds return err; 3631da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_YMF753_3D_MODE_SEL, 0x0c00); 3641da177e4SLinus Torvalds return 0; 3651da177e4SLinus Torvalds } 3661da177e4SLinus Torvalds 367ee42381eSTakashi Iwai static int patch_yamaha_ymf753_post_spdif(struct snd_ac97 * ac97) 3681da177e4SLinus Torvalds { 3691da177e4SLinus Torvalds int err; 3701da177e4SLinus Torvalds 3711da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, snd_ac97_ymf753_controls_spdif, ARRAY_SIZE(snd_ac97_ymf753_controls_spdif))) < 0) 3721da177e4SLinus Torvalds return err; 3731da177e4SLinus Torvalds return 0; 3741da177e4SLinus Torvalds } 3751da177e4SLinus Torvalds 3761da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_yamaha_ymf753_ops = { 3771da177e4SLinus Torvalds .build_3d = patch_yamaha_ymf753_3d, 3781da177e4SLinus Torvalds .build_post_spdif = patch_yamaha_ymf753_post_spdif 3791da177e4SLinus Torvalds }; 3801da177e4SLinus Torvalds 381ac519028STakashi Iwai static int patch_yamaha_ymf753(struct snd_ac97 * ac97) 3821da177e4SLinus Torvalds { 3831da177e4SLinus Torvalds /* Patch for Yamaha YMF753, Copyright (c) by David Shust, dshust@shustring.com. 3841da177e4SLinus Torvalds This chip has nonstandard and extended behaviour with regard to its S/PDIF output. 3851da177e4SLinus Torvalds The AC'97 spec states that the S/PDIF signal is to be output at pin 48. 3861da177e4SLinus Torvalds The YMF753 will ouput the S/PDIF signal to pin 43, 47 (EAPD), or 48. 3871da177e4SLinus Torvalds By default, no output pin is selected, and the S/PDIF signal is not output. 3881da177e4SLinus Torvalds There is also a bit to mute S/PDIF output in a vendor-specific register. 3891da177e4SLinus Torvalds */ 3901da177e4SLinus Torvalds ac97->build_ops = &patch_yamaha_ymf753_ops; 3911da177e4SLinus Torvalds ac97->caps |= AC97_BC_BASS_TREBLE; 3921da177e4SLinus Torvalds ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */ 3931da177e4SLinus Torvalds return 0; 3941da177e4SLinus Torvalds } 3951da177e4SLinus Torvalds 3961da177e4SLinus Torvalds /* 3971da177e4SLinus Torvalds * May 2, 2003 Liam Girdwood <liam.girdwood@wolfsonmicro.com> 3981da177e4SLinus Torvalds * removed broken wolfson00 patch. 3991da177e4SLinus Torvalds * added support for WM9705,WM9708,WM9709,WM9710,WM9711,WM9712 and WM9717. 4001da177e4SLinus Torvalds */ 4011da177e4SLinus Torvalds 402ee42381eSTakashi Iwai static const struct snd_kcontrol_new wm97xx_snd_ac97_controls[] = { 4033998b70fSLiam Girdwood AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1), 4043998b70fSLiam Girdwood AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1), 4053998b70fSLiam Girdwood }; 4063998b70fSLiam Girdwood 407ee42381eSTakashi Iwai static int patch_wolfson_wm9703_specific(struct snd_ac97 * ac97) 4081da177e4SLinus Torvalds { 4091da177e4SLinus Torvalds /* This is known to work for the ViewSonic ViewPad 1000 4103998b70fSLiam Girdwood * Randolph Bentson <bentson@holmsjoen.com> 4113998b70fSLiam Girdwood * WM9703/9707/9708/9717 4123998b70fSLiam Girdwood */ 4133998b70fSLiam Girdwood int err, i; 4141da177e4SLinus Torvalds 4153998b70fSLiam Girdwood for (i = 0; i < ARRAY_SIZE(wm97xx_snd_ac97_controls); i++) { 4163998b70fSLiam Girdwood if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm97xx_snd_ac97_controls[i], ac97))) < 0) 4173998b70fSLiam Girdwood return err; 4183998b70fSLiam Girdwood } 4191da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808); 4201da177e4SLinus Torvalds return 0; 4211da177e4SLinus Torvalds } 4221da177e4SLinus Torvalds 4233998b70fSLiam Girdwood static struct snd_ac97_build_ops patch_wolfson_wm9703_ops = { 4243998b70fSLiam Girdwood .build_specific = patch_wolfson_wm9703_specific, 4253998b70fSLiam Girdwood }; 4263998b70fSLiam Girdwood 427ac519028STakashi Iwai static int patch_wolfson03(struct snd_ac97 * ac97) 4283998b70fSLiam Girdwood { 4293998b70fSLiam Girdwood ac97->build_ops = &patch_wolfson_wm9703_ops; 4303998b70fSLiam Girdwood return 0; 4313998b70fSLiam Girdwood } 4323998b70fSLiam Girdwood 433ee42381eSTakashi Iwai static const struct snd_kcontrol_new wm9704_snd_ac97_controls[] = { 4343998b70fSLiam Girdwood AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1), 4353998b70fSLiam Girdwood AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1), 4363998b70fSLiam Girdwood AC97_DOUBLE("Rear Playback Volume", AC97_WM9704_RMIXER_VOL, 8, 0, 31, 1), 4373998b70fSLiam Girdwood AC97_SINGLE("Rear Playback Switch", AC97_WM9704_RMIXER_VOL, 15, 1, 1), 4383998b70fSLiam Girdwood AC97_DOUBLE("Rear DAC Volume", AC97_WM9704_RPCM_VOL, 8, 0, 31, 1), 4393998b70fSLiam Girdwood AC97_DOUBLE("Surround Volume", AC97_SURROUND_MASTER, 8, 0, 31, 1), 4403998b70fSLiam Girdwood }; 4413998b70fSLiam Girdwood 442ee42381eSTakashi Iwai static int patch_wolfson_wm9704_specific(struct snd_ac97 * ac97) 4433998b70fSLiam Girdwood { 4443998b70fSLiam Girdwood int err, i; 4453998b70fSLiam Girdwood for (i = 0; i < ARRAY_SIZE(wm9704_snd_ac97_controls); i++) { 4463998b70fSLiam Girdwood if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9704_snd_ac97_controls[i], ac97))) < 0) 4473998b70fSLiam Girdwood return err; 4483998b70fSLiam Girdwood } 4493998b70fSLiam Girdwood /* patch for DVD noise */ 4503998b70fSLiam Girdwood snd_ac97_write_cache(ac97, AC97_WM9704_TEST, 0x0200); 4513998b70fSLiam Girdwood return 0; 4523998b70fSLiam Girdwood } 4533998b70fSLiam Girdwood 4543998b70fSLiam Girdwood static struct snd_ac97_build_ops patch_wolfson_wm9704_ops = { 4553998b70fSLiam Girdwood .build_specific = patch_wolfson_wm9704_specific, 4563998b70fSLiam Girdwood }; 4573998b70fSLiam Girdwood 458ac519028STakashi Iwai static int patch_wolfson04(struct snd_ac97 * ac97) 4591da177e4SLinus Torvalds { 4603998b70fSLiam Girdwood /* WM9704M/9704Q */ 4613998b70fSLiam Girdwood ac97->build_ops = &patch_wolfson_wm9704_ops; 4621da177e4SLinus Torvalds return 0; 4631da177e4SLinus Torvalds } 4641da177e4SLinus Torvalds 465ee42381eSTakashi Iwai static int patch_wolfson_wm9705_specific(struct snd_ac97 * ac97) 4663998b70fSLiam Girdwood { 4673998b70fSLiam Girdwood int err, i; 4683998b70fSLiam Girdwood for (i = 0; i < ARRAY_SIZE(wm97xx_snd_ac97_controls); i++) { 4693998b70fSLiam Girdwood if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm97xx_snd_ac97_controls[i], ac97))) < 0) 4703998b70fSLiam Girdwood return err; 4713998b70fSLiam Girdwood } 4723998b70fSLiam Girdwood snd_ac97_write_cache(ac97, 0x72, 0x0808); 4733998b70fSLiam Girdwood return 0; 4743998b70fSLiam Girdwood } 4753998b70fSLiam Girdwood 4763998b70fSLiam Girdwood static struct snd_ac97_build_ops patch_wolfson_wm9705_ops = { 4773998b70fSLiam Girdwood .build_specific = patch_wolfson_wm9705_specific, 4783998b70fSLiam Girdwood }; 4793998b70fSLiam Girdwood 480ac519028STakashi Iwai static int patch_wolfson05(struct snd_ac97 * ac97) 4811da177e4SLinus Torvalds { 4823998b70fSLiam Girdwood /* WM9705, WM9710 */ 4833998b70fSLiam Girdwood ac97->build_ops = &patch_wolfson_wm9705_ops; 4841459c784SRodolfo Giometti #ifdef CONFIG_TOUCHSCREEN_WM9705 4851459c784SRodolfo Giometti /* WM9705 touchscreen uses AUX and VIDEO for touch */ 4868f88820eSLiam Girdwood ac97->flags |= AC97_HAS_NO_VIDEO | AC97_HAS_NO_AUX; 4871459c784SRodolfo Giometti #endif 4881da177e4SLinus Torvalds return 0; 4891da177e4SLinus Torvalds } 4901da177e4SLinus Torvalds 4913998b70fSLiam Girdwood static const char* wm9711_alc_select[] = {"None", "Left", "Right", "Stereo"}; 4923998b70fSLiam Girdwood static const char* wm9711_alc_mix[] = {"Stereo", "Right", "Left", "None"}; 4933998b70fSLiam Girdwood static const char* wm9711_out3_src[] = {"Left", "VREF", "Left + Right", "Mono"}; 4943998b70fSLiam Girdwood static const char* wm9711_out3_lrsrc[] = {"Master Mix", "Headphone Mix"}; 4953998b70fSLiam Girdwood static const char* wm9711_rec_adc[] = {"Stereo", "Left", "Right", "Mute"}; 4963998b70fSLiam Girdwood static const char* wm9711_base[] = {"Linear Control", "Adaptive Boost"}; 4973998b70fSLiam Girdwood static const char* wm9711_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"}; 4983998b70fSLiam Girdwood static const char* wm9711_mic[] = {"Mic 1", "Differential", "Mic 2", "Stereo"}; 4993998b70fSLiam Girdwood static const char* wm9711_rec_sel[] = 5003998b70fSLiam Girdwood {"Mic 1", "NC", "NC", "Master Mix", "Line", "Headphone Mix", "Phone Mix", "Phone"}; 5013998b70fSLiam Girdwood static const char* wm9711_ng_type[] = {"Constant Gain", "Mute"}; 5023998b70fSLiam Girdwood 5033998b70fSLiam Girdwood static const struct ac97_enum wm9711_enum[] = { 5043998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9711_alc_select), 5053998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_VIDEO, 10, 4, wm9711_alc_mix), 5063998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_AUX, 9, 4, wm9711_out3_src), 5073998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_AUX, 8, 2, wm9711_out3_lrsrc), 5083998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_REC_SEL, 12, 4, wm9711_rec_adc), 5093998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_MASTER_TONE, 15, 2, wm9711_base), 5103998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_REC_GAIN, 14, 6, 2, wm9711_rec_gain), 5113998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_MIC, 5, 4, wm9711_mic), 5123998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_REC_SEL, 8, 0, 8, wm9711_rec_sel), 5133998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9711_ng_type), 5143998b70fSLiam Girdwood }; 5153998b70fSLiam Girdwood 516ee42381eSTakashi Iwai static const struct snd_kcontrol_new wm9711_snd_ac97_controls[] = { 5173998b70fSLiam Girdwood AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0), 5183998b70fSLiam Girdwood AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0), 5193998b70fSLiam Girdwood AC97_SINGLE("ALC Decay Time", AC97_CODEC_CLASS_REV, 4, 15, 0), 5203998b70fSLiam Girdwood AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0), 5213998b70fSLiam Girdwood AC97_ENUM("ALC Function", wm9711_enum[0]), 5223998b70fSLiam Girdwood AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 1), 5233998b70fSLiam Girdwood AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 1), 5243998b70fSLiam Girdwood AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0), 5253998b70fSLiam Girdwood AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0), 5263998b70fSLiam Girdwood AC97_ENUM("ALC NG Type", wm9711_enum[9]), 5273998b70fSLiam Girdwood AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 1), 5283998b70fSLiam Girdwood 5293998b70fSLiam Girdwood AC97_SINGLE("Side Tone Switch", AC97_VIDEO, 15, 1, 1), 5303998b70fSLiam Girdwood AC97_SINGLE("Side Tone Volume", AC97_VIDEO, 12, 7, 1), 5313998b70fSLiam Girdwood AC97_ENUM("ALC Headphone Mux", wm9711_enum[1]), 5323998b70fSLiam Girdwood AC97_SINGLE("ALC Headphone Volume", AC97_VIDEO, 7, 7, 1), 5333998b70fSLiam Girdwood 5343998b70fSLiam Girdwood AC97_SINGLE("Out3 Switch", AC97_AUX, 15, 1, 1), 5352aedbda6SLuke Zhang AC97_SINGLE("Out3 ZC Switch", AC97_AUX, 7, 1, 0), 5363998b70fSLiam Girdwood AC97_ENUM("Out3 Mux", wm9711_enum[2]), 5373998b70fSLiam Girdwood AC97_ENUM("Out3 LR Mux", wm9711_enum[3]), 5383998b70fSLiam Girdwood AC97_SINGLE("Out3 Volume", AC97_AUX, 0, 31, 1), 5393998b70fSLiam Girdwood 5403998b70fSLiam Girdwood AC97_SINGLE("Beep to Headphone Switch", AC97_PC_BEEP, 15, 1, 1), 5413998b70fSLiam Girdwood AC97_SINGLE("Beep to Headphone Volume", AC97_PC_BEEP, 12, 7, 1), 5423998b70fSLiam Girdwood AC97_SINGLE("Beep to Side Tone Switch", AC97_PC_BEEP, 11, 1, 1), 5433998b70fSLiam Girdwood AC97_SINGLE("Beep to Side Tone Volume", AC97_PC_BEEP, 8, 7, 1), 5443998b70fSLiam Girdwood AC97_SINGLE("Beep to Phone Switch", AC97_PC_BEEP, 7, 1, 1), 5453998b70fSLiam Girdwood AC97_SINGLE("Beep to Phone Volume", AC97_PC_BEEP, 4, 7, 1), 5463998b70fSLiam Girdwood 5473998b70fSLiam Girdwood AC97_SINGLE("Aux to Headphone Switch", AC97_CD, 15, 1, 1), 5483998b70fSLiam Girdwood AC97_SINGLE("Aux to Headphone Volume", AC97_CD, 12, 7, 1), 5493998b70fSLiam Girdwood AC97_SINGLE("Aux to Side Tone Switch", AC97_CD, 11, 1, 1), 5503998b70fSLiam Girdwood AC97_SINGLE("Aux to Side Tone Volume", AC97_CD, 8, 7, 1), 5513998b70fSLiam Girdwood AC97_SINGLE("Aux to Phone Switch", AC97_CD, 7, 1, 1), 5523998b70fSLiam Girdwood AC97_SINGLE("Aux to Phone Volume", AC97_CD, 4, 7, 1), 5533998b70fSLiam Girdwood 5543998b70fSLiam Girdwood AC97_SINGLE("Phone to Headphone Switch", AC97_PHONE, 15, 1, 1), 5553998b70fSLiam Girdwood AC97_SINGLE("Phone to Master Switch", AC97_PHONE, 14, 1, 1), 5563998b70fSLiam Girdwood 5573998b70fSLiam Girdwood AC97_SINGLE("Line to Headphone Switch", AC97_LINE, 15, 1, 1), 5583998b70fSLiam Girdwood AC97_SINGLE("Line to Master Switch", AC97_LINE, 14, 1, 1), 5593998b70fSLiam Girdwood AC97_SINGLE("Line to Phone Switch", AC97_LINE, 13, 1, 1), 5603998b70fSLiam Girdwood 5613998b70fSLiam Girdwood AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PCM, 15, 1, 1), 5623998b70fSLiam Girdwood AC97_SINGLE("PCM Playback to Master Switch", AC97_PCM, 14, 1, 1), 5633998b70fSLiam Girdwood AC97_SINGLE("PCM Playback to Phone Switch", AC97_PCM, 13, 1, 1), 5643998b70fSLiam Girdwood 5653998b70fSLiam Girdwood AC97_SINGLE("Capture 20dB Boost Switch", AC97_REC_SEL, 14, 1, 0), 5663998b70fSLiam Girdwood AC97_ENUM("Capture to Phone Mux", wm9711_enum[4]), 5673998b70fSLiam Girdwood AC97_SINGLE("Capture to Phone 20dB Boost Switch", AC97_REC_SEL, 11, 1, 1), 5683998b70fSLiam Girdwood AC97_ENUM("Capture Select", wm9711_enum[8]), 5693998b70fSLiam Girdwood 5703998b70fSLiam Girdwood AC97_SINGLE("3D Upper Cut-off Switch", AC97_3D_CONTROL, 5, 1, 1), 5713998b70fSLiam Girdwood AC97_SINGLE("3D Lower Cut-off Switch", AC97_3D_CONTROL, 4, 1, 1), 5723998b70fSLiam Girdwood 5733998b70fSLiam Girdwood AC97_ENUM("Bass Control", wm9711_enum[5]), 5743998b70fSLiam Girdwood AC97_SINGLE("Bass Cut-off Switch", AC97_MASTER_TONE, 12, 1, 1), 5753998b70fSLiam Girdwood AC97_SINGLE("Tone Cut-off Switch", AC97_MASTER_TONE, 4, 1, 1), 5763998b70fSLiam Girdwood AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_MASTER_TONE, 6, 1, 0), 5773998b70fSLiam Girdwood 5783998b70fSLiam Girdwood AC97_SINGLE("ADC Switch", AC97_REC_GAIN, 15, 1, 1), 5793998b70fSLiam Girdwood AC97_ENUM("Capture Volume Steps", wm9711_enum[6]), 5802aedbda6SLuke Zhang AC97_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 63, 1), 5813998b70fSLiam Girdwood AC97_SINGLE("Capture ZC Switch", AC97_REC_GAIN, 7, 1, 0), 5823998b70fSLiam Girdwood 5833998b70fSLiam Girdwood AC97_SINGLE("Mic 1 to Phone Switch", AC97_MIC, 14, 1, 1), 5843998b70fSLiam Girdwood AC97_SINGLE("Mic 2 to Phone Switch", AC97_MIC, 13, 1, 1), 5853998b70fSLiam Girdwood AC97_ENUM("Mic Select Source", wm9711_enum[7]), 5862aedbda6SLuke Zhang AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1), 5872aedbda6SLuke Zhang AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1), 588d7f6f115SJames Courtier-Dutton AC97_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 7, 1, 0), 5893998b70fSLiam Girdwood 5903998b70fSLiam Girdwood AC97_SINGLE("Master ZC Switch", AC97_MASTER, 7, 1, 0), 5913998b70fSLiam Girdwood AC97_SINGLE("Headphone ZC Switch", AC97_HEADPHONE, 7, 1, 0), 5923998b70fSLiam Girdwood AC97_SINGLE("Mono ZC Switch", AC97_MASTER_MONO, 7, 1, 0), 5933998b70fSLiam Girdwood }; 5943998b70fSLiam Girdwood 595ee42381eSTakashi Iwai static int patch_wolfson_wm9711_specific(struct snd_ac97 * ac97) 5963998b70fSLiam Girdwood { 5973998b70fSLiam Girdwood int err, i; 5983998b70fSLiam Girdwood 5993998b70fSLiam Girdwood for (i = 0; i < ARRAY_SIZE(wm9711_snd_ac97_controls); i++) { 6003998b70fSLiam Girdwood if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9711_snd_ac97_controls[i], ac97))) < 0) 6013998b70fSLiam Girdwood return err; 6023998b70fSLiam Girdwood } 6033998b70fSLiam Girdwood snd_ac97_write_cache(ac97, AC97_CODEC_CLASS_REV, 0x0808); 6043998b70fSLiam Girdwood snd_ac97_write_cache(ac97, AC97_PCI_SVID, 0x0808); 6053998b70fSLiam Girdwood snd_ac97_write_cache(ac97, AC97_VIDEO, 0x0808); 6063998b70fSLiam Girdwood snd_ac97_write_cache(ac97, AC97_AUX, 0x0808); 6073998b70fSLiam Girdwood snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808); 6083998b70fSLiam Girdwood snd_ac97_write_cache(ac97, AC97_CD, 0x0000); 6093998b70fSLiam Girdwood return 0; 6103998b70fSLiam Girdwood } 6113998b70fSLiam Girdwood 6123998b70fSLiam Girdwood static struct snd_ac97_build_ops patch_wolfson_wm9711_ops = { 6133998b70fSLiam Girdwood .build_specific = patch_wolfson_wm9711_specific, 6143998b70fSLiam Girdwood }; 6153998b70fSLiam Girdwood 616ac519028STakashi Iwai static int patch_wolfson11(struct snd_ac97 * ac97) 6171da177e4SLinus Torvalds { 6183998b70fSLiam Girdwood /* WM9711, WM9712 */ 6193998b70fSLiam Girdwood ac97->build_ops = &patch_wolfson_wm9711_ops; 6203998b70fSLiam Girdwood 6213998b70fSLiam Girdwood ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_MIC | 6223998b70fSLiam Girdwood AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD; 6233998b70fSLiam Girdwood 6241da177e4SLinus Torvalds return 0; 6251da177e4SLinus Torvalds } 6261da177e4SLinus Torvalds 6271da177e4SLinus Torvalds static const char* wm9713_mic_mixer[] = {"Stereo", "Mic 1", "Mic 2", "Mute"}; 6281da177e4SLinus Torvalds static const char* wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"}; 6293998b70fSLiam Girdwood static const char* wm9713_rec_src[] = 6303998b70fSLiam Girdwood {"Mic 1", "Mic 2", "Line", "Mono In", "Headphone Mix", "Master Mix", 6313998b70fSLiam Girdwood "Mono Mix", "Zh"}; 6323998b70fSLiam Girdwood static const char* wm9713_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"}; 6333998b70fSLiam Girdwood static const char* wm9713_alc_select[] = {"None", "Left", "Right", "Stereo"}; 6343998b70fSLiam Girdwood static const char* wm9713_mono_pga[] = {"Vmid", "Zh", "Mono Mix", "Inv 1"}; 6353998b70fSLiam Girdwood static const char* wm9713_spk_pga[] = 6363998b70fSLiam Girdwood {"Vmid", "Zh", "Headphone Mix", "Master Mix", "Inv", "NC", "NC", "NC"}; 6373998b70fSLiam Girdwood static const char* wm9713_hp_pga[] = {"Vmid", "Zh", "Headphone Mix", "NC"}; 6383998b70fSLiam Girdwood static const char* wm9713_out3_pga[] = {"Vmid", "Zh", "Inv 1", "NC"}; 6393998b70fSLiam Girdwood static const char* wm9713_out4_pga[] = {"Vmid", "Zh", "Inv 2", "NC"}; 6403998b70fSLiam Girdwood static const char* wm9713_dac_inv[] = 6413998b70fSLiam Girdwood {"Off", "Mono Mix", "Master Mix", "Headphone Mix L", "Headphone Mix R", 6423998b70fSLiam Girdwood "Headphone Mix Mono", "NC", "Vmid"}; 6433998b70fSLiam Girdwood static const char* wm9713_base[] = {"Linear Control", "Adaptive Boost"}; 6443998b70fSLiam Girdwood static const char* wm9713_ng_type[] = {"Constant Gain", "Mute"}; 6451da177e4SLinus Torvalds 6461da177e4SLinus Torvalds static const struct ac97_enum wm9713_enum[] = { 6471da177e4SLinus Torvalds AC97_ENUM_SINGLE(AC97_LINE, 3, 4, wm9713_mic_mixer), 6481da177e4SLinus Torvalds AC97_ENUM_SINGLE(AC97_VIDEO, 14, 4, wm9713_rec_mux), 6491da177e4SLinus Torvalds AC97_ENUM_SINGLE(AC97_VIDEO, 9, 4, wm9713_rec_mux), 6503998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_VIDEO, 3, 0, 8, wm9713_rec_src), 6513998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_CD, 14, 6, 2, wm9713_rec_gain), 6523998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9713_alc_select), 6533998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_REC_GAIN, 14, 4, wm9713_mono_pga), 6543998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_REC_GAIN, 11, 8, 8, wm9713_spk_pga), 6553998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_REC_GAIN, 6, 4, 4, wm9713_hp_pga), 6563998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_REC_GAIN, 2, 4, wm9713_out3_pga), 6573998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_REC_GAIN, 0, 4, wm9713_out4_pga), 6583998b70fSLiam Girdwood AC97_ENUM_DOUBLE(AC97_REC_GAIN_MIC, 13, 10, 8, wm9713_dac_inv), 6593998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, wm9713_base), 6603998b70fSLiam Girdwood AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9713_ng_type), 6611da177e4SLinus Torvalds }; 6621da177e4SLinus Torvalds 663ee42381eSTakashi Iwai static const struct snd_kcontrol_new wm13_snd_ac97_controls[] = { 6641da177e4SLinus Torvalds AC97_DOUBLE("Line In Volume", AC97_PC_BEEP, 8, 0, 31, 1), 6653998b70fSLiam Girdwood AC97_SINGLE("Line In to Headphone Switch", AC97_PC_BEEP, 15, 1, 1), 6663998b70fSLiam Girdwood AC97_SINGLE("Line In to Master Switch", AC97_PC_BEEP, 14, 1, 1), 6673998b70fSLiam Girdwood AC97_SINGLE("Line In to Mono Switch", AC97_PC_BEEP, 13, 1, 1), 6683998b70fSLiam Girdwood 6693998b70fSLiam Girdwood AC97_DOUBLE("PCM Playback Volume", AC97_PHONE, 8, 0, 31, 1), 6703998b70fSLiam Girdwood AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PHONE, 15, 1, 1), 6713998b70fSLiam Girdwood AC97_SINGLE("PCM Playback to Master Switch", AC97_PHONE, 14, 1, 1), 6723998b70fSLiam Girdwood AC97_SINGLE("PCM Playback to Mono Switch", AC97_PHONE, 13, 1, 1), 6733998b70fSLiam Girdwood 6743998b70fSLiam Girdwood AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1), 6753998b70fSLiam Girdwood AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1), 6763998b70fSLiam Girdwood AC97_SINGLE("Mic 1 to Mono Switch", AC97_LINE, 7, 1, 1), 6773998b70fSLiam Girdwood AC97_SINGLE("Mic 2 to Mono Switch", AC97_LINE, 6, 1, 1), 678d7f6f115SJames Courtier-Dutton AC97_SINGLE("Mic Boost (+20dB) Switch", AC97_LINE, 5, 1, 0), 6793998b70fSLiam Girdwood AC97_ENUM("Mic to Headphone Mux", wm9713_enum[0]), 6803998b70fSLiam Girdwood AC97_SINGLE("Mic Headphone Mixer Volume", AC97_LINE, 0, 7, 1), 6813998b70fSLiam Girdwood 6823998b70fSLiam Girdwood AC97_SINGLE("Capture Switch", AC97_CD, 15, 1, 1), 6833998b70fSLiam Girdwood AC97_ENUM("Capture Volume Steps", wm9713_enum[4]), 6843998b70fSLiam Girdwood AC97_DOUBLE("Capture Volume", AC97_CD, 8, 0, 15, 0), 6853998b70fSLiam Girdwood AC97_SINGLE("Capture ZC Switch", AC97_CD, 7, 1, 0), 6863998b70fSLiam Girdwood 6873998b70fSLiam Girdwood AC97_ENUM("Capture to Headphone Mux", wm9713_enum[1]), 6883998b70fSLiam Girdwood AC97_SINGLE("Capture to Headphone Volume", AC97_VIDEO, 11, 7, 1), 6893998b70fSLiam Girdwood AC97_ENUM("Capture to Mono Mux", wm9713_enum[2]), 6903998b70fSLiam Girdwood AC97_SINGLE("Capture to Mono Boost (+20dB) Switch", AC97_VIDEO, 8, 1, 0), 6913998b70fSLiam Girdwood AC97_SINGLE("Capture ADC Boost (+20dB) Switch", AC97_VIDEO, 6, 1, 0), 6923998b70fSLiam Girdwood AC97_ENUM("Capture Select", wm9713_enum[3]), 6933998b70fSLiam Girdwood 6943998b70fSLiam Girdwood AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0), 6953998b70fSLiam Girdwood AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0), 6963998b70fSLiam Girdwood AC97_SINGLE("ALC Decay Time ", AC97_CODEC_CLASS_REV, 4, 15, 0), 6973998b70fSLiam Girdwood AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0), 6983998b70fSLiam Girdwood AC97_ENUM("ALC Function", wm9713_enum[5]), 6993998b70fSLiam Girdwood AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 0), 7003998b70fSLiam Girdwood AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 0), 7013998b70fSLiam Girdwood AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0), 7023998b70fSLiam Girdwood AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0), 7033998b70fSLiam Girdwood AC97_ENUM("ALC NG Type", wm9713_enum[13]), 7043998b70fSLiam Girdwood AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 0), 7053998b70fSLiam Girdwood 7063998b70fSLiam Girdwood AC97_DOUBLE("Master ZC Switch", AC97_MASTER, 14, 6, 1, 0), 7073998b70fSLiam Girdwood AC97_DOUBLE("Headphone ZC Switch", AC97_HEADPHONE, 14, 6, 1, 0), 7083998b70fSLiam Girdwood AC97_DOUBLE("Out3/4 ZC Switch", AC97_MASTER_MONO, 14, 6, 1, 0), 7093998b70fSLiam Girdwood AC97_SINGLE("Master Right Switch", AC97_MASTER, 7, 1, 1), 7103998b70fSLiam Girdwood AC97_SINGLE("Headphone Right Switch", AC97_HEADPHONE, 7, 1, 1), 7113998b70fSLiam Girdwood AC97_SINGLE("Out3/4 Right Switch", AC97_MASTER_MONO, 7, 1, 1), 7123998b70fSLiam Girdwood 7133998b70fSLiam Girdwood AC97_SINGLE("Mono In to Headphone Switch", AC97_MASTER_TONE, 15, 1, 1), 7143998b70fSLiam Girdwood AC97_SINGLE("Mono In to Master Switch", AC97_MASTER_TONE, 14, 1, 1), 7153998b70fSLiam Girdwood AC97_SINGLE("Mono In Volume", AC97_MASTER_TONE, 8, 31, 1), 7163998b70fSLiam Girdwood AC97_SINGLE("Mono Switch", AC97_MASTER_TONE, 7, 1, 1), 7173998b70fSLiam Girdwood AC97_SINGLE("Mono ZC Switch", AC97_MASTER_TONE, 6, 1, 0), 7183998b70fSLiam Girdwood AC97_SINGLE("Mono Volume", AC97_MASTER_TONE, 0, 31, 1), 7193998b70fSLiam Girdwood 7203998b70fSLiam Girdwood AC97_SINGLE("PC Beep to Headphone Switch", AC97_AUX, 15, 1, 1), 7213998b70fSLiam Girdwood AC97_SINGLE("PC Beep to Headphone Volume", AC97_AUX, 12, 7, 1), 7223998b70fSLiam Girdwood AC97_SINGLE("PC Beep to Master Switch", AC97_AUX, 11, 1, 1), 7233998b70fSLiam Girdwood AC97_SINGLE("PC Beep to Master Volume", AC97_AUX, 8, 7, 1), 7243998b70fSLiam Girdwood AC97_SINGLE("PC Beep to Mono Switch", AC97_AUX, 7, 1, 1), 7253998b70fSLiam Girdwood AC97_SINGLE("PC Beep to Mono Volume", AC97_AUX, 4, 7, 1), 7263998b70fSLiam Girdwood 7273998b70fSLiam Girdwood AC97_SINGLE("Voice to Headphone Switch", AC97_PCM, 15, 1, 1), 7283998b70fSLiam Girdwood AC97_SINGLE("Voice to Headphone Volume", AC97_PCM, 12, 7, 1), 7293998b70fSLiam Girdwood AC97_SINGLE("Voice to Master Switch", AC97_PCM, 11, 1, 1), 7303998b70fSLiam Girdwood AC97_SINGLE("Voice to Master Volume", AC97_PCM, 8, 7, 1), 7313998b70fSLiam Girdwood AC97_SINGLE("Voice to Mono Switch", AC97_PCM, 7, 1, 1), 7323998b70fSLiam Girdwood AC97_SINGLE("Voice to Mono Volume", AC97_PCM, 4, 7, 1), 7333998b70fSLiam Girdwood 7343998b70fSLiam Girdwood AC97_SINGLE("Aux to Headphone Switch", AC97_REC_SEL, 15, 1, 1), 7353998b70fSLiam Girdwood AC97_SINGLE("Aux to Headphone Volume", AC97_REC_SEL, 12, 7, 1), 7363998b70fSLiam Girdwood AC97_SINGLE("Aux to Master Switch", AC97_REC_SEL, 11, 1, 1), 7373998b70fSLiam Girdwood AC97_SINGLE("Aux to Master Volume", AC97_REC_SEL, 8, 7, 1), 7383998b70fSLiam Girdwood AC97_SINGLE("Aux to Mono Switch", AC97_REC_SEL, 7, 1, 1), 7393998b70fSLiam Girdwood AC97_SINGLE("Aux to Mono Volume", AC97_REC_SEL, 4, 7, 1), 7403998b70fSLiam Girdwood 7413998b70fSLiam Girdwood AC97_ENUM("Mono Input Mux", wm9713_enum[6]), 7423998b70fSLiam Girdwood AC97_ENUM("Master Input Mux", wm9713_enum[7]), 7433998b70fSLiam Girdwood AC97_ENUM("Headphone Input Mux", wm9713_enum[8]), 7443998b70fSLiam Girdwood AC97_ENUM("Out 3 Input Mux", wm9713_enum[9]), 7453998b70fSLiam Girdwood AC97_ENUM("Out 4 Input Mux", wm9713_enum[10]), 7463998b70fSLiam Girdwood 7473998b70fSLiam Girdwood AC97_ENUM("Bass Control", wm9713_enum[12]), 7483998b70fSLiam Girdwood AC97_SINGLE("Bass Cut-off Switch", AC97_GENERAL_PURPOSE, 12, 1, 1), 7493998b70fSLiam Girdwood AC97_SINGLE("Tone Cut-off Switch", AC97_GENERAL_PURPOSE, 4, 1, 1), 7503998b70fSLiam Girdwood AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_GENERAL_PURPOSE, 6, 1, 0), 7513998b70fSLiam Girdwood AC97_SINGLE("Bass Volume", AC97_GENERAL_PURPOSE, 8, 15, 1), 7523998b70fSLiam Girdwood AC97_SINGLE("Tone Volume", AC97_GENERAL_PURPOSE, 0, 15, 1), 7531da177e4SLinus Torvalds }; 7541da177e4SLinus Torvalds 755ee42381eSTakashi Iwai static const struct snd_kcontrol_new wm13_snd_ac97_controls_3d[] = { 7563998b70fSLiam Girdwood AC97_ENUM("Inv Input Mux", wm9713_enum[11]), 7573998b70fSLiam Girdwood AC97_SINGLE("3D Upper Cut-off Switch", AC97_REC_GAIN_MIC, 5, 1, 0), 7583998b70fSLiam Girdwood AC97_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC, 4, 1, 0), 7593998b70fSLiam Girdwood AC97_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1), 7601da177e4SLinus Torvalds }; 7611da177e4SLinus Torvalds 762ee42381eSTakashi Iwai static int patch_wolfson_wm9713_3d (struct snd_ac97 * ac97) 7633998b70fSLiam Girdwood { 7643998b70fSLiam Girdwood int err, i; 7651da177e4SLinus Torvalds 7663998b70fSLiam Girdwood for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_3d); i++) { 7673998b70fSLiam Girdwood if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_3d[i], ac97))) < 0) 7683998b70fSLiam Girdwood return err; 7693998b70fSLiam Girdwood } 7703998b70fSLiam Girdwood return 0; 7713998b70fSLiam Girdwood } 7721da177e4SLinus Torvalds 773ee42381eSTakashi Iwai static int patch_wolfson_wm9713_specific(struct snd_ac97 * ac97) 7741da177e4SLinus Torvalds { 7751da177e4SLinus Torvalds int err, i; 7761da177e4SLinus Torvalds 7773998b70fSLiam Girdwood for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls); i++) { 7783998b70fSLiam Girdwood if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls[i], ac97))) < 0) 7791da177e4SLinus Torvalds return err; 7801da177e4SLinus Torvalds } 7811da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808); 7821da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_PHONE, 0x0808); 7831da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_MIC, 0x0808); 7841da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_LINE, 0x00da); 7851da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_CD, 0x0808); 7861da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_VIDEO, 0xd612); 7871da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x1ba0); 7881da177e4SLinus Torvalds return 0; 7891da177e4SLinus Torvalds } 7901da177e4SLinus Torvalds 7911da177e4SLinus Torvalds #ifdef CONFIG_PM 792ee42381eSTakashi Iwai static void patch_wolfson_wm9713_suspend (struct snd_ac97 * ac97) 7931da177e4SLinus Torvalds { 7941da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xfeff); 7951da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0xffff); 7961da177e4SLinus Torvalds } 7971da177e4SLinus Torvalds 798ee42381eSTakashi Iwai static void patch_wolfson_wm9713_resume (struct snd_ac97 * ac97) 7991da177e4SLinus Torvalds { 8001da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00); 8011da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810); 8021da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0); 8031da177e4SLinus Torvalds } 8041da177e4SLinus Torvalds #endif 8051da177e4SLinus Torvalds 8061da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_wolfson_wm9713_ops = { 8071da177e4SLinus Torvalds .build_specific = patch_wolfson_wm9713_specific, 8083998b70fSLiam Girdwood .build_3d = patch_wolfson_wm9713_3d, 8091da177e4SLinus Torvalds #ifdef CONFIG_PM 8101da177e4SLinus Torvalds .suspend = patch_wolfson_wm9713_suspend, 8111da177e4SLinus Torvalds .resume = patch_wolfson_wm9713_resume 8121da177e4SLinus Torvalds #endif 8131da177e4SLinus Torvalds }; 8141da177e4SLinus Torvalds 815ac519028STakashi Iwai static int patch_wolfson13(struct snd_ac97 * ac97) 8161da177e4SLinus Torvalds { 8173998b70fSLiam Girdwood /* WM9713, WM9714 */ 8181da177e4SLinus Torvalds ac97->build_ops = &patch_wolfson_wm9713_ops; 8191da177e4SLinus Torvalds 8201da177e4SLinus Torvalds ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_PHONE | 8213998b70fSLiam Girdwood AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD | AC97_HAS_NO_TONE | 8223998b70fSLiam Girdwood AC97_HAS_NO_STD_PCM; 823064d2112SLiam Girdwood ac97->scaps &= ~AC97_SCAP_MODEM; 8241da177e4SLinus Torvalds 8251da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00); 8261da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810); 8271da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0); 8281da177e4SLinus Torvalds 8291da177e4SLinus Torvalds return 0; 8301da177e4SLinus Torvalds } 8311da177e4SLinus Torvalds 8321da177e4SLinus Torvalds /* 8331da177e4SLinus Torvalds * Tritech codec 8341da177e4SLinus Torvalds */ 835ac519028STakashi Iwai static int patch_tritech_tr28028(struct snd_ac97 * ac97) 8361da177e4SLinus Torvalds { 8371da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x26, 0x0300); 8381da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x26, 0x0000); 8391da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SURROUND_MASTER, 0x0000); 8401da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SPDIF, 0x0000); 8411da177e4SLinus Torvalds return 0; 8421da177e4SLinus Torvalds } 8431da177e4SLinus Torvalds 8441da177e4SLinus Torvalds /* 8451da177e4SLinus Torvalds * Sigmatel STAC97xx codecs 8461da177e4SLinus Torvalds */ 847ee42381eSTakashi Iwai static int patch_sigmatel_stac9700_3d(struct snd_ac97 * ac97) 8481da177e4SLinus Torvalds { 849ee42381eSTakashi Iwai struct snd_kcontrol *kctl; 8501da177e4SLinus Torvalds int err; 8511da177e4SLinus Torvalds 8521da177e4SLinus Torvalds if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0) 8531da177e4SLinus Torvalds return err; 8541da177e4SLinus Torvalds strcpy(kctl->id.name, "3D Control Sigmatel - Depth"); 8551da177e4SLinus Torvalds kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0); 8561da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000); 8571da177e4SLinus Torvalds return 0; 8581da177e4SLinus Torvalds } 8591da177e4SLinus Torvalds 860ee42381eSTakashi Iwai static int patch_sigmatel_stac9708_3d(struct snd_ac97 * ac97) 8611da177e4SLinus Torvalds { 862ee42381eSTakashi Iwai struct snd_kcontrol *kctl; 8631da177e4SLinus Torvalds int err; 8641da177e4SLinus Torvalds 8651da177e4SLinus Torvalds if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0) 8661da177e4SLinus Torvalds return err; 8671da177e4SLinus Torvalds strcpy(kctl->id.name, "3D Control Sigmatel - Depth"); 8681da177e4SLinus Torvalds kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 0, 3, 0); 8691da177e4SLinus Torvalds if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0) 8701da177e4SLinus Torvalds return err; 8711da177e4SLinus Torvalds strcpy(kctl->id.name, "3D Control Sigmatel - Rear Depth"); 8721da177e4SLinus Torvalds kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0); 8731da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000); 8741da177e4SLinus Torvalds return 0; 8751da177e4SLinus Torvalds } 8761da177e4SLinus Torvalds 877ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_sigmatel_4speaker = 8781da177e4SLinus Torvalds AC97_SINGLE("Sigmatel 4-Speaker Stereo Playback Switch", AC97_SIGMATEL_DAC2INVERT, 2, 1, 0); 8791da177e4SLinus Torvalds 880ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_sigmatel_phaseinvert = 8811da177e4SLinus Torvalds AC97_SINGLE("Sigmatel Surround Phase Inversion Playback Switch", AC97_SIGMATEL_DAC2INVERT, 3, 1, 0); 8821da177e4SLinus Torvalds 883ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_sigmatel_controls[] = { 8841da177e4SLinus Torvalds AC97_SINGLE("Sigmatel DAC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 1, 1, 0), 8851da177e4SLinus Torvalds AC97_SINGLE("Sigmatel ADC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 0, 1, 0) 8861da177e4SLinus Torvalds }; 8871da177e4SLinus Torvalds 888ee42381eSTakashi Iwai static int patch_sigmatel_stac97xx_specific(struct snd_ac97 * ac97) 8891da177e4SLinus Torvalds { 8901da177e4SLinus Torvalds int err; 8911da177e4SLinus Torvalds 8921da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_ANALOG, snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) & ~0x0003); 8931da177e4SLinus Torvalds if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 1)) 8941da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[0], 1)) < 0) 8951da177e4SLinus Torvalds return err; 8961da177e4SLinus Torvalds if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 0)) 8971da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[1], 1)) < 0) 8981da177e4SLinus Torvalds return err; 8991da177e4SLinus Torvalds if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 2)) 9001da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_4speaker, 1)) < 0) 9011da177e4SLinus Torvalds return err; 9021da177e4SLinus Torvalds if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 3)) 9031da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_phaseinvert, 1)) < 0) 9041da177e4SLinus Torvalds return err; 9051da177e4SLinus Torvalds return 0; 9061da177e4SLinus Torvalds } 9071da177e4SLinus Torvalds 9081da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_sigmatel_stac9700_ops = { 9091da177e4SLinus Torvalds .build_3d = patch_sigmatel_stac9700_3d, 9101da177e4SLinus Torvalds .build_specific = patch_sigmatel_stac97xx_specific 9111da177e4SLinus Torvalds }; 9121da177e4SLinus Torvalds 913ac519028STakashi Iwai static int patch_sigmatel_stac9700(struct snd_ac97 * ac97) 9141da177e4SLinus Torvalds { 9151da177e4SLinus Torvalds ac97->build_ops = &patch_sigmatel_stac9700_ops; 9161da177e4SLinus Torvalds return 0; 9171da177e4SLinus Torvalds } 9181da177e4SLinus Torvalds 919ee42381eSTakashi Iwai static int snd_ac97_stac9708_put_bias(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 9201da177e4SLinus Torvalds { 921ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 9221da177e4SLinus Torvalds int err; 9231da177e4SLinus Torvalds 92462932df8SIngo Molnar mutex_lock(&ac97->page_mutex); 9251da177e4SLinus Torvalds snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0xabba); 9261da177e4SLinus Torvalds err = snd_ac97_update_bits(ac97, AC97_SIGMATEL_BIAS2, 0x0010, 9271da177e4SLinus Torvalds (ucontrol->value.integer.value[0] & 1) << 4); 9281da177e4SLinus Torvalds snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0); 92962932df8SIngo Molnar mutex_unlock(&ac97->page_mutex); 9301da177e4SLinus Torvalds return err; 9311da177e4SLinus Torvalds } 9321da177e4SLinus Torvalds 933ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_stac9708_bias_control = { 9341da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 9351da177e4SLinus Torvalds .name = "Sigmatel Output Bias Switch", 9361da177e4SLinus Torvalds .info = snd_ac97_info_volsw, 9371da177e4SLinus Torvalds .get = snd_ac97_get_volsw, 9381da177e4SLinus Torvalds .put = snd_ac97_stac9708_put_bias, 9391da177e4SLinus Torvalds .private_value = AC97_SINGLE_VALUE(AC97_SIGMATEL_BIAS2, 4, 1, 0), 9401da177e4SLinus Torvalds }; 9411da177e4SLinus Torvalds 942ee42381eSTakashi Iwai static int patch_sigmatel_stac9708_specific(struct snd_ac97 *ac97) 9431da177e4SLinus Torvalds { 9441da177e4SLinus Torvalds int err; 9451da177e4SLinus Torvalds 946e4c3bf0fSJames C Georgas /* the register bit is writable, but the function is not implemented: */ 947e4c3bf0fSJames C Georgas snd_ac97_remove_ctl(ac97, "PCM Out Path & Mute", NULL); 948e4c3bf0fSJames C Georgas 9491da177e4SLinus Torvalds snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Sigmatel Surround Playback"); 9501da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_stac9708_bias_control, 1)) < 0) 9511da177e4SLinus Torvalds return err; 9521da177e4SLinus Torvalds return patch_sigmatel_stac97xx_specific(ac97); 9531da177e4SLinus Torvalds } 9541da177e4SLinus Torvalds 9551da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_sigmatel_stac9708_ops = { 9561da177e4SLinus Torvalds .build_3d = patch_sigmatel_stac9708_3d, 9571da177e4SLinus Torvalds .build_specific = patch_sigmatel_stac9708_specific 9581da177e4SLinus Torvalds }; 9591da177e4SLinus Torvalds 960ac519028STakashi Iwai static int patch_sigmatel_stac9708(struct snd_ac97 * ac97) 9611da177e4SLinus Torvalds { 9621da177e4SLinus Torvalds unsigned int codec72, codec6c; 9631da177e4SLinus Torvalds 9641da177e4SLinus Torvalds ac97->build_ops = &patch_sigmatel_stac9708_ops; 9651da177e4SLinus Torvalds ac97->caps |= 0x10; /* HP (sigmatel surround) support */ 9661da177e4SLinus Torvalds 9671da177e4SLinus Torvalds codec72 = snd_ac97_read(ac97, AC97_SIGMATEL_BIAS2) & 0x8000; 9681da177e4SLinus Torvalds codec6c = snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG); 9691da177e4SLinus Torvalds 9701da177e4SLinus Torvalds if ((codec72==0) && (codec6c==0)) { 9711da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); 9721da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1000); 9731da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba); 9741da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0007); 9751da177e4SLinus Torvalds } else if ((codec72==0x8000) && (codec6c==0)) { 9761da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); 9771da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1001); 9781da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_DAC2INVERT, 0x0008); 9791da177e4SLinus Torvalds } else if ((codec72==0x8000) && (codec6c==0x0080)) { 9801da177e4SLinus Torvalds /* nothing */ 9811da177e4SLinus Torvalds } 9821da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000); 9831da177e4SLinus Torvalds return 0; 9841da177e4SLinus Torvalds } 9851da177e4SLinus Torvalds 986ac519028STakashi Iwai static int patch_sigmatel_stac9721(struct snd_ac97 * ac97) 9871da177e4SLinus Torvalds { 9881da177e4SLinus Torvalds ac97->build_ops = &patch_sigmatel_stac9700_ops; 9891da177e4SLinus Torvalds if (snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) == 0) { 9901da177e4SLinus Torvalds // patch for SigmaTel 9911da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); 9921da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x4000); 9931da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba); 9941da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002); 9951da177e4SLinus Torvalds } 9961da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000); 9971da177e4SLinus Torvalds return 0; 9981da177e4SLinus Torvalds } 9991da177e4SLinus Torvalds 1000ac519028STakashi Iwai static int patch_sigmatel_stac9744(struct snd_ac97 * ac97) 10011da177e4SLinus Torvalds { 10021da177e4SLinus Torvalds // patch for SigmaTel 10031da177e4SLinus Torvalds ac97->build_ops = &patch_sigmatel_stac9700_ops; 10041da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); 10051da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */ 10061da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba); 10071da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002); 10081da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000); 10091da177e4SLinus Torvalds return 0; 10101da177e4SLinus Torvalds } 10111da177e4SLinus Torvalds 1012ac519028STakashi Iwai static int patch_sigmatel_stac9756(struct snd_ac97 * ac97) 10131da177e4SLinus Torvalds { 10141da177e4SLinus Torvalds // patch for SigmaTel 10151da177e4SLinus Torvalds ac97->build_ops = &patch_sigmatel_stac9700_ops; 10161da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); 10171da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */ 10181da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba); 10191da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002); 10201da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000); 10211da177e4SLinus Torvalds return 0; 10221da177e4SLinus Torvalds } 10231da177e4SLinus Torvalds 1024ee42381eSTakashi Iwai static int snd_ac97_stac9758_output_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 10251da177e4SLinus Torvalds { 10261da177e4SLinus Torvalds static char *texts[5] = { "Input/Disabled", "Front Output", 10271da177e4SLinus Torvalds "Rear Output", "Center/LFE Output", "Mixer Output" }; 10281da177e4SLinus Torvalds 10291da177e4SLinus Torvalds uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 10301da177e4SLinus Torvalds uinfo->count = 1; 10311da177e4SLinus Torvalds uinfo->value.enumerated.items = 5; 10321da177e4SLinus Torvalds if (uinfo->value.enumerated.item > 4) 10331da177e4SLinus Torvalds uinfo->value.enumerated.item = 4; 10341da177e4SLinus Torvalds strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 10351da177e4SLinus Torvalds return 0; 10361da177e4SLinus Torvalds } 10371da177e4SLinus Torvalds 1038ee42381eSTakashi Iwai static int snd_ac97_stac9758_output_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 10391da177e4SLinus Torvalds { 1040ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 10411da177e4SLinus Torvalds int shift = kcontrol->private_value; 10421da177e4SLinus Torvalds unsigned short val; 10431da177e4SLinus Torvalds 10441da177e4SLinus Torvalds val = ac97->regs[AC97_SIGMATEL_OUTSEL] >> shift; 10451da177e4SLinus Torvalds if (!(val & 4)) 10461da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = 0; 10471da177e4SLinus Torvalds else 10481da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = 1 + (val & 3); 10491da177e4SLinus Torvalds return 0; 10501da177e4SLinus Torvalds } 10511da177e4SLinus Torvalds 1052ee42381eSTakashi Iwai static int snd_ac97_stac9758_output_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 10531da177e4SLinus Torvalds { 1054ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 10551da177e4SLinus Torvalds int shift = kcontrol->private_value; 10561da177e4SLinus Torvalds unsigned short val; 10571da177e4SLinus Torvalds 10581da177e4SLinus Torvalds if (ucontrol->value.enumerated.item[0] > 4) 10591da177e4SLinus Torvalds return -EINVAL; 10601da177e4SLinus Torvalds if (ucontrol->value.enumerated.item[0] == 0) 10611da177e4SLinus Torvalds val = 0; 10621da177e4SLinus Torvalds else 10631da177e4SLinus Torvalds val = 4 | (ucontrol->value.enumerated.item[0] - 1); 10641da177e4SLinus Torvalds return ac97_update_bits_page(ac97, AC97_SIGMATEL_OUTSEL, 10651da177e4SLinus Torvalds 7 << shift, val << shift, 0); 10661da177e4SLinus Torvalds } 10671da177e4SLinus Torvalds 1068ee42381eSTakashi Iwai static int snd_ac97_stac9758_input_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 10691da177e4SLinus Torvalds { 10701da177e4SLinus Torvalds static char *texts[7] = { "Mic2 Jack", "Mic1 Jack", "Line In Jack", 10711da177e4SLinus Torvalds "Front Jack", "Rear Jack", "Center/LFE Jack", "Mute" }; 10721da177e4SLinus Torvalds 10731da177e4SLinus Torvalds uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 10741da177e4SLinus Torvalds uinfo->count = 1; 10751da177e4SLinus Torvalds uinfo->value.enumerated.items = 7; 10761da177e4SLinus Torvalds if (uinfo->value.enumerated.item > 6) 10771da177e4SLinus Torvalds uinfo->value.enumerated.item = 6; 10781da177e4SLinus Torvalds strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 10791da177e4SLinus Torvalds return 0; 10801da177e4SLinus Torvalds } 10811da177e4SLinus Torvalds 1082ee42381eSTakashi Iwai static int snd_ac97_stac9758_input_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 10831da177e4SLinus Torvalds { 1084ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 10851da177e4SLinus Torvalds int shift = kcontrol->private_value; 10861da177e4SLinus Torvalds unsigned short val; 10871da177e4SLinus Torvalds 10881da177e4SLinus Torvalds val = ac97->regs[AC97_SIGMATEL_INSEL]; 10891da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = (val >> shift) & 7; 10901da177e4SLinus Torvalds return 0; 10911da177e4SLinus Torvalds } 10921da177e4SLinus Torvalds 1093ee42381eSTakashi Iwai static int snd_ac97_stac9758_input_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 10941da177e4SLinus Torvalds { 1095ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 10961da177e4SLinus Torvalds int shift = kcontrol->private_value; 10971da177e4SLinus Torvalds 10981da177e4SLinus Torvalds return ac97_update_bits_page(ac97, AC97_SIGMATEL_INSEL, 7 << shift, 10991da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] << shift, 0); 11001da177e4SLinus Torvalds } 11011da177e4SLinus Torvalds 1102ee42381eSTakashi Iwai static int snd_ac97_stac9758_phonesel_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 11031da177e4SLinus Torvalds { 11041da177e4SLinus Torvalds static char *texts[3] = { "None", "Front Jack", "Rear Jack" }; 11051da177e4SLinus Torvalds 11061da177e4SLinus Torvalds uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 11071da177e4SLinus Torvalds uinfo->count = 1; 11081da177e4SLinus Torvalds uinfo->value.enumerated.items = 3; 11091da177e4SLinus Torvalds if (uinfo->value.enumerated.item > 2) 11101da177e4SLinus Torvalds uinfo->value.enumerated.item = 2; 11111da177e4SLinus Torvalds strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 11121da177e4SLinus Torvalds return 0; 11131da177e4SLinus Torvalds } 11141da177e4SLinus Torvalds 1115ee42381eSTakashi Iwai static int snd_ac97_stac9758_phonesel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 11161da177e4SLinus Torvalds { 1117ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 11181da177e4SLinus Torvalds 11191da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = ac97->regs[AC97_SIGMATEL_IOMISC] & 3; 11201da177e4SLinus Torvalds return 0; 11211da177e4SLinus Torvalds } 11221da177e4SLinus Torvalds 1123ee42381eSTakashi Iwai static int snd_ac97_stac9758_phonesel_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 11271da177e4SLinus Torvalds return ac97_update_bits_page(ac97, AC97_SIGMATEL_IOMISC, 3, 11281da177e4SLinus Torvalds ucontrol->value.enumerated.item[0], 0); 11291da177e4SLinus Torvalds } 11301da177e4SLinus Torvalds 11311da177e4SLinus Torvalds #define STAC9758_OUTPUT_JACK(xname, shift) \ 11321da177e4SLinus Torvalds { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 11331da177e4SLinus Torvalds .info = snd_ac97_stac9758_output_jack_info, \ 11341da177e4SLinus Torvalds .get = snd_ac97_stac9758_output_jack_get, \ 11351da177e4SLinus Torvalds .put = snd_ac97_stac9758_output_jack_put, \ 11361da177e4SLinus Torvalds .private_value = shift } 11371da177e4SLinus Torvalds #define STAC9758_INPUT_JACK(xname, shift) \ 11381da177e4SLinus Torvalds { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 11391da177e4SLinus Torvalds .info = snd_ac97_stac9758_input_jack_info, \ 11401da177e4SLinus Torvalds .get = snd_ac97_stac9758_input_jack_get, \ 11411da177e4SLinus Torvalds .put = snd_ac97_stac9758_input_jack_put, \ 11421da177e4SLinus Torvalds .private_value = shift } 1143ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_sigmatel_stac9758_controls[] = { 11441da177e4SLinus Torvalds STAC9758_OUTPUT_JACK("Mic1 Jack", 1), 11451da177e4SLinus Torvalds STAC9758_OUTPUT_JACK("LineIn Jack", 4), 11461da177e4SLinus Torvalds STAC9758_OUTPUT_JACK("Front Jack", 7), 11471da177e4SLinus Torvalds STAC9758_OUTPUT_JACK("Rear Jack", 10), 11481da177e4SLinus Torvalds STAC9758_OUTPUT_JACK("Center/LFE Jack", 13), 11491da177e4SLinus Torvalds STAC9758_INPUT_JACK("Mic Input Source", 0), 11501da177e4SLinus Torvalds STAC9758_INPUT_JACK("Line Input Source", 8), 11511da177e4SLinus Torvalds { 11521da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 11531da177e4SLinus Torvalds .name = "Headphone Amp", 11541da177e4SLinus Torvalds .info = snd_ac97_stac9758_phonesel_info, 11551da177e4SLinus Torvalds .get = snd_ac97_stac9758_phonesel_get, 11561da177e4SLinus Torvalds .put = snd_ac97_stac9758_phonesel_put 11571da177e4SLinus Torvalds }, 11581da177e4SLinus Torvalds AC97_SINGLE("Exchange Center/LFE", AC97_SIGMATEL_IOMISC, 4, 1, 0), 11591da177e4SLinus Torvalds AC97_SINGLE("Headphone +3dB Boost", AC97_SIGMATEL_IOMISC, 8, 1, 0) 11601da177e4SLinus Torvalds }; 11611da177e4SLinus Torvalds 1162ee42381eSTakashi Iwai static int patch_sigmatel_stac9758_specific(struct snd_ac97 *ac97) 11631da177e4SLinus Torvalds { 11641da177e4SLinus Torvalds int err; 11651da177e4SLinus Torvalds 11661da177e4SLinus Torvalds err = patch_sigmatel_stac97xx_specific(ac97); 11671da177e4SLinus Torvalds if (err < 0) 11681da177e4SLinus Torvalds return err; 11691da177e4SLinus Torvalds err = patch_build_controls(ac97, snd_ac97_sigmatel_stac9758_controls, 11701da177e4SLinus Torvalds ARRAY_SIZE(snd_ac97_sigmatel_stac9758_controls)); 11711da177e4SLinus Torvalds if (err < 0) 11721da177e4SLinus Torvalds return err; 11731da177e4SLinus Torvalds /* DAC-A direct */ 11741da177e4SLinus Torvalds snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Front Playback"); 11751da177e4SLinus Torvalds /* DAC-A to Mix = PCM */ 11761da177e4SLinus Torvalds /* DAC-B direct = Surround */ 11771da177e4SLinus Torvalds /* DAC-B to Mix */ 11781da177e4SLinus Torvalds snd_ac97_rename_vol_ctl(ac97, "Video Playback", "Surround Mix Playback"); 11791da177e4SLinus Torvalds /* DAC-C direct = Center/LFE */ 11801da177e4SLinus Torvalds 11811da177e4SLinus Torvalds return 0; 11821da177e4SLinus Torvalds } 11831da177e4SLinus Torvalds 11841da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_sigmatel_stac9758_ops = { 11851da177e4SLinus Torvalds .build_3d = patch_sigmatel_stac9700_3d, 11861da177e4SLinus Torvalds .build_specific = patch_sigmatel_stac9758_specific 11871da177e4SLinus Torvalds }; 11881da177e4SLinus Torvalds 1189ac519028STakashi Iwai static int patch_sigmatel_stac9758(struct snd_ac97 * ac97) 11901da177e4SLinus Torvalds { 11911da177e4SLinus Torvalds static unsigned short regs[4] = { 11921da177e4SLinus Torvalds AC97_SIGMATEL_OUTSEL, 11931da177e4SLinus Torvalds AC97_SIGMATEL_IOMISC, 11941da177e4SLinus Torvalds AC97_SIGMATEL_INSEL, 11951da177e4SLinus Torvalds AC97_SIGMATEL_VARIOUS 11961da177e4SLinus Torvalds }; 11971da177e4SLinus Torvalds static unsigned short def_regs[4] = { 11981da177e4SLinus Torvalds /* OUTSEL */ 0xd794, /* CL:CL, SR:SR, LO:MX, LI:DS, MI:DS */ 11991da177e4SLinus Torvalds /* IOMISC */ 0x2001, 12001da177e4SLinus Torvalds /* INSEL */ 0x0201, /* LI:LI, MI:M1 */ 12011da177e4SLinus Torvalds /* VARIOUS */ 0x0040 12021da177e4SLinus Torvalds }; 12031da177e4SLinus Torvalds static unsigned short m675_regs[4] = { 12041da177e4SLinus Torvalds /* OUTSEL */ 0xfc70, /* CL:MX, SR:MX, LO:DS, LI:MX, MI:DS */ 12051da177e4SLinus Torvalds /* IOMISC */ 0x2102, /* HP amp on */ 12061da177e4SLinus Torvalds /* INSEL */ 0x0203, /* LI:LI, MI:FR */ 12071da177e4SLinus Torvalds /* VARIOUS */ 0x0041 /* stereo mic */ 12081da177e4SLinus Torvalds }; 12091da177e4SLinus Torvalds unsigned short *pregs = def_regs; 12101da177e4SLinus Torvalds int i; 12111da177e4SLinus Torvalds 12121da177e4SLinus Torvalds /* Gateway M675 notebook */ 12131da177e4SLinus Torvalds if (ac97->pci && 12141da177e4SLinus Torvalds ac97->subsystem_vendor == 0x107b && 12151da177e4SLinus Torvalds ac97->subsystem_device == 0x0601) 12161da177e4SLinus Torvalds pregs = m675_regs; 12171da177e4SLinus Torvalds 12181da177e4SLinus Torvalds // patch for SigmaTel 12191da177e4SLinus Torvalds ac97->build_ops = &patch_sigmatel_stac9758_ops; 12201da177e4SLinus Torvalds /* FIXME: assume only page 0 for writing cache */ 12211da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR); 12221da177e4SLinus Torvalds for (i = 0; i < 4; i++) 12231da177e4SLinus Torvalds snd_ac97_write_cache(ac97, regs[i], pregs[i]); 12241da177e4SLinus Torvalds 12251da177e4SLinus Torvalds ac97->flags |= AC97_STEREO_MUTES; 12261da177e4SLinus Torvalds return 0; 12271da177e4SLinus Torvalds } 12281da177e4SLinus Torvalds 12291da177e4SLinus Torvalds /* 12301da177e4SLinus Torvalds * Cirrus Logic CS42xx codecs 12311da177e4SLinus Torvalds */ 1232ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_cirrus_controls_spdif[2] = { 12331da177e4SLinus Torvalds AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CSR_SPDIF, 15, 1, 0), 12341da177e4SLinus Torvalds AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "AC97-SPSA", AC97_CSR_ACMODE, 0, 3, 0) 12351da177e4SLinus Torvalds }; 12361da177e4SLinus Torvalds 1237ee42381eSTakashi Iwai static int patch_cirrus_build_spdif(struct snd_ac97 * ac97) 12381da177e4SLinus Torvalds { 12391da177e4SLinus Torvalds int err; 12401da177e4SLinus Torvalds 12411da177e4SLinus Torvalds /* con mask, pro mask, default */ 12421da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0) 12431da177e4SLinus Torvalds return err; 12441da177e4SLinus Torvalds /* switch, spsa */ 12451da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[0], 1)) < 0) 12461da177e4SLinus Torvalds return err; 12471da177e4SLinus Torvalds switch (ac97->id & AC97_ID_CS_MASK) { 12481da177e4SLinus Torvalds case AC97_ID_CS4205: 12491da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[1], 1)) < 0) 12501da177e4SLinus Torvalds return err; 12511da177e4SLinus Torvalds break; 12521da177e4SLinus Torvalds } 12531da177e4SLinus Torvalds /* set default PCM S/PDIF params */ 12541da177e4SLinus Torvalds /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */ 12551da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_CSR_SPDIF, 0x0a20); 12561da177e4SLinus Torvalds return 0; 12571da177e4SLinus Torvalds } 12581da177e4SLinus Torvalds 12591da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_cirrus_ops = { 12601da177e4SLinus Torvalds .build_spdif = patch_cirrus_build_spdif 12611da177e4SLinus Torvalds }; 12621da177e4SLinus Torvalds 1263ac519028STakashi Iwai static int patch_cirrus_spdif(struct snd_ac97 * ac97) 12641da177e4SLinus Torvalds { 12651da177e4SLinus Torvalds /* Basically, the cs4201/cs4205/cs4297a has non-standard sp/dif registers. 12661da177e4SLinus Torvalds WHY CAN'T ANYONE FOLLOW THE BLOODY SPEC? *sigh* 12671da177e4SLinus Torvalds - sp/dif EA ID is not set, but sp/dif is always present. 12681da177e4SLinus Torvalds - enable/disable is spdif register bit 15. 12691da177e4SLinus Torvalds - sp/dif control register is 0x68. differs from AC97: 12701da177e4SLinus Torvalds - valid is bit 14 (vs 15) 12711da177e4SLinus Torvalds - no DRS 12721da177e4SLinus Torvalds - only 44.1/48k [00 = 48, 01=44,1] (AC97 is 00=44.1, 10=48) 12731da177e4SLinus Torvalds - sp/dif ssource select is in 0x5e bits 0,1. 12741da177e4SLinus Torvalds */ 12751da177e4SLinus Torvalds 12761da177e4SLinus Torvalds ac97->build_ops = &patch_cirrus_ops; 12771da177e4SLinus Torvalds ac97->flags |= AC97_CS_SPDIF; 12781da177e4SLinus Torvalds ac97->rates[AC97_RATES_SPDIF] &= ~SNDRV_PCM_RATE_32000; 12791da177e4SLinus Torvalds ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */ 12801da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_CSR_ACMODE, 0x0080); 12811da177e4SLinus Torvalds return 0; 12821da177e4SLinus Torvalds } 12831da177e4SLinus Torvalds 1284ac519028STakashi Iwai static int patch_cirrus_cs4299(struct snd_ac97 * ac97) 12851da177e4SLinus Torvalds { 12861da177e4SLinus Torvalds /* force the detection of PC Beep */ 12871da177e4SLinus Torvalds ac97->flags |= AC97_HAS_PC_BEEP; 12881da177e4SLinus Torvalds 12891da177e4SLinus Torvalds return patch_cirrus_spdif(ac97); 12901da177e4SLinus Torvalds } 12911da177e4SLinus Torvalds 12921da177e4SLinus Torvalds /* 12931da177e4SLinus Torvalds * Conexant codecs 12941da177e4SLinus Torvalds */ 1295ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_conexant_controls_spdif[1] = { 12961da177e4SLinus Torvalds AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CXR_AUDIO_MISC, 3, 1, 0), 12971da177e4SLinus Torvalds }; 12981da177e4SLinus Torvalds 1299ee42381eSTakashi Iwai static int patch_conexant_build_spdif(struct snd_ac97 * ac97) 13001da177e4SLinus Torvalds { 13011da177e4SLinus Torvalds int err; 13021da177e4SLinus Torvalds 13031da177e4SLinus Torvalds /* con mask, pro mask, default */ 13041da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0) 13051da177e4SLinus Torvalds return err; 13061da177e4SLinus Torvalds /* switch */ 13071da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_conexant_controls_spdif[0], 1)) < 0) 13081da177e4SLinus Torvalds return err; 13091da177e4SLinus Torvalds /* set default PCM S/PDIF params */ 13101da177e4SLinus Torvalds /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */ 13111da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_CXR_AUDIO_MISC, 13121da177e4SLinus Torvalds snd_ac97_read(ac97, AC97_CXR_AUDIO_MISC) & ~(AC97_CXR_SPDIFEN|AC97_CXR_COPYRGT|AC97_CXR_SPDIF_MASK)); 13131da177e4SLinus Torvalds return 0; 13141da177e4SLinus Torvalds } 13151da177e4SLinus Torvalds 13161da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_conexant_ops = { 13171da177e4SLinus Torvalds .build_spdif = patch_conexant_build_spdif 13181da177e4SLinus Torvalds }; 13191da177e4SLinus Torvalds 1320ac519028STakashi Iwai static int patch_conexant(struct snd_ac97 * ac97) 13211da177e4SLinus Torvalds { 13221da177e4SLinus Torvalds ac97->build_ops = &patch_conexant_ops; 13231da177e4SLinus Torvalds ac97->flags |= AC97_CX_SPDIF; 13241da177e4SLinus Torvalds ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */ 13251da177e4SLinus Torvalds ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */ 13261da177e4SLinus Torvalds return 0; 13271da177e4SLinus Torvalds } 13281da177e4SLinus Torvalds 1329ac519028STakashi Iwai static int patch_cx20551(struct snd_ac97 *ac97) 13309e292c00STakashi Iwai { 13319e292c00STakashi Iwai snd_ac97_update_bits(ac97, 0x5c, 0x01, 0x01); 13329e292c00STakashi Iwai return 0; 13339e292c00STakashi Iwai } 13349e292c00STakashi Iwai 13351da177e4SLinus Torvalds /* 13361da177e4SLinus Torvalds * Analog Device AD18xx, AD19xx codecs 13371da177e4SLinus Torvalds */ 13381da177e4SLinus Torvalds #ifdef CONFIG_PM 1339ee42381eSTakashi Iwai static void ad18xx_resume(struct snd_ac97 *ac97) 13401da177e4SLinus Torvalds { 13411da177e4SLinus Torvalds static unsigned short setup_regs[] = { 13421da177e4SLinus Torvalds AC97_AD_MISC, AC97_AD_SERIAL_CFG, AC97_AD_JACK_SPDIF, 13431da177e4SLinus Torvalds }; 13441da177e4SLinus Torvalds int i, codec; 13451da177e4SLinus Torvalds 13461da177e4SLinus Torvalds for (i = 0; i < (int)ARRAY_SIZE(setup_regs); i++) { 13471da177e4SLinus Torvalds unsigned short reg = setup_regs[i]; 13481da177e4SLinus Torvalds if (test_bit(reg, ac97->reg_accessed)) { 13491da177e4SLinus Torvalds snd_ac97_write(ac97, reg, ac97->regs[reg]); 13501da177e4SLinus Torvalds snd_ac97_read(ac97, reg); 13511da177e4SLinus Torvalds } 13521da177e4SLinus Torvalds } 13531da177e4SLinus Torvalds 13541da177e4SLinus Torvalds if (! (ac97->flags & AC97_AD_MULTI)) 13551da177e4SLinus Torvalds /* normal restore */ 13561da177e4SLinus Torvalds snd_ac97_restore_status(ac97); 13571da177e4SLinus Torvalds else { 13581da177e4SLinus Torvalds /* restore the AD18xx codec configurations */ 13591da177e4SLinus Torvalds for (codec = 0; codec < 3; codec++) { 13601da177e4SLinus Torvalds if (! ac97->spec.ad18xx.id[codec]) 13611da177e4SLinus Torvalds continue; 13621da177e4SLinus Torvalds /* select single codec */ 13631da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 13641da177e4SLinus Torvalds ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]); 13651da177e4SLinus Torvalds ac97->bus->ops->write(ac97, AC97_AD_CODEC_CFG, ac97->spec.ad18xx.codec_cfg[codec]); 13661da177e4SLinus Torvalds } 13671da177e4SLinus Torvalds /* select all codecs */ 13681da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000); 13691da177e4SLinus Torvalds 13701da177e4SLinus Torvalds /* restore status */ 13711da177e4SLinus Torvalds for (i = 2; i < 0x7c ; i += 2) { 13721da177e4SLinus Torvalds if (i == AC97_POWERDOWN || i == AC97_EXTENDED_ID) 13731da177e4SLinus Torvalds continue; 13741da177e4SLinus Torvalds if (test_bit(i, ac97->reg_accessed)) { 13751da177e4SLinus Torvalds /* handle multi codecs for AD18xx */ 13761da177e4SLinus Torvalds if (i == AC97_PCM) { 13771da177e4SLinus Torvalds for (codec = 0; codec < 3; codec++) { 13781da177e4SLinus Torvalds if (! ac97->spec.ad18xx.id[codec]) 13791da177e4SLinus Torvalds continue; 13801da177e4SLinus Torvalds /* select single codec */ 13811da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 13821da177e4SLinus Torvalds ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]); 13831da177e4SLinus Torvalds /* update PCM bits */ 13841da177e4SLinus Torvalds ac97->bus->ops->write(ac97, AC97_PCM, ac97->spec.ad18xx.pcmreg[codec]); 13851da177e4SLinus Torvalds } 13861da177e4SLinus Torvalds /* select all codecs */ 13871da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000); 13881da177e4SLinus Torvalds continue; 13891da177e4SLinus Torvalds } else if (i == AC97_AD_TEST || 13901da177e4SLinus Torvalds i == AC97_AD_CODEC_CFG || 13911da177e4SLinus Torvalds i == AC97_AD_SERIAL_CFG) 13921da177e4SLinus Torvalds continue; /* ignore */ 13931da177e4SLinus Torvalds } 13941da177e4SLinus Torvalds snd_ac97_write(ac97, i, ac97->regs[i]); 13951da177e4SLinus Torvalds snd_ac97_read(ac97, i); 13961da177e4SLinus Torvalds } 13971da177e4SLinus Torvalds } 13981da177e4SLinus Torvalds 13991da177e4SLinus Torvalds snd_ac97_restore_iec958(ac97); 14001da177e4SLinus Torvalds } 14011561f09aSJaya Kumar 14021561f09aSJaya Kumar static void ad1888_resume(struct snd_ac97 *ac97) 14031561f09aSJaya Kumar { 14041561f09aSJaya Kumar ad18xx_resume(ac97); 14051561f09aSJaya Kumar snd_ac97_write_cache(ac97, AC97_CODEC_CLASS_REV, 0x8080); 14061561f09aSJaya Kumar } 14071561f09aSJaya Kumar 14081da177e4SLinus Torvalds #endif 14091da177e4SLinus Torvalds 1410bd25b7caSVille Syrjala static const struct snd_ac97_res_table ad1819_restbl[] = { 1411bd25b7caSVille Syrjala { AC97_PHONE, 0x9f1f }, 1412bd25b7caSVille Syrjala { AC97_MIC, 0x9f1f }, 1413bd25b7caSVille Syrjala { AC97_LINE, 0x9f1f }, 1414bd25b7caSVille Syrjala { AC97_CD, 0x9f1f }, 1415bd25b7caSVille Syrjala { AC97_VIDEO, 0x9f1f }, 1416bd25b7caSVille Syrjala { AC97_AUX, 0x9f1f }, 1417bd25b7caSVille Syrjala { AC97_PCM, 0x9f1f }, 1418bd25b7caSVille Syrjala { } /* terminator */ 1419bd25b7caSVille Syrjala }; 1420bd25b7caSVille Syrjala 1421ac519028STakashi Iwai static int patch_ad1819(struct snd_ac97 * ac97) 14221da177e4SLinus Torvalds { 14231da177e4SLinus Torvalds unsigned short scfg; 14241da177e4SLinus Torvalds 14251da177e4SLinus Torvalds // patch for Analog Devices 14261da177e4SLinus Torvalds scfg = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG); 14271da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, scfg | 0x7000); /* select all codecs */ 1428bd25b7caSVille Syrjala ac97->res_table = ad1819_restbl; 14291da177e4SLinus Torvalds return 0; 14301da177e4SLinus Torvalds } 14311da177e4SLinus Torvalds 1432ee42381eSTakashi Iwai static unsigned short patch_ad1881_unchained(struct snd_ac97 * ac97, int idx, unsigned short mask) 14331da177e4SLinus Torvalds { 14341da177e4SLinus Torvalds unsigned short val; 14351da177e4SLinus Torvalds 14361da177e4SLinus Torvalds // test for unchained codec 14371da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, mask); 14381da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000); /* ID0C, ID1C, SDIE = off */ 14391da177e4SLinus Torvalds val = snd_ac97_read(ac97, AC97_VENDOR_ID2); 14401da177e4SLinus Torvalds if ((val & 0xff40) != 0x5340) 14411da177e4SLinus Torvalds return 0; 14421da177e4SLinus Torvalds ac97->spec.ad18xx.unchained[idx] = mask; 14431da177e4SLinus Torvalds ac97->spec.ad18xx.id[idx] = val; 14441da177e4SLinus Torvalds ac97->spec.ad18xx.codec_cfg[idx] = 0x0000; 14451da177e4SLinus Torvalds return mask; 14461da177e4SLinus Torvalds } 14471da177e4SLinus Torvalds 1448ee42381eSTakashi Iwai static int patch_ad1881_chained1(struct snd_ac97 * ac97, int idx, unsigned short codec_bits) 14491da177e4SLinus Torvalds { 14501da177e4SLinus Torvalds static int cfg_bits[3] = { 1<<12, 1<<14, 1<<13 }; 14511da177e4SLinus Torvalds unsigned short val; 14521da177e4SLinus Torvalds 14531da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, cfg_bits[idx]); 14541da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0004); // SDIE 14551da177e4SLinus Torvalds val = snd_ac97_read(ac97, AC97_VENDOR_ID2); 14561da177e4SLinus Torvalds if ((val & 0xff40) != 0x5340) 14571da177e4SLinus Torvalds return 0; 14581da177e4SLinus Torvalds if (codec_bits) 14591da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, codec_bits); 14601da177e4SLinus Torvalds ac97->spec.ad18xx.chained[idx] = cfg_bits[idx]; 14611da177e4SLinus Torvalds ac97->spec.ad18xx.id[idx] = val; 14621da177e4SLinus Torvalds ac97->spec.ad18xx.codec_cfg[idx] = codec_bits ? codec_bits : 0x0004; 14631da177e4SLinus Torvalds return 1; 14641da177e4SLinus Torvalds } 14651da177e4SLinus Torvalds 1466ee42381eSTakashi Iwai static void patch_ad1881_chained(struct snd_ac97 * ac97, int unchained_idx, int cidx1, int cidx2) 14671da177e4SLinus Torvalds { 14681da177e4SLinus Torvalds // already detected? 14691da177e4SLinus Torvalds if (ac97->spec.ad18xx.unchained[cidx1] || ac97->spec.ad18xx.chained[cidx1]) 14701da177e4SLinus Torvalds cidx1 = -1; 14711da177e4SLinus Torvalds if (ac97->spec.ad18xx.unchained[cidx2] || ac97->spec.ad18xx.chained[cidx2]) 14721da177e4SLinus Torvalds cidx2 = -1; 14731da177e4SLinus Torvalds if (cidx1 < 0 && cidx2 < 0) 14741da177e4SLinus Torvalds return; 14751da177e4SLinus Torvalds // test for chained codecs 14761da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 14771da177e4SLinus Torvalds ac97->spec.ad18xx.unchained[unchained_idx]); 14781da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0002); // ID1C 14791da177e4SLinus Torvalds ac97->spec.ad18xx.codec_cfg[unchained_idx] = 0x0002; 14801da177e4SLinus Torvalds if (cidx1 >= 0) { 1481c19bcdc6STakashi Iwai if (cidx2 < 0) 1482c19bcdc6STakashi Iwai patch_ad1881_chained1(ac97, cidx1, 0); 1483c19bcdc6STakashi Iwai else if (patch_ad1881_chained1(ac97, cidx1, 0x0006)) // SDIE | ID1C 14841da177e4SLinus Torvalds patch_ad1881_chained1(ac97, cidx2, 0); 14851da177e4SLinus Torvalds else if (patch_ad1881_chained1(ac97, cidx2, 0x0006)) // SDIE | ID1C 14861da177e4SLinus Torvalds patch_ad1881_chained1(ac97, cidx1, 0); 14871da177e4SLinus Torvalds } else if (cidx2 >= 0) { 14881da177e4SLinus Torvalds patch_ad1881_chained1(ac97, cidx2, 0); 14891da177e4SLinus Torvalds } 14901da177e4SLinus Torvalds } 14911da177e4SLinus Torvalds 14921da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_ad1881_build_ops = { 14931da177e4SLinus Torvalds #ifdef CONFIG_PM 14941da177e4SLinus Torvalds .resume = ad18xx_resume 14951da177e4SLinus Torvalds #endif 14961da177e4SLinus Torvalds }; 14971da177e4SLinus Torvalds 1498ac519028STakashi Iwai static int patch_ad1881(struct snd_ac97 * ac97) 14991da177e4SLinus Torvalds { 15001da177e4SLinus Torvalds static const char cfg_idxs[3][2] = { 15011da177e4SLinus Torvalds {2, 1}, 15021da177e4SLinus Torvalds {0, 2}, 15031da177e4SLinus Torvalds {0, 1} 15041da177e4SLinus Torvalds }; 15051da177e4SLinus Torvalds 15061da177e4SLinus Torvalds // patch for Analog Devices 15071da177e4SLinus Torvalds unsigned short codecs[3]; 15081da177e4SLinus Torvalds unsigned short val; 15091da177e4SLinus Torvalds int idx, num; 15101da177e4SLinus Torvalds 15111da177e4SLinus Torvalds val = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG); 15121da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, val); 15131da177e4SLinus Torvalds codecs[0] = patch_ad1881_unchained(ac97, 0, (1<<12)); 15141da177e4SLinus Torvalds codecs[1] = patch_ad1881_unchained(ac97, 1, (1<<14)); 15151da177e4SLinus Torvalds codecs[2] = patch_ad1881_unchained(ac97, 2, (1<<13)); 15161da177e4SLinus Torvalds 15177c22f1aaSTakashi Iwai if (! (codecs[0] || codecs[1] || codecs[2])) 15187c22f1aaSTakashi Iwai goto __end; 15191da177e4SLinus Torvalds 15201da177e4SLinus Torvalds for (idx = 0; idx < 3; idx++) 15211da177e4SLinus Torvalds if (ac97->spec.ad18xx.unchained[idx]) 15221da177e4SLinus Torvalds patch_ad1881_chained(ac97, idx, cfg_idxs[idx][0], cfg_idxs[idx][1]); 15231da177e4SLinus Torvalds 15241da177e4SLinus Torvalds if (ac97->spec.ad18xx.id[1]) { 15251da177e4SLinus Torvalds ac97->flags |= AC97_AD_MULTI; 15261da177e4SLinus Torvalds ac97->scaps |= AC97_SCAP_SURROUND_DAC; 15271da177e4SLinus Torvalds } 15281da177e4SLinus Torvalds if (ac97->spec.ad18xx.id[2]) { 15291da177e4SLinus Torvalds ac97->flags |= AC97_AD_MULTI; 15301da177e4SLinus Torvalds ac97->scaps |= AC97_SCAP_CENTER_LFE_DAC; 15311da177e4SLinus Torvalds } 15321da177e4SLinus Torvalds 15331da177e4SLinus Torvalds __end: 15341da177e4SLinus Torvalds /* select all codecs */ 15351da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000); 15361da177e4SLinus Torvalds /* check if only one codec is present */ 15371da177e4SLinus Torvalds for (idx = num = 0; idx < 3; idx++) 15381da177e4SLinus Torvalds if (ac97->spec.ad18xx.id[idx]) 15391da177e4SLinus Torvalds num++; 15401da177e4SLinus Torvalds if (num == 1) { 15411da177e4SLinus Torvalds /* ok, deselect all ID bits */ 15421da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000); 15431da177e4SLinus Torvalds ac97->spec.ad18xx.codec_cfg[0] = 15441da177e4SLinus Torvalds ac97->spec.ad18xx.codec_cfg[1] = 15451da177e4SLinus Torvalds ac97->spec.ad18xx.codec_cfg[2] = 0x0000; 15461da177e4SLinus Torvalds } 15471da177e4SLinus Torvalds /* required for AD1886/AD1885 combination */ 15481da177e4SLinus Torvalds ac97->ext_id = snd_ac97_read(ac97, AC97_EXTENDED_ID); 15491da177e4SLinus Torvalds if (ac97->spec.ad18xx.id[0]) { 15501da177e4SLinus Torvalds ac97->id &= 0xffff0000; 15511da177e4SLinus Torvalds ac97->id |= ac97->spec.ad18xx.id[0]; 15521da177e4SLinus Torvalds } 15531da177e4SLinus Torvalds ac97->build_ops = &patch_ad1881_build_ops; 15541da177e4SLinus Torvalds return 0; 15551da177e4SLinus Torvalds } 15561da177e4SLinus Torvalds 1557ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_ad1885[] = { 15581da177e4SLinus Torvalds AC97_SINGLE("Digital Mono Direct", AC97_AD_MISC, 11, 1, 0), 15591da177e4SLinus Torvalds /* AC97_SINGLE("Digital Audio Mode", AC97_AD_MISC, 12, 1, 0), */ /* seems problematic */ 15601da177e4SLinus Torvalds AC97_SINGLE("Low Power Mixer", AC97_AD_MISC, 14, 1, 0), 15611da177e4SLinus Torvalds AC97_SINGLE("Zero Fill DAC", AC97_AD_MISC, 15, 1, 0), 15621da177e4SLinus Torvalds AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 9, 1, 1), /* inverted */ 15631da177e4SLinus Torvalds AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 8, 1, 1), /* inverted */ 15641da177e4SLinus Torvalds }; 15651da177e4SLinus Torvalds 15660cb29ea0STakashi Iwai static const DECLARE_TLV_DB_SCALE(db_scale_6bit_6db_max, -8850, 150, 0); 15672f3482fbSTakashi Iwai 1568ee42381eSTakashi Iwai static int patch_ad1885_specific(struct snd_ac97 * ac97) 15691da177e4SLinus Torvalds { 15701da177e4SLinus Torvalds int err; 15711da177e4SLinus Torvalds 15721da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, snd_ac97_controls_ad1885, ARRAY_SIZE(snd_ac97_controls_ad1885))) < 0) 15731da177e4SLinus Torvalds return err; 15742f3482fbSTakashi Iwai reset_tlv(ac97, "Headphone Playback Volume", 15752f3482fbSTakashi Iwai db_scale_6bit_6db_max); 15761da177e4SLinus Torvalds return 0; 15771da177e4SLinus Torvalds } 15781da177e4SLinus Torvalds 15791da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_ad1885_build_ops = { 15801da177e4SLinus Torvalds .build_specific = &patch_ad1885_specific, 15811da177e4SLinus Torvalds #ifdef CONFIG_PM 15821da177e4SLinus Torvalds .resume = ad18xx_resume 15831da177e4SLinus Torvalds #endif 15841da177e4SLinus Torvalds }; 15851da177e4SLinus Torvalds 1586ac519028STakashi Iwai static int patch_ad1885(struct snd_ac97 * ac97) 15871da177e4SLinus Torvalds { 15881da177e4SLinus Torvalds patch_ad1881(ac97); 15891da177e4SLinus Torvalds /* This is required to deal with the Intel D815EEAL2 */ 15901da177e4SLinus Torvalds /* i.e. Line out is actually headphone out from codec */ 15911da177e4SLinus Torvalds 15921da177e4SLinus Torvalds /* set default */ 15931da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_AD_MISC, 0x0404); 15941da177e4SLinus Torvalds 15951da177e4SLinus Torvalds ac97->build_ops = &patch_ad1885_build_ops; 15961da177e4SLinus Torvalds return 0; 15971da177e4SLinus Torvalds } 15981da177e4SLinus Torvalds 15992f3482fbSTakashi Iwai static int patch_ad1886_specific(struct snd_ac97 * ac97) 16002f3482fbSTakashi Iwai { 16012f3482fbSTakashi Iwai reset_tlv(ac97, "Headphone Playback Volume", 16022f3482fbSTakashi Iwai db_scale_6bit_6db_max); 16032f3482fbSTakashi Iwai return 0; 16042f3482fbSTakashi Iwai } 16052f3482fbSTakashi Iwai 16062f3482fbSTakashi Iwai static struct snd_ac97_build_ops patch_ad1886_build_ops = { 16072f3482fbSTakashi Iwai .build_specific = &patch_ad1886_specific, 16082f3482fbSTakashi Iwai #ifdef CONFIG_PM 16092f3482fbSTakashi Iwai .resume = ad18xx_resume 16102f3482fbSTakashi Iwai #endif 16112f3482fbSTakashi Iwai }; 16122f3482fbSTakashi Iwai 1613ac519028STakashi Iwai static int patch_ad1886(struct snd_ac97 * ac97) 16141da177e4SLinus Torvalds { 16151da177e4SLinus Torvalds patch_ad1881(ac97); 16161da177e4SLinus Torvalds /* Presario700 workaround */ 16171da177e4SLinus Torvalds /* for Jack Sense/SPDIF Register misetting causing */ 16181da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_AD_JACK_SPDIF, 0x0010); 16192f3482fbSTakashi Iwai ac97->build_ops = &patch_ad1886_build_ops; 16201da177e4SLinus Torvalds return 0; 16211da177e4SLinus Torvalds } 16221da177e4SLinus Torvalds 162367e9f4b6SRandy Cushman /* MISC bits (AD1888/AD1980/AD1985 register 0x76) */ 16241da177e4SLinus Torvalds #define AC97_AD198X_MBC 0x0003 /* mic boost */ 16251da177e4SLinus Torvalds #define AC97_AD198X_MBC_20 0x0000 /* +20dB */ 16261da177e4SLinus Torvalds #define AC97_AD198X_MBC_10 0x0001 /* +10dB */ 16271da177e4SLinus Torvalds #define AC97_AD198X_MBC_30 0x0002 /* +30dB */ 16281da177e4SLinus Torvalds #define AC97_AD198X_VREFD 0x0004 /* VREF high-Z */ 16296428ea1bSRandy Cushman #define AC97_AD198X_VREFH 0x0008 /* 0=2.25V, 1=3.7V */ 16306428ea1bSRandy Cushman #define AC97_AD198X_VREF_0 0x000c /* 0V (AD1985 only) */ 16316428ea1bSRandy Cushman #define AC97_AD198X_VREF_MASK (AC97_AD198X_VREFH | AC97_AD198X_VREFD) 16326428ea1bSRandy Cushman #define AC97_AD198X_VREF_SHIFT 2 16331da177e4SLinus Torvalds #define AC97_AD198X_SRU 0x0010 /* sample rate unlock */ 16341da177e4SLinus Torvalds #define AC97_AD198X_LOSEL 0x0020 /* LINE_OUT amplifiers input select */ 16351da177e4SLinus Torvalds #define AC97_AD198X_2MIC 0x0040 /* 2-channel mic select */ 16361da177e4SLinus Torvalds #define AC97_AD198X_SPRD 0x0080 /* SPREAD enable */ 16376428ea1bSRandy Cushman #define AC97_AD198X_DMIX0 0x0100 /* downmix mode: */ 16386428ea1bSRandy Cushman /* 0 = 6-to-4, 1 = 6-to-2 downmix */ 16391da177e4SLinus Torvalds #define AC97_AD198X_DMIX1 0x0200 /* downmix mode: 1 = enabled */ 16401da177e4SLinus Torvalds #define AC97_AD198X_HPSEL 0x0400 /* headphone amplifier input select */ 16411da177e4SLinus Torvalds #define AC97_AD198X_CLDIS 0x0800 /* center/lfe disable */ 16421da177e4SLinus Torvalds #define AC97_AD198X_LODIS 0x1000 /* LINE_OUT disable */ 16431da177e4SLinus Torvalds #define AC97_AD198X_MSPLT 0x2000 /* mute split */ 16441da177e4SLinus Torvalds #define AC97_AD198X_AC97NC 0x4000 /* AC97 no compatible mode */ 16451da177e4SLinus Torvalds #define AC97_AD198X_DACZ 0x8000 /* DAC zero-fill mode */ 16461da177e4SLinus Torvalds 164767e9f4b6SRandy Cushman /* MISC 1 bits (AD1986 register 0x76) */ 164867e9f4b6SRandy Cushman #define AC97_AD1986_MBC 0x0003 /* mic boost */ 164967e9f4b6SRandy Cushman #define AC97_AD1986_MBC_20 0x0000 /* +20dB */ 165067e9f4b6SRandy Cushman #define AC97_AD1986_MBC_10 0x0001 /* +10dB */ 165167e9f4b6SRandy Cushman #define AC97_AD1986_MBC_30 0x0002 /* +30dB */ 165267e9f4b6SRandy Cushman #define AC97_AD1986_LISEL0 0x0004 /* LINE_IN select bit 0 */ 165367e9f4b6SRandy Cushman #define AC97_AD1986_LISEL1 0x0008 /* LINE_IN select bit 1 */ 165467e9f4b6SRandy Cushman #define AC97_AD1986_LISEL_MASK (AC97_AD1986_LISEL1 | AC97_AD1986_LISEL0) 165567e9f4b6SRandy Cushman #define AC97_AD1986_LISEL_LI 0x0000 /* LINE_IN pins as LINE_IN source */ 165667e9f4b6SRandy Cushman #define AC97_AD1986_LISEL_SURR 0x0004 /* SURROUND pins as LINE_IN source */ 165767e9f4b6SRandy Cushman #define AC97_AD1986_LISEL_MIC 0x0008 /* MIC_1/2 pins as LINE_IN source */ 165867e9f4b6SRandy Cushman #define AC97_AD1986_SRU 0x0010 /* sample rate unlock */ 165967e9f4b6SRandy Cushman #define AC97_AD1986_SOSEL 0x0020 /* SURROUND_OUT amplifiers input sel */ 166067e9f4b6SRandy Cushman #define AC97_AD1986_2MIC 0x0040 /* 2-channel mic select */ 166167e9f4b6SRandy Cushman #define AC97_AD1986_SPRD 0x0080 /* SPREAD enable */ 166267e9f4b6SRandy Cushman #define AC97_AD1986_DMIX0 0x0100 /* downmix mode: */ 166367e9f4b6SRandy Cushman /* 0 = 6-to-4, 1 = 6-to-2 downmix */ 166467e9f4b6SRandy Cushman #define AC97_AD1986_DMIX1 0x0200 /* downmix mode: 1 = enabled */ 166567e9f4b6SRandy Cushman #define AC97_AD1986_CLDIS 0x0800 /* center/lfe disable */ 166667e9f4b6SRandy Cushman #define AC97_AD1986_SODIS 0x1000 /* SURROUND_OUT disable */ 166767e9f4b6SRandy Cushman #define AC97_AD1986_MSPLT 0x2000 /* mute split (read only 1) */ 166867e9f4b6SRandy Cushman #define AC97_AD1986_AC97NC 0x4000 /* AC97 no compatible mode (r/o 1) */ 166967e9f4b6SRandy Cushman #define AC97_AD1986_DACZ 0x8000 /* DAC zero-fill mode */ 167067e9f4b6SRandy Cushman 167167e9f4b6SRandy Cushman /* MISC 2 bits (AD1986 register 0x70) */ 167267e9f4b6SRandy Cushman #define AC97_AD_MISC2 0x70 /* Misc Control Bits 2 (AD1986) */ 167367e9f4b6SRandy Cushman 167467e9f4b6SRandy Cushman #define AC97_AD1986_CVREF0 0x0004 /* C/LFE VREF_OUT 2.25V */ 167567e9f4b6SRandy Cushman #define AC97_AD1986_CVREF1 0x0008 /* C/LFE VREF_OUT 0V */ 167667e9f4b6SRandy Cushman #define AC97_AD1986_CVREF2 0x0010 /* C/LFE VREF_OUT 3.7V */ 167767e9f4b6SRandy Cushman #define AC97_AD1986_CVREF_MASK \ 167867e9f4b6SRandy Cushman (AC97_AD1986_CVREF2 | AC97_AD1986_CVREF1 | AC97_AD1986_CVREF0) 167967e9f4b6SRandy Cushman #define AC97_AD1986_JSMAP 0x0020 /* Jack Sense Mapping 1 = alternate */ 168067e9f4b6SRandy Cushman #define AC97_AD1986_MMDIS 0x0080 /* Mono Mute Disable */ 168167e9f4b6SRandy Cushman #define AC97_AD1986_MVREF0 0x0400 /* MIC VREF_OUT 2.25V */ 168267e9f4b6SRandy Cushman #define AC97_AD1986_MVREF1 0x0800 /* MIC VREF_OUT 0V */ 168367e9f4b6SRandy Cushman #define AC97_AD1986_MVREF2 0x1000 /* MIC VREF_OUT 3.7V */ 168467e9f4b6SRandy Cushman #define AC97_AD1986_MVREF_MASK \ 168567e9f4b6SRandy Cushman (AC97_AD1986_MVREF2 | AC97_AD1986_MVREF1 | AC97_AD1986_MVREF0) 168667e9f4b6SRandy Cushman 168767e9f4b6SRandy Cushman /* MISC 3 bits (AD1986 register 0x7a) */ 168867e9f4b6SRandy Cushman #define AC97_AD_MISC3 0x7a /* Misc Control Bits 3 (AD1986) */ 168967e9f4b6SRandy Cushman 169067e9f4b6SRandy Cushman #define AC97_AD1986_MMIX 0x0004 /* Mic Mix, left/right */ 169167e9f4b6SRandy Cushman #define AC97_AD1986_GPO 0x0008 /* General Purpose Out */ 169267e9f4b6SRandy Cushman #define AC97_AD1986_LOHPEN 0x0010 /* LINE_OUT headphone drive */ 169367e9f4b6SRandy Cushman #define AC97_AD1986_LVREF0 0x0100 /* LINE_OUT VREF_OUT 2.25V */ 169467e9f4b6SRandy Cushman #define AC97_AD1986_LVREF1 0x0200 /* LINE_OUT VREF_OUT 0V */ 169567e9f4b6SRandy Cushman #define AC97_AD1986_LVREF2 0x0400 /* LINE_OUT VREF_OUT 3.7V */ 169667e9f4b6SRandy Cushman #define AC97_AD1986_LVREF_MASK \ 169767e9f4b6SRandy Cushman (AC97_AD1986_LVREF2 | AC97_AD1986_LVREF1 | AC97_AD1986_LVREF0) 169867e9f4b6SRandy Cushman #define AC97_AD1986_JSINVA 0x0800 /* Jack Sense Invert SENSE_A */ 169967e9f4b6SRandy Cushman #define AC97_AD1986_LOSEL 0x1000 /* LINE_OUT amplifiers input select */ 170067e9f4b6SRandy Cushman #define AC97_AD1986_HPSEL0 0x2000 /* Headphone amplifiers */ 170167e9f4b6SRandy Cushman /* input select Surround DACs */ 170267e9f4b6SRandy Cushman #define AC97_AD1986_HPSEL1 0x4000 /* Headphone amplifiers input */ 170367e9f4b6SRandy Cushman /* select C/LFE DACs */ 170467e9f4b6SRandy Cushman #define AC97_AD1986_JSINVB 0x8000 /* Jack Sense Invert SENSE_B */ 170567e9f4b6SRandy Cushman 170667e9f4b6SRandy Cushman /* Serial Config bits (AD1986 register 0x74) (incomplete) */ 170767e9f4b6SRandy Cushman #define AC97_AD1986_OMS0 0x0100 /* Optional Mic Selector bit 0 */ 170867e9f4b6SRandy Cushman #define AC97_AD1986_OMS1 0x0200 /* Optional Mic Selector bit 1 */ 170967e9f4b6SRandy Cushman #define AC97_AD1986_OMS2 0x0400 /* Optional Mic Selector bit 2 */ 171067e9f4b6SRandy Cushman #define AC97_AD1986_OMS_MASK \ 171167e9f4b6SRandy Cushman (AC97_AD1986_OMS2 | AC97_AD1986_OMS1 | AC97_AD1986_OMS0) 171267e9f4b6SRandy Cushman #define AC97_AD1986_OMS_M 0x0000 /* MIC_1/2 pins are MIC sources */ 171367e9f4b6SRandy Cushman #define AC97_AD1986_OMS_L 0x0100 /* LINE_IN pins are MIC sources */ 171467e9f4b6SRandy Cushman #define AC97_AD1986_OMS_C 0x0200 /* Center/LFE pins are MCI sources */ 171567e9f4b6SRandy Cushman #define AC97_AD1986_OMS_MC 0x0400 /* Mix of MIC and C/LFE pins */ 171667e9f4b6SRandy Cushman /* are MIC sources */ 171767e9f4b6SRandy Cushman #define AC97_AD1986_OMS_ML 0x0500 /* MIX of MIC and LINE_IN pins */ 171867e9f4b6SRandy Cushman /* are MIC sources */ 171967e9f4b6SRandy Cushman #define AC97_AD1986_OMS_LC 0x0600 /* MIX of LINE_IN and C/LFE pins */ 172067e9f4b6SRandy Cushman /* are MIC sources */ 172167e9f4b6SRandy Cushman #define AC97_AD1986_OMS_MLC 0x0700 /* MIX of MIC, LINE_IN, C/LFE pins */ 172267e9f4b6SRandy Cushman /* are MIC sources */ 172367e9f4b6SRandy Cushman 17241da177e4SLinus Torvalds 1725ee42381eSTakashi Iwai static int snd_ac97_ad198x_spdif_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 17261da177e4SLinus Torvalds { 17271da177e4SLinus Torvalds static char *texts[2] = { "AC-Link", "A/D Converter" }; 17281da177e4SLinus Torvalds 17291da177e4SLinus Torvalds uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 17301da177e4SLinus Torvalds uinfo->count = 1; 17311da177e4SLinus Torvalds uinfo->value.enumerated.items = 2; 17321da177e4SLinus Torvalds if (uinfo->value.enumerated.item > 1) 17331da177e4SLinus Torvalds uinfo->value.enumerated.item = 1; 17341da177e4SLinus Torvalds strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 17351da177e4SLinus Torvalds return 0; 17361da177e4SLinus Torvalds } 17371da177e4SLinus Torvalds 1738ee42381eSTakashi Iwai static int snd_ac97_ad198x_spdif_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 17391da177e4SLinus Torvalds { 1740ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 17411da177e4SLinus Torvalds unsigned short val; 17421da177e4SLinus Torvalds 17431da177e4SLinus Torvalds val = ac97->regs[AC97_AD_SERIAL_CFG]; 17441da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = (val >> 2) & 1; 17451da177e4SLinus Torvalds return 0; 17461da177e4SLinus Torvalds } 17471da177e4SLinus Torvalds 1748ee42381eSTakashi Iwai static int snd_ac97_ad198x_spdif_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 17491da177e4SLinus Torvalds { 1750ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 17511da177e4SLinus Torvalds unsigned short val; 17521da177e4SLinus Torvalds 17531da177e4SLinus Torvalds if (ucontrol->value.enumerated.item[0] > 1) 17541da177e4SLinus Torvalds return -EINVAL; 17551da177e4SLinus Torvalds val = ucontrol->value.enumerated.item[0] << 2; 17561da177e4SLinus Torvalds return snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x0004, val); 17571da177e4SLinus Torvalds } 17581da177e4SLinus Torvalds 1759ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ad198x_spdif_source = { 17601da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 17611da177e4SLinus Torvalds .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source", 17621da177e4SLinus Torvalds .info = snd_ac97_ad198x_spdif_source_info, 17631da177e4SLinus Torvalds .get = snd_ac97_ad198x_spdif_source_get, 17641da177e4SLinus Torvalds .put = snd_ac97_ad198x_spdif_source_put, 17651da177e4SLinus Torvalds }; 17661da177e4SLinus Torvalds 1767ee42381eSTakashi Iwai static int patch_ad198x_post_spdif(struct snd_ac97 * ac97) 17681da177e4SLinus Torvalds { 17691da177e4SLinus Torvalds return patch_build_controls(ac97, &snd_ac97_ad198x_spdif_source, 1); 17701da177e4SLinus Torvalds } 17711da177e4SLinus Torvalds 1772ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ad1981x_jack_sense[] = { 17731da177e4SLinus Torvalds AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 11, 1, 0), 17741da177e4SLinus Torvalds AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0), 17751da177e4SLinus Torvalds }; 17761da177e4SLinus Torvalds 1777128a46a5STakashi Iwai /* black list to avoid HP/Line jack-sense controls 1778128a46a5STakashi Iwai * (SS vendor << 16 | device) 1779128a46a5STakashi Iwai */ 1780128a46a5STakashi Iwai static unsigned int ad1981_jacks_blacklist[] = { 1781a31e8c72STakashi Iwai 0x10140523, /* Thinkpad R40 */ 1782a31e8c72STakashi Iwai 0x10140534, /* Thinkpad X31 */ 1783a43c4d4dSTakashi Iwai 0x10140537, /* Thinkpad T41p */ 1784128a46a5STakashi Iwai 0x10140554, /* Thinkpad T42p/R50p */ 17858286c53eSDaniel T Chen 0x10140567, /* Thinkpad T43p 2668-G7U */ 17868286c53eSDaniel T Chen 0x10140581, /* Thinkpad X41-2527 */ 17878286c53eSDaniel T Chen 0x104380b0, /* Asus A7V8X-MX */ 17888286c53eSDaniel T Chen 0x11790241, /* Toshiba Satellite A-15 S127 */ 17898286c53eSDaniel T Chen 0x144dc01a, /* Samsung NP-X20C004/SEG */ 1790128a46a5STakashi Iwai 0 /* end */ 1791128a46a5STakashi Iwai }; 1792128a46a5STakashi Iwai 1793128a46a5STakashi Iwai static int check_list(struct snd_ac97 *ac97, const unsigned int *list) 1794128a46a5STakashi Iwai { 1795128a46a5STakashi Iwai u32 subid = ((u32)ac97->subsystem_vendor << 16) | ac97->subsystem_device; 1796128a46a5STakashi Iwai for (; *list; list++) 1797128a46a5STakashi Iwai if (*list == subid) 1798128a46a5STakashi Iwai return 1; 1799128a46a5STakashi Iwai return 0; 1800128a46a5STakashi Iwai } 1801128a46a5STakashi Iwai 1802ee42381eSTakashi Iwai static int patch_ad1981a_specific(struct snd_ac97 * ac97) 18031da177e4SLinus Torvalds { 1804128a46a5STakashi Iwai if (check_list(ac97, ad1981_jacks_blacklist)) 1805128a46a5STakashi Iwai return 0; 18061da177e4SLinus Torvalds return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense, 18071da177e4SLinus Torvalds ARRAY_SIZE(snd_ac97_ad1981x_jack_sense)); 18081da177e4SLinus Torvalds } 18091da177e4SLinus Torvalds 18101da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_ad1981a_build_ops = { 18111da177e4SLinus Torvalds .build_post_spdif = patch_ad198x_post_spdif, 18121da177e4SLinus Torvalds .build_specific = patch_ad1981a_specific, 18131da177e4SLinus Torvalds #ifdef CONFIG_PM 18141da177e4SLinus Torvalds .resume = ad18xx_resume 18151da177e4SLinus Torvalds #endif 18161da177e4SLinus Torvalds }; 18171da177e4SLinus Torvalds 1818128a46a5STakashi Iwai /* white list to enable HP jack-sense bits 1819128a46a5STakashi Iwai * (SS vendor << 16 | device) 1820128a46a5STakashi Iwai */ 1821128a46a5STakashi Iwai static unsigned int ad1981_jacks_whitelist[] = { 1822128a46a5STakashi Iwai 0x0e11005a, /* HP nc4000/4010 */ 1823128a46a5STakashi Iwai 0x103c0890, /* HP nc6000 */ 1824128a46a5STakashi Iwai 0x103c0938, /* HP nc4220 */ 1825128a46a5STakashi Iwai 0x103c099c, /* HP nx6110 */ 1826128a46a5STakashi Iwai 0x103c0944, /* HP nc6220 */ 1827128a46a5STakashi Iwai 0x103c0934, /* HP nc8220 */ 1828128a46a5STakashi Iwai 0x103c006d, /* HP nx9105 */ 1829128a46a5STakashi Iwai 0x17340088, /* FSC Scenic-W */ 1830128a46a5STakashi Iwai 0 /* end */ 1831128a46a5STakashi Iwai }; 1832128a46a5STakashi Iwai 1833ee42381eSTakashi Iwai static void check_ad1981_hp_jack_sense(struct snd_ac97 *ac97) 18341da177e4SLinus Torvalds { 1835128a46a5STakashi Iwai if (check_list(ac97, ad1981_jacks_whitelist)) 18361da177e4SLinus Torvalds /* enable headphone jack sense */ 18371da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_AD_JACK_SPDIF, 1<<11, 1<<11); 18381da177e4SLinus Torvalds } 18391da177e4SLinus Torvalds 1840ac519028STakashi Iwai static int patch_ad1981a(struct snd_ac97 *ac97) 18411da177e4SLinus Torvalds { 18421da177e4SLinus Torvalds patch_ad1881(ac97); 18431da177e4SLinus Torvalds ac97->build_ops = &patch_ad1981a_build_ops; 18441da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT); 18451da177e4SLinus Torvalds ac97->flags |= AC97_STEREO_MUTES; 18461da177e4SLinus Torvalds check_ad1981_hp_jack_sense(ac97); 18471da177e4SLinus Torvalds return 0; 18481da177e4SLinus Torvalds } 18491da177e4SLinus Torvalds 1850ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ad198x_2cmic = 18511da177e4SLinus Torvalds AC97_SINGLE("Stereo Mic", AC97_AD_MISC, 6, 1, 0); 18521da177e4SLinus Torvalds 1853ee42381eSTakashi Iwai static int patch_ad1981b_specific(struct snd_ac97 *ac97) 18541da177e4SLinus Torvalds { 18551da177e4SLinus Torvalds int err; 18561da177e4SLinus Torvalds 18571da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0) 18581da177e4SLinus Torvalds return err; 1859128a46a5STakashi Iwai if (check_list(ac97, ad1981_jacks_blacklist)) 1860128a46a5STakashi Iwai return 0; 18611da177e4SLinus Torvalds return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense, 18621da177e4SLinus Torvalds ARRAY_SIZE(snd_ac97_ad1981x_jack_sense)); 18631da177e4SLinus Torvalds } 18641da177e4SLinus Torvalds 18651da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_ad1981b_build_ops = { 18661da177e4SLinus Torvalds .build_post_spdif = patch_ad198x_post_spdif, 18671da177e4SLinus Torvalds .build_specific = patch_ad1981b_specific, 18681da177e4SLinus Torvalds #ifdef CONFIG_PM 18691da177e4SLinus Torvalds .resume = ad18xx_resume 18701da177e4SLinus Torvalds #endif 18711da177e4SLinus Torvalds }; 18721da177e4SLinus Torvalds 1873ac519028STakashi Iwai static int patch_ad1981b(struct snd_ac97 *ac97) 18741da177e4SLinus Torvalds { 18751da177e4SLinus Torvalds patch_ad1881(ac97); 18761da177e4SLinus Torvalds ac97->build_ops = &patch_ad1981b_build_ops; 18771da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT); 18781da177e4SLinus Torvalds ac97->flags |= AC97_STEREO_MUTES; 18791da177e4SLinus Torvalds check_ad1981_hp_jack_sense(ac97); 18801da177e4SLinus Torvalds return 0; 18811da177e4SLinus Torvalds } 18821da177e4SLinus Torvalds 1883*a5ce8890STakashi Iwai #define snd_ac97_ad1888_lohpsel_info snd_ctl_boolean_mono_info 18841da177e4SLinus Torvalds 1885ee42381eSTakashi Iwai static int snd_ac97_ad1888_lohpsel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 18861da177e4SLinus Torvalds { 1887ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 18881da177e4SLinus Torvalds unsigned short val; 18891da177e4SLinus Torvalds 18901da177e4SLinus Torvalds val = ac97->regs[AC97_AD_MISC]; 18911da177e4SLinus Torvalds ucontrol->value.integer.value[0] = !(val & AC97_AD198X_LOSEL); 18921da177e4SLinus Torvalds return 0; 18931da177e4SLinus Torvalds } 18941da177e4SLinus Torvalds 1895ee42381eSTakashi Iwai static int snd_ac97_ad1888_lohpsel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 18961da177e4SLinus Torvalds { 1897ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 18981da177e4SLinus Torvalds unsigned short val; 18991da177e4SLinus Torvalds 19001da177e4SLinus Torvalds val = !ucontrol->value.integer.value[0] 19011da177e4SLinus Torvalds ? (AC97_AD198X_LOSEL | AC97_AD198X_HPSEL) : 0; 19021da177e4SLinus Torvalds return snd_ac97_update_bits(ac97, AC97_AD_MISC, 19031da177e4SLinus Torvalds AC97_AD198X_LOSEL | AC97_AD198X_HPSEL, val); 19041da177e4SLinus Torvalds } 19051da177e4SLinus Torvalds 1906ee42381eSTakashi Iwai static int snd_ac97_ad1888_downmix_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 19071da177e4SLinus Torvalds { 19081da177e4SLinus Torvalds static char *texts[3] = {"Off", "6 -> 4", "6 -> 2"}; 19091da177e4SLinus Torvalds 19101da177e4SLinus Torvalds uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 19111da177e4SLinus Torvalds uinfo->count = 1; 19121da177e4SLinus Torvalds uinfo->value.enumerated.items = 3; 19131da177e4SLinus Torvalds if (uinfo->value.enumerated.item > 2) 19141da177e4SLinus Torvalds uinfo->value.enumerated.item = 2; 19151da177e4SLinus Torvalds strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 19161da177e4SLinus Torvalds return 0; 19171da177e4SLinus Torvalds } 19181da177e4SLinus Torvalds 1919ee42381eSTakashi Iwai static int snd_ac97_ad1888_downmix_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 19201da177e4SLinus Torvalds { 1921ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 19221da177e4SLinus Torvalds unsigned short val; 19231da177e4SLinus Torvalds 19241da177e4SLinus Torvalds val = ac97->regs[AC97_AD_MISC]; 19251da177e4SLinus Torvalds if (!(val & AC97_AD198X_DMIX1)) 19261da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = 0; 19271da177e4SLinus Torvalds else 19281da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = 1 + ((val >> 8) & 1); 19291da177e4SLinus Torvalds return 0; 19301da177e4SLinus Torvalds } 19311da177e4SLinus Torvalds 1932ee42381eSTakashi Iwai static int snd_ac97_ad1888_downmix_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 19331da177e4SLinus Torvalds { 1934ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 19351da177e4SLinus Torvalds unsigned short val; 19361da177e4SLinus Torvalds 19371da177e4SLinus Torvalds if (ucontrol->value.enumerated.item[0] > 2) 19381da177e4SLinus Torvalds return -EINVAL; 19391da177e4SLinus Torvalds if (ucontrol->value.enumerated.item[0] == 0) 19401da177e4SLinus Torvalds val = 0; 19411da177e4SLinus Torvalds else 19421da177e4SLinus Torvalds val = AC97_AD198X_DMIX1 | 19431da177e4SLinus Torvalds ((ucontrol->value.enumerated.item[0] - 1) << 8); 19441da177e4SLinus Torvalds return snd_ac97_update_bits(ac97, AC97_AD_MISC, 19451da177e4SLinus Torvalds AC97_AD198X_DMIX0 | AC97_AD198X_DMIX1, val); 19461da177e4SLinus Torvalds } 19471da177e4SLinus Torvalds 1948ee42381eSTakashi Iwai static void ad1888_update_jacks(struct snd_ac97 *ac97) 1949eb8caf30STakashi Iwai { 19504525c9f3STakashi Iwai unsigned short val = 0; 1951c26a8de2SRandy Cushman /* clear LODIS if shared jack is to be used for Surround out */ 1952c26a8de2SRandy Cushman if (is_shared_linein(ac97)) 19534525c9f3STakashi Iwai val |= (1 << 12); 1954c26a8de2SRandy Cushman /* clear CLDIS if shared jack is to be used for C/LFE out */ 1955c26a8de2SRandy Cushman if (is_shared_micin(ac97)) 19564525c9f3STakashi Iwai val |= (1 << 11); 1957eb8caf30STakashi Iwai /* shared Line-In */ 19584525c9f3STakashi Iwai snd_ac97_update_bits(ac97, AC97_AD_MISC, (1 << 11) | (1 << 12), val); 1959eb8caf30STakashi Iwai } 1960eb8caf30STakashi Iwai 1961ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ad1888_controls[] = { 19621da177e4SLinus Torvalds { 19631da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 19641da177e4SLinus Torvalds .name = "Exchange Front/Surround", 19651da177e4SLinus Torvalds .info = snd_ac97_ad1888_lohpsel_info, 19661da177e4SLinus Torvalds .get = snd_ac97_ad1888_lohpsel_get, 19671da177e4SLinus Torvalds .put = snd_ac97_ad1888_lohpsel_put 19681da177e4SLinus Torvalds }, 196902856b56SJaya Kumar AC97_SINGLE("V_REFOUT Enable", AC97_AD_MISC, 2, 1, 1), 197002856b56SJaya Kumar AC97_SINGLE("High Pass Filter Enable", AC97_AD_TEST2, 12, 1, 1), 19711da177e4SLinus Torvalds AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC, 7, 1, 0), 19721da177e4SLinus Torvalds { 19731da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 19741da177e4SLinus Torvalds .name = "Downmix", 19751da177e4SLinus Torvalds .info = snd_ac97_ad1888_downmix_info, 19761da177e4SLinus Torvalds .get = snd_ac97_ad1888_downmix_get, 19771da177e4SLinus Torvalds .put = snd_ac97_ad1888_downmix_put 19781da177e4SLinus Torvalds }, 1979eb8caf30STakashi Iwai AC97_SURROUND_JACK_MODE_CTL, 1980eb8caf30STakashi Iwai AC97_CHANNEL_MODE_CTL, 1981eeacb545SSergey Ulanov 1982eeacb545SSergey Ulanov AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0), 1983eeacb545SSergey Ulanov AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0), 19841da177e4SLinus Torvalds }; 19851da177e4SLinus Torvalds 1986ee42381eSTakashi Iwai static int patch_ad1888_specific(struct snd_ac97 *ac97) 19871da177e4SLinus Torvalds { 19881da177e4SLinus Torvalds /* rename 0x04 as "Master" and 0x02 as "Master Surround" */ 19891da177e4SLinus Torvalds snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Master Surround Playback"); 19901da177e4SLinus Torvalds snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback"); 19911da177e4SLinus Torvalds return patch_build_controls(ac97, snd_ac97_ad1888_controls, ARRAY_SIZE(snd_ac97_ad1888_controls)); 19921da177e4SLinus Torvalds } 19931da177e4SLinus Torvalds 19941da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_ad1888_build_ops = { 19951da177e4SLinus Torvalds .build_post_spdif = patch_ad198x_post_spdif, 19961da177e4SLinus Torvalds .build_specific = patch_ad1888_specific, 19971da177e4SLinus Torvalds #ifdef CONFIG_PM 19981561f09aSJaya Kumar .resume = ad1888_resume, 19991da177e4SLinus Torvalds #endif 2000eb8caf30STakashi Iwai .update_jacks = ad1888_update_jacks, 20011da177e4SLinus Torvalds }; 20021da177e4SLinus Torvalds 2003ac519028STakashi Iwai static int patch_ad1888(struct snd_ac97 * ac97) 20041da177e4SLinus Torvalds { 20051da177e4SLinus Torvalds unsigned short misc; 20061da177e4SLinus Torvalds 20071da177e4SLinus Torvalds patch_ad1881(ac97); 20081da177e4SLinus Torvalds ac97->build_ops = &patch_ad1888_build_ops; 20091da177e4SLinus Torvalds /* Switch FRONT/SURROUND LINE-OUT/HP-OUT default connection */ 20101da177e4SLinus Torvalds /* it seems that most vendors connect line-out connector to headphone out of AC'97 */ 20111da177e4SLinus Torvalds /* AD-compatible mode */ 20121da177e4SLinus Torvalds /* Stereo mutes enabled */ 20131da177e4SLinus Torvalds misc = snd_ac97_read(ac97, AC97_AD_MISC); 20141da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_AD_MISC, misc | 20151da177e4SLinus Torvalds AC97_AD198X_LOSEL | 20161da177e4SLinus Torvalds AC97_AD198X_HPSEL | 20171da177e4SLinus Torvalds AC97_AD198X_MSPLT | 20181da177e4SLinus Torvalds AC97_AD198X_AC97NC); 20191da177e4SLinus Torvalds ac97->flags |= AC97_STEREO_MUTES; 20201da177e4SLinus Torvalds return 0; 20211da177e4SLinus Torvalds } 20221da177e4SLinus Torvalds 2023ee42381eSTakashi Iwai static int patch_ad1980_specific(struct snd_ac97 *ac97) 20241da177e4SLinus Torvalds { 20251da177e4SLinus Torvalds int err; 20261da177e4SLinus Torvalds 20271da177e4SLinus Torvalds if ((err = patch_ad1888_specific(ac97)) < 0) 20281da177e4SLinus Torvalds return err; 20291da177e4SLinus Torvalds return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1); 20301da177e4SLinus Torvalds } 20311da177e4SLinus Torvalds 20321da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_ad1980_build_ops = { 20331da177e4SLinus Torvalds .build_post_spdif = patch_ad198x_post_spdif, 20341da177e4SLinus Torvalds .build_specific = patch_ad1980_specific, 20351da177e4SLinus Torvalds #ifdef CONFIG_PM 2036462c4173SClemens Ladisch .resume = ad18xx_resume, 20371da177e4SLinus Torvalds #endif 2038462c4173SClemens Ladisch .update_jacks = ad1888_update_jacks, 20391da177e4SLinus Torvalds }; 20401da177e4SLinus Torvalds 2041ac519028STakashi Iwai static int patch_ad1980(struct snd_ac97 * ac97) 20421da177e4SLinus Torvalds { 20431da177e4SLinus Torvalds patch_ad1888(ac97); 20441da177e4SLinus Torvalds ac97->build_ops = &patch_ad1980_build_ops; 20451da177e4SLinus Torvalds return 0; 20461da177e4SLinus Torvalds } 20471da177e4SLinus Torvalds 20486428ea1bSRandy Cushman static int snd_ac97_ad1985_vrefout_info(struct snd_kcontrol *kcontrol, 20496428ea1bSRandy Cushman struct snd_ctl_elem_info *uinfo) 20506428ea1bSRandy Cushman { 20516428ea1bSRandy Cushman static char *texts[4] = {"High-Z", "3.7 V", "2.25 V", "0 V"}; 20526428ea1bSRandy Cushman 20536428ea1bSRandy Cushman uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 20546428ea1bSRandy Cushman uinfo->count = 1; 20556428ea1bSRandy Cushman uinfo->value.enumerated.items = 4; 20566428ea1bSRandy Cushman if (uinfo->value.enumerated.item > 3) 20576428ea1bSRandy Cushman uinfo->value.enumerated.item = 3; 20586428ea1bSRandy Cushman strcpy(uinfo->value.enumerated.name, 20596428ea1bSRandy Cushman texts[uinfo->value.enumerated.item]); 20606428ea1bSRandy Cushman return 0; 20616428ea1bSRandy Cushman } 20626428ea1bSRandy Cushman 20636428ea1bSRandy Cushman static int snd_ac97_ad1985_vrefout_get(struct snd_kcontrol *kcontrol, 20646428ea1bSRandy Cushman struct snd_ctl_elem_value *ucontrol) 20656428ea1bSRandy Cushman { 20666428ea1bSRandy Cushman static const int reg2ctrl[4] = {2, 0, 1, 3}; 20676428ea1bSRandy Cushman struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 20686428ea1bSRandy Cushman unsigned short val; 20696428ea1bSRandy Cushman val = (ac97->regs[AC97_AD_MISC] & AC97_AD198X_VREF_MASK) 20706428ea1bSRandy Cushman >> AC97_AD198X_VREF_SHIFT; 20716428ea1bSRandy Cushman ucontrol->value.enumerated.item[0] = reg2ctrl[val]; 20726428ea1bSRandy Cushman return 0; 20736428ea1bSRandy Cushman } 20746428ea1bSRandy Cushman 20756428ea1bSRandy Cushman static int snd_ac97_ad1985_vrefout_put(struct snd_kcontrol *kcontrol, 20766428ea1bSRandy Cushman struct snd_ctl_elem_value *ucontrol) 20776428ea1bSRandy Cushman { 20786428ea1bSRandy Cushman static const int ctrl2reg[4] = {1, 2, 0, 3}; 20796428ea1bSRandy Cushman struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 20806428ea1bSRandy Cushman unsigned short val; 20816428ea1bSRandy Cushman 20826428ea1bSRandy Cushman if (ucontrol->value.enumerated.item[0] > 3 20836428ea1bSRandy Cushman || ucontrol->value.enumerated.item[0] < 0) 20846428ea1bSRandy Cushman return -EINVAL; 20856428ea1bSRandy Cushman val = ctrl2reg[ucontrol->value.enumerated.item[0]] 20866428ea1bSRandy Cushman << AC97_AD198X_VREF_SHIFT; 20876428ea1bSRandy Cushman return snd_ac97_update_bits(ac97, AC97_AD_MISC, 20886428ea1bSRandy Cushman AC97_AD198X_VREF_MASK, val); 20896428ea1bSRandy Cushman } 20906428ea1bSRandy Cushman 2091ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_ad1985_controls[] = { 20926428ea1bSRandy Cushman AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0), 20936428ea1bSRandy Cushman { 20946428ea1bSRandy Cushman .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 20956428ea1bSRandy Cushman .name = "Exchange Front/Surround", 20966428ea1bSRandy Cushman .info = snd_ac97_ad1888_lohpsel_info, 20976428ea1bSRandy Cushman .get = snd_ac97_ad1888_lohpsel_get, 20986428ea1bSRandy Cushman .put = snd_ac97_ad1888_lohpsel_put 20996428ea1bSRandy Cushman }, 21006428ea1bSRandy Cushman AC97_SINGLE("High Pass Filter Enable", AC97_AD_TEST2, 12, 1, 1), 21016428ea1bSRandy Cushman AC97_SINGLE("Spread Front to Surround and Center/LFE", 21026428ea1bSRandy Cushman AC97_AD_MISC, 7, 1, 0), 21036428ea1bSRandy Cushman { 21046428ea1bSRandy Cushman .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 21056428ea1bSRandy Cushman .name = "Downmix", 21066428ea1bSRandy Cushman .info = snd_ac97_ad1888_downmix_info, 21076428ea1bSRandy Cushman .get = snd_ac97_ad1888_downmix_get, 21086428ea1bSRandy Cushman .put = snd_ac97_ad1888_downmix_put 21096428ea1bSRandy Cushman }, 21106428ea1bSRandy Cushman { 21116428ea1bSRandy Cushman .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 21126428ea1bSRandy Cushman .name = "V_REFOUT", 21136428ea1bSRandy Cushman .info = snd_ac97_ad1985_vrefout_info, 21146428ea1bSRandy Cushman .get = snd_ac97_ad1985_vrefout_get, 21156428ea1bSRandy Cushman .put = snd_ac97_ad1985_vrefout_put 21166428ea1bSRandy Cushman }, 21176428ea1bSRandy Cushman AC97_SURROUND_JACK_MODE_CTL, 21186428ea1bSRandy Cushman AC97_CHANNEL_MODE_CTL, 21196428ea1bSRandy Cushman 21206428ea1bSRandy Cushman AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0), 21216428ea1bSRandy Cushman AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0), 21221da177e4SLinus Torvalds }; 21231da177e4SLinus Torvalds 2124ee42381eSTakashi Iwai static void ad1985_update_jacks(struct snd_ac97 *ac97) 2125e5b3f45fSTakashi Iwai { 21264525c9f3STakashi Iwai ad1888_update_jacks(ac97); 2127c26a8de2SRandy Cushman /* clear OMS if shared jack is to be used for C/LFE out */ 2128fc232c6eSTakashi Iwai snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 1 << 9, 2129c26a8de2SRandy Cushman is_shared_micin(ac97) ? 1 << 9 : 0); 2130e5b3f45fSTakashi Iwai } 2131e5b3f45fSTakashi Iwai 2132ee42381eSTakashi Iwai static int patch_ad1985_specific(struct snd_ac97 *ac97) 21331da177e4SLinus Torvalds { 21341da177e4SLinus Torvalds int err; 21351da177e4SLinus Torvalds 21366428ea1bSRandy Cushman /* rename 0x04 as "Master" and 0x02 as "Master Surround" */ 21376428ea1bSRandy Cushman snd_ac97_rename_vol_ctl(ac97, "Master Playback", 21386428ea1bSRandy Cushman "Master Surround Playback"); 21396428ea1bSRandy Cushman snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback"); 21406428ea1bSRandy Cushman 21416428ea1bSRandy Cushman if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0) 21421da177e4SLinus Torvalds return err; 21436428ea1bSRandy Cushman 21446428ea1bSRandy Cushman return patch_build_controls(ac97, snd_ac97_ad1985_controls, 21456428ea1bSRandy Cushman ARRAY_SIZE(snd_ac97_ad1985_controls)); 21461da177e4SLinus Torvalds } 21471da177e4SLinus Torvalds 21481da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_ad1985_build_ops = { 21491da177e4SLinus Torvalds .build_post_spdif = patch_ad198x_post_spdif, 21501da177e4SLinus Torvalds .build_specific = patch_ad1985_specific, 21511da177e4SLinus Torvalds #ifdef CONFIG_PM 2152462c4173SClemens Ladisch .resume = ad18xx_resume, 21531da177e4SLinus Torvalds #endif 2154e5b3f45fSTakashi Iwai .update_jacks = ad1985_update_jacks, 21551da177e4SLinus Torvalds }; 21561da177e4SLinus Torvalds 2157ac519028STakashi Iwai static int patch_ad1985(struct snd_ac97 * ac97) 21581da177e4SLinus Torvalds { 21591da177e4SLinus Torvalds unsigned short misc; 21601da177e4SLinus Torvalds 21611da177e4SLinus Torvalds patch_ad1881(ac97); 21621da177e4SLinus Torvalds ac97->build_ops = &patch_ad1985_build_ops; 21631da177e4SLinus Torvalds misc = snd_ac97_read(ac97, AC97_AD_MISC); 21641da177e4SLinus Torvalds /* switch front/surround line-out/hp-out */ 21651da177e4SLinus Torvalds /* AD-compatible mode */ 21661da177e4SLinus Torvalds /* Stereo mutes enabled */ 21671da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_AD_MISC, misc | 21681da177e4SLinus Torvalds AC97_AD198X_LOSEL | 21691da177e4SLinus Torvalds AC97_AD198X_HPSEL | 21701da177e4SLinus Torvalds AC97_AD198X_MSPLT | 21711da177e4SLinus Torvalds AC97_AD198X_AC97NC); 21721da177e4SLinus Torvalds ac97->flags |= AC97_STEREO_MUTES; 21736428ea1bSRandy Cushman 21746428ea1bSRandy Cushman /* update current jack configuration */ 21756428ea1bSRandy Cushman ad1985_update_jacks(ac97); 21766428ea1bSRandy Cushman 21771da177e4SLinus Torvalds /* on AD1985 rev. 3, AC'97 revision bits are zero */ 21781da177e4SLinus Torvalds ac97->ext_id = (ac97->ext_id & ~AC97_EI_REV_MASK) | AC97_EI_REV_23; 21791da177e4SLinus Torvalds return 0; 21801da177e4SLinus Torvalds } 21811da177e4SLinus Torvalds 2182*a5ce8890STakashi Iwai #define snd_ac97_ad1986_bool_info snd_ctl_boolean_mono_info 218367e9f4b6SRandy Cushman 218467e9f4b6SRandy Cushman static int snd_ac97_ad1986_lososel_get(struct snd_kcontrol *kcontrol, 218567e9f4b6SRandy Cushman struct snd_ctl_elem_value *ucontrol) 218667e9f4b6SRandy Cushman { 218767e9f4b6SRandy Cushman struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 218867e9f4b6SRandy Cushman unsigned short val; 218967e9f4b6SRandy Cushman 219067e9f4b6SRandy Cushman val = ac97->regs[AC97_AD_MISC3]; 219167e9f4b6SRandy Cushman ucontrol->value.integer.value[0] = (val & AC97_AD1986_LOSEL) != 0; 219267e9f4b6SRandy Cushman return 0; 219367e9f4b6SRandy Cushman } 219467e9f4b6SRandy Cushman 219567e9f4b6SRandy Cushman static int snd_ac97_ad1986_lososel_put(struct snd_kcontrol *kcontrol, 219667e9f4b6SRandy Cushman struct snd_ctl_elem_value *ucontrol) 219767e9f4b6SRandy Cushman { 219867e9f4b6SRandy Cushman struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 219967e9f4b6SRandy Cushman int ret0; 220067e9f4b6SRandy Cushman int ret1; 220167e9f4b6SRandy Cushman int sprd = (ac97->regs[AC97_AD_MISC] & AC97_AD1986_SPRD) != 0; 220267e9f4b6SRandy Cushman 220367e9f4b6SRandy Cushman ret0 = snd_ac97_update_bits(ac97, AC97_AD_MISC3, AC97_AD1986_LOSEL, 220467e9f4b6SRandy Cushman ucontrol->value.integer.value[0] != 0 220567e9f4b6SRandy Cushman ? AC97_AD1986_LOSEL : 0); 220667e9f4b6SRandy Cushman if (ret0 < 0) 220767e9f4b6SRandy Cushman return ret0; 220867e9f4b6SRandy Cushman 220967e9f4b6SRandy Cushman /* SOSEL is set to values of "Spread" or "Exchange F/S" controls */ 221067e9f4b6SRandy Cushman ret1 = snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD1986_SOSEL, 221167e9f4b6SRandy Cushman (ucontrol->value.integer.value[0] != 0 221267e9f4b6SRandy Cushman || sprd) 221367e9f4b6SRandy Cushman ? AC97_AD1986_SOSEL : 0); 221467e9f4b6SRandy Cushman if (ret1 < 0) 221567e9f4b6SRandy Cushman return ret1; 221667e9f4b6SRandy Cushman 221767e9f4b6SRandy Cushman return (ret0 > 0 || ret1 > 0) ? 1 : 0; 221867e9f4b6SRandy Cushman } 221967e9f4b6SRandy Cushman 222067e9f4b6SRandy Cushman static int snd_ac97_ad1986_spread_get(struct snd_kcontrol *kcontrol, 222167e9f4b6SRandy Cushman struct snd_ctl_elem_value *ucontrol) 222267e9f4b6SRandy Cushman { 222367e9f4b6SRandy Cushman struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 222467e9f4b6SRandy Cushman unsigned short val; 222567e9f4b6SRandy Cushman 222667e9f4b6SRandy Cushman val = ac97->regs[AC97_AD_MISC]; 222767e9f4b6SRandy Cushman ucontrol->value.integer.value[0] = (val & AC97_AD1986_SPRD) != 0; 222867e9f4b6SRandy Cushman return 0; 222967e9f4b6SRandy Cushman } 223067e9f4b6SRandy Cushman 223167e9f4b6SRandy Cushman static int snd_ac97_ad1986_spread_put(struct snd_kcontrol *kcontrol, 223267e9f4b6SRandy Cushman struct snd_ctl_elem_value *ucontrol) 223367e9f4b6SRandy Cushman { 223467e9f4b6SRandy Cushman struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 223567e9f4b6SRandy Cushman int ret0; 223667e9f4b6SRandy Cushman int ret1; 223767e9f4b6SRandy Cushman int sprd = (ac97->regs[AC97_AD_MISC3] & AC97_AD1986_LOSEL) != 0; 223867e9f4b6SRandy Cushman 223967e9f4b6SRandy Cushman ret0 = snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD1986_SPRD, 224067e9f4b6SRandy Cushman ucontrol->value.integer.value[0] != 0 224167e9f4b6SRandy Cushman ? AC97_AD1986_SPRD : 0); 224267e9f4b6SRandy Cushman if (ret0 < 0) 224367e9f4b6SRandy Cushman return ret0; 224467e9f4b6SRandy Cushman 224567e9f4b6SRandy Cushman /* SOSEL is set to values of "Spread" or "Exchange F/S" controls */ 224667e9f4b6SRandy Cushman ret1 = snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD1986_SOSEL, 224767e9f4b6SRandy Cushman (ucontrol->value.integer.value[0] != 0 224867e9f4b6SRandy Cushman || sprd) 224967e9f4b6SRandy Cushman ? AC97_AD1986_SOSEL : 0); 225067e9f4b6SRandy Cushman if (ret1 < 0) 225167e9f4b6SRandy Cushman return ret1; 225267e9f4b6SRandy Cushman 225367e9f4b6SRandy Cushman return (ret0 > 0 || ret1 > 0) ? 1 : 0; 225467e9f4b6SRandy Cushman } 225567e9f4b6SRandy Cushman 225667e9f4b6SRandy Cushman static int snd_ac97_ad1986_miclisel_get(struct snd_kcontrol *kcontrol, 225767e9f4b6SRandy Cushman struct snd_ctl_elem_value *ucontrol) 225867e9f4b6SRandy Cushman { 225967e9f4b6SRandy Cushman struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 226067e9f4b6SRandy Cushman 226167e9f4b6SRandy Cushman ucontrol->value.integer.value[0] = ac97->spec.ad18xx.swap_mic_linein; 226267e9f4b6SRandy Cushman return 0; 226367e9f4b6SRandy Cushman } 226467e9f4b6SRandy Cushman 226567e9f4b6SRandy Cushman static int snd_ac97_ad1986_miclisel_put(struct snd_kcontrol *kcontrol, 226667e9f4b6SRandy Cushman struct snd_ctl_elem_value *ucontrol) 226767e9f4b6SRandy Cushman { 226867e9f4b6SRandy Cushman struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 226967e9f4b6SRandy Cushman unsigned char swap = ucontrol->value.integer.value[0] != 0; 227067e9f4b6SRandy Cushman 227167e9f4b6SRandy Cushman if (swap != ac97->spec.ad18xx.swap_mic_linein) { 227267e9f4b6SRandy Cushman ac97->spec.ad18xx.swap_mic_linein = swap; 227367e9f4b6SRandy Cushman if (ac97->build_ops->update_jacks) 227467e9f4b6SRandy Cushman ac97->build_ops->update_jacks(ac97); 227567e9f4b6SRandy Cushman return 1; 227667e9f4b6SRandy Cushman } 227767e9f4b6SRandy Cushman return 0; 227867e9f4b6SRandy Cushman } 227967e9f4b6SRandy Cushman 228067e9f4b6SRandy Cushman static int snd_ac97_ad1986_vrefout_get(struct snd_kcontrol *kcontrol, 228167e9f4b6SRandy Cushman struct snd_ctl_elem_value *ucontrol) 228267e9f4b6SRandy Cushman { 228367e9f4b6SRandy Cushman /* Use MIC_1/2 V_REFOUT as the "get" value */ 228467e9f4b6SRandy Cushman struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 228567e9f4b6SRandy Cushman unsigned short val; 228667e9f4b6SRandy Cushman unsigned short reg = ac97->regs[AC97_AD_MISC2]; 228767e9f4b6SRandy Cushman if ((reg & AC97_AD1986_MVREF0) != 0) 228867e9f4b6SRandy Cushman val = 2; 228967e9f4b6SRandy Cushman else if ((reg & AC97_AD1986_MVREF1) != 0) 229067e9f4b6SRandy Cushman val = 3; 229167e9f4b6SRandy Cushman else if ((reg & AC97_AD1986_MVREF2) != 0) 229267e9f4b6SRandy Cushman val = 1; 229367e9f4b6SRandy Cushman else 229467e9f4b6SRandy Cushman val = 0; 229567e9f4b6SRandy Cushman ucontrol->value.enumerated.item[0] = val; 229667e9f4b6SRandy Cushman return 0; 229767e9f4b6SRandy Cushman } 229867e9f4b6SRandy Cushman 229967e9f4b6SRandy Cushman static int snd_ac97_ad1986_vrefout_put(struct snd_kcontrol *kcontrol, 230067e9f4b6SRandy Cushman struct snd_ctl_elem_value *ucontrol) 230167e9f4b6SRandy Cushman { 230267e9f4b6SRandy Cushman struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 230367e9f4b6SRandy Cushman unsigned short cval; 230467e9f4b6SRandy Cushman unsigned short lval; 230567e9f4b6SRandy Cushman unsigned short mval; 230667e9f4b6SRandy Cushman int cret; 230767e9f4b6SRandy Cushman int lret; 230867e9f4b6SRandy Cushman int mret; 230967e9f4b6SRandy Cushman 231067e9f4b6SRandy Cushman switch (ucontrol->value.enumerated.item[0]) 231167e9f4b6SRandy Cushman { 231267e9f4b6SRandy Cushman case 0: /* High-Z */ 231367e9f4b6SRandy Cushman cval = 0; 231467e9f4b6SRandy Cushman lval = 0; 231567e9f4b6SRandy Cushman mval = 0; 231667e9f4b6SRandy Cushman break; 231767e9f4b6SRandy Cushman case 1: /* 3.7 V */ 231867e9f4b6SRandy Cushman cval = AC97_AD1986_CVREF2; 231967e9f4b6SRandy Cushman lval = AC97_AD1986_LVREF2; 232067e9f4b6SRandy Cushman mval = AC97_AD1986_MVREF2; 232167e9f4b6SRandy Cushman break; 232267e9f4b6SRandy Cushman case 2: /* 2.25 V */ 232367e9f4b6SRandy Cushman cval = AC97_AD1986_CVREF0; 232467e9f4b6SRandy Cushman lval = AC97_AD1986_LVREF0; 232567e9f4b6SRandy Cushman mval = AC97_AD1986_MVREF0; 232667e9f4b6SRandy Cushman break; 232767e9f4b6SRandy Cushman case 3: /* 0 V */ 232867e9f4b6SRandy Cushman cval = AC97_AD1986_CVREF1; 232967e9f4b6SRandy Cushman lval = AC97_AD1986_LVREF1; 233067e9f4b6SRandy Cushman mval = AC97_AD1986_MVREF1; 233167e9f4b6SRandy Cushman break; 233267e9f4b6SRandy Cushman default: 233367e9f4b6SRandy Cushman return -EINVAL; 233467e9f4b6SRandy Cushman } 233567e9f4b6SRandy Cushman 233667e9f4b6SRandy Cushman cret = snd_ac97_update_bits(ac97, AC97_AD_MISC2, 233767e9f4b6SRandy Cushman AC97_AD1986_CVREF_MASK, cval); 233867e9f4b6SRandy Cushman if (cret < 0) 233967e9f4b6SRandy Cushman return cret; 234067e9f4b6SRandy Cushman lret = snd_ac97_update_bits(ac97, AC97_AD_MISC3, 234167e9f4b6SRandy Cushman AC97_AD1986_LVREF_MASK, lval); 234267e9f4b6SRandy Cushman if (lret < 0) 234367e9f4b6SRandy Cushman return lret; 234467e9f4b6SRandy Cushman mret = snd_ac97_update_bits(ac97, AC97_AD_MISC2, 234567e9f4b6SRandy Cushman AC97_AD1986_MVREF_MASK, mval); 234667e9f4b6SRandy Cushman if (mret < 0) 234767e9f4b6SRandy Cushman return mret; 234867e9f4b6SRandy Cushman 234967e9f4b6SRandy Cushman return (cret > 0 || lret > 0 || mret > 0) ? 1 : 0; 235067e9f4b6SRandy Cushman } 235167e9f4b6SRandy Cushman 235267e9f4b6SRandy Cushman static const struct snd_kcontrol_new snd_ac97_ad1986_controls[] = { 235367e9f4b6SRandy Cushman AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0), 235467e9f4b6SRandy Cushman { 235567e9f4b6SRandy Cushman .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 235667e9f4b6SRandy Cushman .name = "Exchange Front/Surround", 235767e9f4b6SRandy Cushman .info = snd_ac97_ad1986_bool_info, 235867e9f4b6SRandy Cushman .get = snd_ac97_ad1986_lososel_get, 235967e9f4b6SRandy Cushman .put = snd_ac97_ad1986_lososel_put 236067e9f4b6SRandy Cushman }, 236167e9f4b6SRandy Cushman { 236267e9f4b6SRandy Cushman .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 236367e9f4b6SRandy Cushman .name = "Exchange Mic/Line In", 236467e9f4b6SRandy Cushman .info = snd_ac97_ad1986_bool_info, 236567e9f4b6SRandy Cushman .get = snd_ac97_ad1986_miclisel_get, 236667e9f4b6SRandy Cushman .put = snd_ac97_ad1986_miclisel_put 236767e9f4b6SRandy Cushman }, 236867e9f4b6SRandy Cushman { 236967e9f4b6SRandy Cushman .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 237067e9f4b6SRandy Cushman .name = "Spread Front to Surround and Center/LFE", 237167e9f4b6SRandy Cushman .info = snd_ac97_ad1986_bool_info, 237267e9f4b6SRandy Cushman .get = snd_ac97_ad1986_spread_get, 237367e9f4b6SRandy Cushman .put = snd_ac97_ad1986_spread_put 237467e9f4b6SRandy Cushman }, 237567e9f4b6SRandy Cushman { 237667e9f4b6SRandy Cushman .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 237767e9f4b6SRandy Cushman .name = "Downmix", 237867e9f4b6SRandy Cushman .info = snd_ac97_ad1888_downmix_info, 237967e9f4b6SRandy Cushman .get = snd_ac97_ad1888_downmix_get, 238067e9f4b6SRandy Cushman .put = snd_ac97_ad1888_downmix_put 238167e9f4b6SRandy Cushman }, 238267e9f4b6SRandy Cushman { 238367e9f4b6SRandy Cushman .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 238467e9f4b6SRandy Cushman .name = "V_REFOUT", 238567e9f4b6SRandy Cushman .info = snd_ac97_ad1985_vrefout_info, 238667e9f4b6SRandy Cushman .get = snd_ac97_ad1986_vrefout_get, 238767e9f4b6SRandy Cushman .put = snd_ac97_ad1986_vrefout_put 238867e9f4b6SRandy Cushman }, 238967e9f4b6SRandy Cushman AC97_SURROUND_JACK_MODE_CTL, 239067e9f4b6SRandy Cushman AC97_CHANNEL_MODE_CTL, 239167e9f4b6SRandy Cushman 239267e9f4b6SRandy Cushman AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0), 239367e9f4b6SRandy Cushman AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0) 239467e9f4b6SRandy Cushman }; 239567e9f4b6SRandy Cushman 239667e9f4b6SRandy Cushman static void ad1986_update_jacks(struct snd_ac97 *ac97) 239767e9f4b6SRandy Cushman { 239867e9f4b6SRandy Cushman unsigned short misc_val = 0; 239967e9f4b6SRandy Cushman unsigned short ser_val; 240067e9f4b6SRandy Cushman 240167e9f4b6SRandy Cushman /* disable SURROUND and CENTER/LFE if not surround mode */ 240267e9f4b6SRandy Cushman if (!is_surround_on(ac97)) 240367e9f4b6SRandy Cushman misc_val |= AC97_AD1986_SODIS; 240467e9f4b6SRandy Cushman if (!is_clfe_on(ac97)) 240567e9f4b6SRandy Cushman misc_val |= AC97_AD1986_CLDIS; 240667e9f4b6SRandy Cushman 240767e9f4b6SRandy Cushman /* select line input (default=LINE_IN, SURROUND or MIC_1/2) */ 240867e9f4b6SRandy Cushman if (is_shared_linein(ac97)) 240967e9f4b6SRandy Cushman misc_val |= AC97_AD1986_LISEL_SURR; 241067e9f4b6SRandy Cushman else if (ac97->spec.ad18xx.swap_mic_linein != 0) 241167e9f4b6SRandy Cushman misc_val |= AC97_AD1986_LISEL_MIC; 241267e9f4b6SRandy Cushman snd_ac97_update_bits(ac97, AC97_AD_MISC, 241367e9f4b6SRandy Cushman AC97_AD1986_SODIS | AC97_AD1986_CLDIS | 241467e9f4b6SRandy Cushman AC97_AD1986_LISEL_MASK, 241567e9f4b6SRandy Cushman misc_val); 241667e9f4b6SRandy Cushman 241767e9f4b6SRandy Cushman /* select microphone input (MIC_1/2, Center/LFE or LINE_IN) */ 241867e9f4b6SRandy Cushman if (is_shared_micin(ac97)) 241967e9f4b6SRandy Cushman ser_val = AC97_AD1986_OMS_C; 242067e9f4b6SRandy Cushman else if (ac97->spec.ad18xx.swap_mic_linein != 0) 242167e9f4b6SRandy Cushman ser_val = AC97_AD1986_OMS_L; 242267e9f4b6SRandy Cushman else 242367e9f4b6SRandy Cushman ser_val = AC97_AD1986_OMS_M; 242467e9f4b6SRandy Cushman snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 242567e9f4b6SRandy Cushman AC97_AD1986_OMS_MASK, 242667e9f4b6SRandy Cushman ser_val); 242767e9f4b6SRandy Cushman } 242867e9f4b6SRandy Cushman 242967e9f4b6SRandy Cushman static int patch_ad1986_specific(struct snd_ac97 *ac97) 243067e9f4b6SRandy Cushman { 243167e9f4b6SRandy Cushman int err; 243267e9f4b6SRandy Cushman 243367e9f4b6SRandy Cushman if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0) 243467e9f4b6SRandy Cushman return err; 243567e9f4b6SRandy Cushman 243667e9f4b6SRandy Cushman return patch_build_controls(ac97, snd_ac97_ad1986_controls, 243767e9f4b6SRandy Cushman ARRAY_SIZE(snd_ac97_ad1985_controls)); 243867e9f4b6SRandy Cushman } 243967e9f4b6SRandy Cushman 244067e9f4b6SRandy Cushman static struct snd_ac97_build_ops patch_ad1986_build_ops = { 244167e9f4b6SRandy Cushman .build_post_spdif = patch_ad198x_post_spdif, 244267e9f4b6SRandy Cushman .build_specific = patch_ad1986_specific, 244367e9f4b6SRandy Cushman #ifdef CONFIG_PM 244467e9f4b6SRandy Cushman .resume = ad18xx_resume, 244567e9f4b6SRandy Cushman #endif 244667e9f4b6SRandy Cushman .update_jacks = ad1986_update_jacks, 244767e9f4b6SRandy Cushman }; 244867e9f4b6SRandy Cushman 2449ac519028STakashi Iwai static int patch_ad1986(struct snd_ac97 * ac97) 245067e9f4b6SRandy Cushman { 245167e9f4b6SRandy Cushman patch_ad1881(ac97); 245267e9f4b6SRandy Cushman ac97->build_ops = &patch_ad1986_build_ops; 245367e9f4b6SRandy Cushman ac97->flags |= AC97_STEREO_MUTES; 245467e9f4b6SRandy Cushman 245567e9f4b6SRandy Cushman /* update current jack configuration */ 245667e9f4b6SRandy Cushman ad1986_update_jacks(ac97); 245767e9f4b6SRandy Cushman 245867e9f4b6SRandy Cushman return 0; 245967e9f4b6SRandy Cushman } 246067e9f4b6SRandy Cushman 246167e9f4b6SRandy Cushman 24621da177e4SLinus Torvalds /* 24631da177e4SLinus Torvalds * realtek ALC65x/850 codecs 24641da177e4SLinus Torvalds */ 2465ee42381eSTakashi Iwai static void alc650_update_jacks(struct snd_ac97 *ac97) 24661da177e4SLinus Torvalds { 2467eb8caf30STakashi Iwai int shared; 24681da177e4SLinus Torvalds 2469831466f4SRandy Cushman /* shared Line-In / Surround Out */ 2470831466f4SRandy Cushman shared = is_shared_surrout(ac97); 2471eb8caf30STakashi Iwai snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 9, 2472eb8caf30STakashi Iwai shared ? (1 << 9) : 0); 2473831466f4SRandy Cushman /* update shared Mic In / Center/LFE Out */ 2474831466f4SRandy Cushman shared = is_shared_clfeout(ac97); 24751da177e4SLinus Torvalds /* disable/enable vref */ 24761da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12, 2477eb8caf30STakashi Iwai shared ? (1 << 12) : 0); 24781da177e4SLinus Torvalds /* turn on/off center-on-mic */ 24791da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 10, 2480eb8caf30STakashi Iwai shared ? (1 << 10) : 0); 24811da177e4SLinus Torvalds /* GPIO0 high for mic */ 24821da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_ALC650_GPIO_STATUS, 0x100, 2483eb8caf30STakashi Iwai shared ? 0 : 0x100); 24841da177e4SLinus Torvalds } 24851da177e4SLinus Torvalds 2486ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_alc650[] = { 24871da177e4SLinus Torvalds AC97_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0), 24881da177e4SLinus Torvalds AC97_SINGLE("Surround Down Mix", AC97_ALC650_MULTICH, 1, 1, 0), 24891da177e4SLinus Torvalds AC97_SINGLE("Center/LFE Down Mix", AC97_ALC650_MULTICH, 2, 1, 0), 24901da177e4SLinus Torvalds AC97_SINGLE("Exchange Center/LFE", AC97_ALC650_MULTICH, 3, 1, 0), 24911da177e4SLinus Torvalds /* 4: Analog Input To Surround */ 24921da177e4SLinus Torvalds /* 5: Analog Input To Center/LFE */ 24931da177e4SLinus Torvalds /* 6: Independent Master Volume Right */ 24941da177e4SLinus Torvalds /* 7: Independent Master Volume Left */ 24951da177e4SLinus Torvalds /* 8: reserved */ 2496eb8caf30STakashi Iwai /* 9: Line-In/Surround share */ 2497eb8caf30STakashi Iwai /* 10: Mic/CLFE share */ 24981da177e4SLinus Torvalds /* 11-13: in IEC958 controls */ 24991da177e4SLinus Torvalds AC97_SINGLE("Swap Surround Slot", AC97_ALC650_MULTICH, 14, 1, 0), 25001da177e4SLinus Torvalds #if 0 /* always set in patch_alc650 */ 25011da177e4SLinus Torvalds AC97_SINGLE("IEC958 Input Clock Enable", AC97_ALC650_CLOCK, 0, 1, 0), 25021da177e4SLinus Torvalds AC97_SINGLE("IEC958 Input Pin Enable", AC97_ALC650_CLOCK, 1, 1, 0), 25031da177e4SLinus Torvalds AC97_SINGLE("Surround DAC Switch", AC97_ALC650_SURR_DAC_VOL, 15, 1, 1), 25041da177e4SLinus Torvalds AC97_DOUBLE("Surround DAC Volume", AC97_ALC650_SURR_DAC_VOL, 8, 0, 31, 1), 25051da177e4SLinus Torvalds AC97_SINGLE("Center/LFE DAC Switch", AC97_ALC650_LFE_DAC_VOL, 15, 1, 1), 25061da177e4SLinus Torvalds AC97_DOUBLE("Center/LFE DAC Volume", AC97_ALC650_LFE_DAC_VOL, 8, 0, 31, 1), 25071da177e4SLinus Torvalds #endif 2508eb8caf30STakashi Iwai AC97_SURROUND_JACK_MODE_CTL, 2509eb8caf30STakashi Iwai AC97_CHANNEL_MODE_CTL, 25101da177e4SLinus Torvalds }; 25111da177e4SLinus Torvalds 2512ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc650[] = { 251310e8d78aSClemens Ladisch AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0), 25141da177e4SLinus Torvalds AC97_SINGLE("Analog to IEC958 Output", AC97_ALC650_MULTICH, 12, 1, 0), 25151da177e4SLinus Torvalds /* disable this controls since it doesn't work as expected */ 25161da177e4SLinus Torvalds /* AC97_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 13, 1, 0), */ 25171da177e4SLinus Torvalds }; 25181da177e4SLinus Torvalds 25190cb29ea0STakashi Iwai static const DECLARE_TLV_DB_SCALE(db_scale_5bit_3db_max, -4350, 150, 0); 25202f3482fbSTakashi Iwai 2521ee42381eSTakashi Iwai static int patch_alc650_specific(struct snd_ac97 * ac97) 25221da177e4SLinus Torvalds { 25231da177e4SLinus Torvalds int err; 25241da177e4SLinus Torvalds 25251da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, snd_ac97_controls_alc650, ARRAY_SIZE(snd_ac97_controls_alc650))) < 0) 25261da177e4SLinus Torvalds return err; 25271da177e4SLinus Torvalds if (ac97->ext_id & AC97_EI_SPDIF) { 25281da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc650, ARRAY_SIZE(snd_ac97_spdif_controls_alc650))) < 0) 25291da177e4SLinus Torvalds return err; 25301da177e4SLinus Torvalds } 25312f3482fbSTakashi Iwai if (ac97->id != AC97_ID_ALC650F) 25322f3482fbSTakashi Iwai reset_tlv(ac97, "Master Playback Volume", 25332f3482fbSTakashi Iwai db_scale_5bit_3db_max); 25341da177e4SLinus Torvalds return 0; 25351da177e4SLinus Torvalds } 25361da177e4SLinus Torvalds 25371da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_alc650_ops = { 2538eb8caf30STakashi Iwai .build_specific = patch_alc650_specific, 2539eb8caf30STakashi Iwai .update_jacks = alc650_update_jacks 25401da177e4SLinus Torvalds }; 25411da177e4SLinus Torvalds 2542ac519028STakashi Iwai static int patch_alc650(struct snd_ac97 * ac97) 25431da177e4SLinus Torvalds { 25441da177e4SLinus Torvalds unsigned short val; 25451da177e4SLinus Torvalds 25461da177e4SLinus Torvalds ac97->build_ops = &patch_alc650_ops; 25471da177e4SLinus Torvalds 25481da177e4SLinus Torvalds /* determine the revision */ 25491da177e4SLinus Torvalds val = snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f; 25501da177e4SLinus Torvalds if (val < 3) 25511da177e4SLinus Torvalds ac97->id = 0x414c4720; /* Old version */ 25521da177e4SLinus Torvalds else if (val < 0x10) 25531da177e4SLinus Torvalds ac97->id = 0x414c4721; /* D version */ 25541da177e4SLinus Torvalds else if (val < 0x20) 25551da177e4SLinus Torvalds ac97->id = 0x414c4722; /* E version */ 25561da177e4SLinus Torvalds else if (val < 0x30) 25571da177e4SLinus Torvalds ac97->id = 0x414c4723; /* F version */ 25581da177e4SLinus Torvalds 25591da177e4SLinus Torvalds /* revision E or F */ 25601da177e4SLinus Torvalds /* FIXME: what about revision D ? */ 25611da177e4SLinus Torvalds ac97->spec.dev_flags = (ac97->id == 0x414c4722 || 25621da177e4SLinus Torvalds ac97->id == 0x414c4723); 25631da177e4SLinus Torvalds 25641da177e4SLinus Torvalds /* enable AC97_ALC650_GPIO_SETUP, AC97_ALC650_CLOCK for R/W */ 25651da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS, 25661da177e4SLinus Torvalds snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x8000); 25671da177e4SLinus Torvalds 25681da177e4SLinus Torvalds /* Enable SPDIF-IN only on Rev.E and above */ 25691da177e4SLinus Torvalds val = snd_ac97_read(ac97, AC97_ALC650_CLOCK); 25701da177e4SLinus Torvalds /* SPDIF IN with pin 47 */ 2571eed65649STakashi Iwai if (ac97->spec.dev_flags && 2572eed65649STakashi Iwai /* ASUS A6KM requires EAPD */ 2573eed65649STakashi Iwai ! (ac97->subsystem_vendor == 0x1043 && 2574eed65649STakashi Iwai ac97->subsystem_device == 0x1103)) 25751da177e4SLinus Torvalds val |= 0x03; /* enable */ 25761da177e4SLinus Torvalds else 25771da177e4SLinus Torvalds val &= ~0x03; /* disable */ 25781da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_CLOCK, val); 25791da177e4SLinus Torvalds 25801da177e4SLinus Torvalds /* set default: slot 3,4,7,8,6,9 25811da177e4SLinus Torvalds spdif-in monitor off, analog-spdif off, spdif-in off 25821da177e4SLinus Torvalds center on mic off, surround on line-in off 25831da177e4SLinus Torvalds downmix off, duplicate front off 25841da177e4SLinus Torvalds */ 25851da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 0); 25861da177e4SLinus Torvalds 25871da177e4SLinus Torvalds /* set GPIO0 for mic bias */ 25881da177e4SLinus Torvalds /* GPIO0 pin output, no interrupt, high */ 25891da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_SETUP, 25901da177e4SLinus Torvalds snd_ac97_read(ac97, AC97_ALC650_GPIO_SETUP) | 0x01); 25911da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS, 25921da177e4SLinus Torvalds (snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x100) & ~0x10); 25931da177e4SLinus Torvalds 25941da177e4SLinus Torvalds /* full DAC volume */ 25951da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808); 25961da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808); 25971da177e4SLinus Torvalds return 0; 25981da177e4SLinus Torvalds } 25991da177e4SLinus Torvalds 2600ee42381eSTakashi Iwai static void alc655_update_jacks(struct snd_ac97 *ac97) 26011da177e4SLinus Torvalds { 2602eb8caf30STakashi Iwai int shared; 26031da177e4SLinus Torvalds 2604831466f4SRandy Cushman /* shared Line-In / Surround Out */ 2605831466f4SRandy Cushman shared = is_shared_surrout(ac97); 2606eb8caf30STakashi Iwai ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 9, 2607eb8caf30STakashi Iwai shared ? (1 << 9) : 0, 0); 2608831466f4SRandy Cushman /* update shared Mic In / Center/LFE Out */ 2609831466f4SRandy Cushman shared = is_shared_clfeout(ac97); 26101da177e4SLinus Torvalds /* misc control; vrefout disable */ 26111da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12, 2612eb8caf30STakashi Iwai shared ? (1 << 12) : 0); 2613eb8caf30STakashi Iwai ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 10, 2614eb8caf30STakashi Iwai shared ? (1 << 10) : 0, 0); 26151da177e4SLinus Torvalds } 26161da177e4SLinus Torvalds 2617ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_alc655[] = { 26181da177e4SLinus Torvalds AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0), 2619eb8caf30STakashi Iwai AC97_SURROUND_JACK_MODE_CTL, 2620eb8caf30STakashi Iwai AC97_CHANNEL_MODE_CTL, 26211da177e4SLinus Torvalds }; 26221da177e4SLinus Torvalds 2623ee42381eSTakashi Iwai static int alc655_iec958_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 26241da177e4SLinus Torvalds { 26251da177e4SLinus Torvalds static char *texts_655[3] = { "PCM", "Analog In", "IEC958 In" }; 26261da177e4SLinus Torvalds static char *texts_658[4] = { "PCM", "Analog1 In", "Analog2 In", "IEC958 In" }; 2627ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 26281da177e4SLinus Torvalds 26291da177e4SLinus Torvalds uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 26301da177e4SLinus Torvalds uinfo->count = 1; 26311da177e4SLinus Torvalds uinfo->value.enumerated.items = ac97->spec.dev_flags ? 4 : 3; 26321da177e4SLinus Torvalds if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 26331da177e4SLinus Torvalds uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 26341da177e4SLinus Torvalds strcpy(uinfo->value.enumerated.name, 26351da177e4SLinus Torvalds ac97->spec.dev_flags ? 26361da177e4SLinus Torvalds texts_658[uinfo->value.enumerated.item] : 26371da177e4SLinus Torvalds texts_655[uinfo->value.enumerated.item]); 26381da177e4SLinus Torvalds return 0; 26391da177e4SLinus Torvalds } 26401da177e4SLinus Torvalds 2641ee42381eSTakashi Iwai static int alc655_iec958_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 26421da177e4SLinus Torvalds { 2643ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 26441da177e4SLinus Torvalds unsigned short val; 26451da177e4SLinus Torvalds 26461da177e4SLinus Torvalds val = ac97->regs[AC97_ALC650_MULTICH]; 26471da177e4SLinus Torvalds val = (val >> 12) & 3; 26481da177e4SLinus Torvalds if (ac97->spec.dev_flags && val == 3) 26491da177e4SLinus Torvalds val = 0; 26501da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = val; 26511da177e4SLinus Torvalds return 0; 26521da177e4SLinus Torvalds } 26531da177e4SLinus Torvalds 2654ee42381eSTakashi Iwai static int alc655_iec958_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 26551da177e4SLinus Torvalds { 2656ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 26571da177e4SLinus Torvalds 26581da177e4SLinus Torvalds return ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 3 << 12, 26591da177e4SLinus Torvalds (unsigned short)ucontrol->value.enumerated.item[0] << 12, 26601da177e4SLinus Torvalds 0); 26611da177e4SLinus Torvalds } 26621da177e4SLinus Torvalds 2663ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc655[] = { 266410e8d78aSClemens Ladisch AC97_PAGE_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0, 0), 26651da177e4SLinus Torvalds /* disable this controls since it doesn't work as expected */ 26661da177e4SLinus Torvalds /* AC97_PAGE_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 14, 1, 0, 0), */ 26671da177e4SLinus Torvalds { 26681da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2669031c95d4STakashi Iwai .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source", 26701da177e4SLinus Torvalds .info = alc655_iec958_route_info, 26711da177e4SLinus Torvalds .get = alc655_iec958_route_get, 26721da177e4SLinus Torvalds .put = alc655_iec958_route_put, 26731da177e4SLinus Torvalds }, 26741da177e4SLinus Torvalds }; 26751da177e4SLinus Torvalds 2676ee42381eSTakashi Iwai static int patch_alc655_specific(struct snd_ac97 * ac97) 26771da177e4SLinus Torvalds { 26781da177e4SLinus Torvalds int err; 26791da177e4SLinus Torvalds 26801da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, snd_ac97_controls_alc655, ARRAY_SIZE(snd_ac97_controls_alc655))) < 0) 26811da177e4SLinus Torvalds return err; 26821da177e4SLinus Torvalds if (ac97->ext_id & AC97_EI_SPDIF) { 26831da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0) 26841da177e4SLinus Torvalds return err; 26851da177e4SLinus Torvalds } 26861da177e4SLinus Torvalds return 0; 26871da177e4SLinus Torvalds } 26881da177e4SLinus Torvalds 26891da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_alc655_ops = { 2690eb8caf30STakashi Iwai .build_specific = patch_alc655_specific, 2691eb8caf30STakashi Iwai .update_jacks = alc655_update_jacks 26921da177e4SLinus Torvalds }; 26931da177e4SLinus Torvalds 2694ac519028STakashi Iwai static int patch_alc655(struct snd_ac97 * ac97) 26951da177e4SLinus Torvalds { 26961da177e4SLinus Torvalds unsigned int val; 26971da177e4SLinus Torvalds 2698a5022b0dSTakashi Iwai if (ac97->id == AC97_ID_ALC658) { 2699a5022b0dSTakashi Iwai ac97->spec.dev_flags = 1; /* ALC658 */ 2700a5022b0dSTakashi Iwai if ((snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f) == 2) { 2701a5022b0dSTakashi Iwai ac97->id = AC97_ID_ALC658D; 2702a5022b0dSTakashi Iwai ac97->spec.dev_flags = 2; 2703a5022b0dSTakashi Iwai } 2704a5022b0dSTakashi Iwai } 27051da177e4SLinus Torvalds 27061da177e4SLinus Torvalds ac97->build_ops = &patch_alc655_ops; 27071da177e4SLinus Torvalds 27081da177e4SLinus Torvalds /* assume only page 0 for writing cache */ 27091da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR); 27101da177e4SLinus Torvalds 27111da177e4SLinus Torvalds /* adjust default values */ 27121da177e4SLinus Torvalds val = snd_ac97_read(ac97, 0x7a); /* misc control */ 2713a5022b0dSTakashi Iwai if (ac97->spec.dev_flags) /* ALC658 */ 27141da177e4SLinus Torvalds val &= ~(1 << 1); /* Pin 47 is spdif input pin */ 2715ee71508eSTakashi Iwai else { /* ALC655 */ 2716ee71508eSTakashi Iwai if (ac97->subsystem_vendor == 0x1462 && 2717d244bf89SMagnus Sandin (ac97->subsystem_device == 0x0131 || /* MSI S270 laptop */ 2718e7d24f0bSJaroslav Kysela ac97->subsystem_device == 0x0161 || /* LG K1 Express */ 2719cbcc2c4cSJerome Demange ac97->subsystem_device == 0x0351 || /* MSI L725 laptop */ 2720592a82e8STakashi Iwai ac97->subsystem_device == 0x0471 || /* MSI L720 laptop */ 2721cbcc2c4cSJerome Demange ac97->subsystem_device == 0x0061)) /* MSI S250 laptop */ 2722ee71508eSTakashi Iwai val &= ~(1 << 1); /* Pin 47 is EAPD (for internal speaker) */ 2723ee71508eSTakashi Iwai else 27241da177e4SLinus Torvalds val |= (1 << 1); /* Pin 47 is spdif input pin */ 2725ee71508eSTakashi Iwai } 27261da177e4SLinus Torvalds val &= ~(1 << 12); /* vref enable */ 27271da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x7a, val); 27281da177e4SLinus Torvalds /* set default: spdif-in enabled, 27291da177e4SLinus Torvalds spdif-in monitor off, spdif-in PCM off 27301da177e4SLinus Torvalds center on mic off, surround on line-in off 27311da177e4SLinus Torvalds duplicate front off 27321da177e4SLinus Torvalds */ 27331da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15); 27341da177e4SLinus Torvalds 27351da177e4SLinus Torvalds /* full DAC volume */ 27361da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808); 27371da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808); 2738a5022b0dSTakashi Iwai 2739a5022b0dSTakashi Iwai /* update undocumented bit... */ 2740a5022b0dSTakashi Iwai if (ac97->id == AC97_ID_ALC658D) 2741a5022b0dSTakashi Iwai snd_ac97_update_bits(ac97, 0x74, 0x0800, 0x0800); 2742a5022b0dSTakashi Iwai 27431da177e4SLinus Torvalds return 0; 27441da177e4SLinus Torvalds } 27451da177e4SLinus Torvalds 27461da177e4SLinus Torvalds 27471da177e4SLinus Torvalds #define AC97_ALC850_JACK_SELECT 0x76 27481da177e4SLinus Torvalds #define AC97_ALC850_MISC1 0x7a 27491da177e4SLinus Torvalds 2750ee42381eSTakashi Iwai static void alc850_update_jacks(struct snd_ac97 *ac97) 27511da177e4SLinus Torvalds { 2752eb8caf30STakashi Iwai int shared; 27531da177e4SLinus Torvalds 2754831466f4SRandy Cushman /* shared Line-In / Surround Out */ 2755831466f4SRandy Cushman shared = is_shared_surrout(ac97); 27561da177e4SLinus Torvalds /* SURR 1kOhm (bit4), Amp (bit5) */ 27571da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<4)|(1<<5), 2758eb8caf30STakashi Iwai shared ? (1<<5) : (1<<4)); 27591da177e4SLinus Torvalds /* LINE-IN = 0, SURROUND = 2 */ 2760eb8caf30STakashi Iwai snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 12, 2761eb8caf30STakashi Iwai shared ? (2<<12) : (0<<12)); 2762831466f4SRandy Cushman /* update shared Mic In / Center/LFE Out */ 2763831466f4SRandy Cushman shared = is_shared_clfeout(ac97); 27641da177e4SLinus Torvalds /* Vref disable (bit12), 1kOhm (bit13) */ 27651da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<12)|(1<<13), 2766eb8caf30STakashi Iwai shared ? (1<<12) : (1<<13)); 2767da79e44dSTakashi Iwai /* MIC-IN = 1, CENTER-LFE = 5 */ 2768eb8caf30STakashi Iwai snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 4, 2769da79e44dSTakashi Iwai shared ? (5<<4) : (1<<4)); 27701da177e4SLinus Torvalds } 27711da177e4SLinus Torvalds 2772ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_alc850[] = { 27731da177e4SLinus Torvalds AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0), 277467e1b51eSSergey Vlasov AC97_SINGLE("Mic Front Input Switch", AC97_ALC850_JACK_SELECT, 15, 1, 1), 2775eb8caf30STakashi Iwai AC97_SURROUND_JACK_MODE_CTL, 2776eb8caf30STakashi Iwai AC97_CHANNEL_MODE_CTL, 27771da177e4SLinus Torvalds }; 27781da177e4SLinus Torvalds 2779ee42381eSTakashi Iwai static int patch_alc850_specific(struct snd_ac97 *ac97) 27801da177e4SLinus Torvalds { 27811da177e4SLinus Torvalds int err; 27821da177e4SLinus Torvalds 27831da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, snd_ac97_controls_alc850, ARRAY_SIZE(snd_ac97_controls_alc850))) < 0) 27841da177e4SLinus Torvalds return err; 27851da177e4SLinus Torvalds if (ac97->ext_id & AC97_EI_SPDIF) { 27861da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0) 27871da177e4SLinus Torvalds return err; 27881da177e4SLinus Torvalds } 27891da177e4SLinus Torvalds return 0; 27901da177e4SLinus Torvalds } 27911da177e4SLinus Torvalds 27921da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_alc850_ops = { 2793eb8caf30STakashi Iwai .build_specific = patch_alc850_specific, 2794eb8caf30STakashi Iwai .update_jacks = alc850_update_jacks 27951da177e4SLinus Torvalds }; 27961da177e4SLinus Torvalds 2797ac519028STakashi Iwai static int patch_alc850(struct snd_ac97 *ac97) 27981da177e4SLinus Torvalds { 27991da177e4SLinus Torvalds ac97->build_ops = &patch_alc850_ops; 28001da177e4SLinus Torvalds 28011da177e4SLinus Torvalds ac97->spec.dev_flags = 0; /* for IEC958 playback route - ALC655 compatible */ 28021da177e4SLinus Torvalds 28031da177e4SLinus Torvalds /* assume only page 0 for writing cache */ 28041da177e4SLinus Torvalds snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR); 28051da177e4SLinus Torvalds 28061da177e4SLinus Torvalds /* adjust default values */ 28071da177e4SLinus Torvalds /* set default: spdif-in enabled, 28081da177e4SLinus Torvalds spdif-in monitor off, spdif-in PCM off 28091da177e4SLinus Torvalds center on mic off, surround on line-in off 28101da177e4SLinus Torvalds duplicate front off 28111da177e4SLinus Torvalds */ 28121da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15); 28131da177e4SLinus Torvalds /* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off 28141da177e4SLinus Torvalds * Front Amp: on, Vref: enable, Center 1kOhm: on, Mix: on 28151da177e4SLinus Torvalds */ 28161da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x7a, (1<<1)|(1<<4)|(0<<5)|(1<<6)| 28171da177e4SLinus Torvalds (1<<7)|(0<<12)|(1<<13)|(0<<14)); 28181da177e4SLinus Torvalds /* detection UIO2,3: all path floating, UIO3: MIC, Vref2: disable, 28191da177e4SLinus Torvalds * UIO1: FRONT, Vref3: disable, UIO3: LINE, Front-Mic: mute 28201da177e4SLinus Torvalds */ 28211da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x76, (0<<0)|(0<<2)|(1<<4)|(1<<7)|(2<<8)| 28221da177e4SLinus Torvalds (1<<11)|(0<<12)|(1<<15)); 28231da177e4SLinus Torvalds 28241da177e4SLinus Torvalds /* full DAC volume */ 28251da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808); 28261da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808); 28271da177e4SLinus Torvalds return 0; 28281da177e4SLinus Torvalds } 28291da177e4SLinus Torvalds 28301da177e4SLinus Torvalds 28311da177e4SLinus Torvalds /* 28321da177e4SLinus Torvalds * C-Media CM97xx codecs 28331da177e4SLinus Torvalds */ 2834ee42381eSTakashi Iwai static void cm9738_update_jacks(struct snd_ac97 *ac97) 2835eb8caf30STakashi Iwai { 2836831466f4SRandy Cushman /* shared Line-In / Surround Out */ 2837eb8caf30STakashi Iwai snd_ac97_update_bits(ac97, AC97_CM9738_VENDOR_CTRL, 1 << 10, 2838831466f4SRandy Cushman is_shared_surrout(ac97) ? (1 << 10) : 0); 2839eb8caf30STakashi Iwai } 2840eb8caf30STakashi Iwai 2841ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_cm9738_controls[] = { 28421da177e4SLinus Torvalds AC97_SINGLE("Duplicate Front", AC97_CM9738_VENDOR_CTRL, 13, 1, 0), 2843eb8caf30STakashi Iwai AC97_SURROUND_JACK_MODE_CTL, 2844eb8caf30STakashi Iwai AC97_CHANNEL_MODE_4CH_CTL, 28451da177e4SLinus Torvalds }; 28461da177e4SLinus Torvalds 2847ee42381eSTakashi Iwai static int patch_cm9738_specific(struct snd_ac97 * ac97) 28481da177e4SLinus Torvalds { 28491da177e4SLinus Torvalds return patch_build_controls(ac97, snd_ac97_cm9738_controls, ARRAY_SIZE(snd_ac97_cm9738_controls)); 28501da177e4SLinus Torvalds } 28511da177e4SLinus Torvalds 28521da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_cm9738_ops = { 2853eb8caf30STakashi Iwai .build_specific = patch_cm9738_specific, 2854eb8caf30STakashi Iwai .update_jacks = cm9738_update_jacks 28551da177e4SLinus Torvalds }; 28561da177e4SLinus Torvalds 2857ac519028STakashi Iwai static int patch_cm9738(struct snd_ac97 * ac97) 28581da177e4SLinus Torvalds { 28591da177e4SLinus Torvalds ac97->build_ops = &patch_cm9738_ops; 28601da177e4SLinus Torvalds /* FIXME: can anyone confirm below? */ 28611da177e4SLinus Torvalds /* CM9738 has no PCM volume although the register reacts */ 28621da177e4SLinus Torvalds ac97->flags |= AC97_HAS_NO_PCM_VOL; 28631da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_PCM, 0x8000); 28641da177e4SLinus Torvalds 28651da177e4SLinus Torvalds return 0; 28661da177e4SLinus Torvalds } 28671da177e4SLinus Torvalds 2868ee42381eSTakashi Iwai static int snd_ac97_cmedia_spdif_playback_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 28691da177e4SLinus Torvalds { 28701da177e4SLinus Torvalds static char *texts[] = { "Analog", "Digital" }; 28711da177e4SLinus Torvalds 28721da177e4SLinus Torvalds uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 28731da177e4SLinus Torvalds uinfo->count = 1; 28741da177e4SLinus Torvalds uinfo->value.enumerated.items = 2; 28751da177e4SLinus Torvalds if (uinfo->value.enumerated.item > 1) 28761da177e4SLinus Torvalds uinfo->value.enumerated.item = 1; 28771da177e4SLinus Torvalds strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 28781da177e4SLinus Torvalds return 0; 28791da177e4SLinus Torvalds } 28801da177e4SLinus Torvalds 2881ee42381eSTakashi Iwai static int snd_ac97_cmedia_spdif_playback_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 28821da177e4SLinus Torvalds { 2883ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 28841da177e4SLinus Torvalds unsigned short val; 28851da177e4SLinus Torvalds 28861da177e4SLinus Torvalds val = ac97->regs[AC97_CM9739_SPDIF_CTRL]; 28871da177e4SLinus Torvalds ucontrol->value.enumerated.item[0] = (val >> 1) & 0x01; 28881da177e4SLinus Torvalds return 0; 28891da177e4SLinus Torvalds } 28901da177e4SLinus Torvalds 2891ee42381eSTakashi Iwai static int snd_ac97_cmedia_spdif_playback_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 28921da177e4SLinus Torvalds { 2893ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 28941da177e4SLinus Torvalds 28951da177e4SLinus Torvalds return snd_ac97_update_bits(ac97, AC97_CM9739_SPDIF_CTRL, 28961da177e4SLinus Torvalds 0x01 << 1, 28971da177e4SLinus Torvalds (ucontrol->value.enumerated.item[0] & 0x01) << 1); 28981da177e4SLinus Torvalds } 28991da177e4SLinus Torvalds 2900ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_cm9739_controls_spdif[] = { 29011da177e4SLinus Torvalds /* BIT 0: SPDI_EN - always true */ 29021da177e4SLinus Torvalds { /* BIT 1: SPDIFS */ 29031da177e4SLinus Torvalds .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 29041da177e4SLinus Torvalds .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source", 29051da177e4SLinus Torvalds .info = snd_ac97_cmedia_spdif_playback_source_info, 29061da177e4SLinus Torvalds .get = snd_ac97_cmedia_spdif_playback_source_get, 29071da177e4SLinus Torvalds .put = snd_ac97_cmedia_spdif_playback_source_put, 29081da177e4SLinus Torvalds }, 29091da177e4SLinus Torvalds /* BIT 2: IG_SPIV */ 29101da177e4SLinus Torvalds AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9739_SPDIF_CTRL, 2, 1, 0), 29111da177e4SLinus Torvalds /* BIT 3: SPI2F */ 29121da177e4SLinus Torvalds AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9739_SPDIF_CTRL, 3, 1, 0), 29131da177e4SLinus Torvalds /* BIT 4: SPI2SDI */ 29141da177e4SLinus Torvalds AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9739_SPDIF_CTRL, 4, 1, 0), 29151da177e4SLinus Torvalds /* BIT 8: SPD32 - 32bit SPDIF - not supported yet */ 29161da177e4SLinus Torvalds }; 29171da177e4SLinus Torvalds 2918ee42381eSTakashi Iwai static void cm9739_update_jacks(struct snd_ac97 *ac97) 29191da177e4SLinus Torvalds { 2920831466f4SRandy Cushman /* shared Line-In / Surround Out */ 2921eb8caf30STakashi Iwai snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 1 << 10, 2922831466f4SRandy Cushman is_shared_surrout(ac97) ? (1 << 10) : 0); 2923831466f4SRandy Cushman /* shared Mic In / Center/LFE Out **/ 2924eb8caf30STakashi Iwai snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 0x3000, 2925831466f4SRandy Cushman is_shared_clfeout(ac97) ? 0x1000 : 0x2000); 29261da177e4SLinus Torvalds } 29271da177e4SLinus Torvalds 2928ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_cm9739_controls[] = { 2929eb8caf30STakashi Iwai AC97_SURROUND_JACK_MODE_CTL, 2930eb8caf30STakashi Iwai AC97_CHANNEL_MODE_CTL, 29311da177e4SLinus Torvalds }; 29321da177e4SLinus Torvalds 2933ee42381eSTakashi Iwai static int patch_cm9739_specific(struct snd_ac97 * ac97) 29341da177e4SLinus Torvalds { 29351da177e4SLinus Torvalds return patch_build_controls(ac97, snd_ac97_cm9739_controls, ARRAY_SIZE(snd_ac97_cm9739_controls)); 29361da177e4SLinus Torvalds } 29371da177e4SLinus Torvalds 2938ee42381eSTakashi Iwai static int patch_cm9739_post_spdif(struct snd_ac97 * ac97) 29391da177e4SLinus Torvalds { 29401da177e4SLinus Torvalds return patch_build_controls(ac97, snd_ac97_cm9739_controls_spdif, ARRAY_SIZE(snd_ac97_cm9739_controls_spdif)); 29411da177e4SLinus Torvalds } 29421da177e4SLinus Torvalds 29431da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_cm9739_ops = { 29441da177e4SLinus Torvalds .build_specific = patch_cm9739_specific, 2945eb8caf30STakashi Iwai .build_post_spdif = patch_cm9739_post_spdif, 2946eb8caf30STakashi Iwai .update_jacks = cm9739_update_jacks 29471da177e4SLinus Torvalds }; 29481da177e4SLinus Torvalds 2949ac519028STakashi Iwai static int patch_cm9739(struct snd_ac97 * ac97) 29501da177e4SLinus Torvalds { 29511da177e4SLinus Torvalds unsigned short val; 29521da177e4SLinus Torvalds 29531da177e4SLinus Torvalds ac97->build_ops = &patch_cm9739_ops; 29541da177e4SLinus Torvalds 29551da177e4SLinus Torvalds /* CM9739/A has no Master and PCM volume although the register reacts */ 29561da177e4SLinus Torvalds ac97->flags |= AC97_HAS_NO_MASTER_VOL | AC97_HAS_NO_PCM_VOL; 29571da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_MASTER, 0x8000); 29581da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_PCM, 0x8000); 29591da177e4SLinus Torvalds 29601da177e4SLinus Torvalds /* check spdif */ 29611da177e4SLinus Torvalds val = snd_ac97_read(ac97, AC97_EXTENDED_STATUS); 29621da177e4SLinus Torvalds if (val & AC97_EA_SPCV) { 29631da177e4SLinus Torvalds /* enable spdif in */ 29641da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL, 29651da177e4SLinus Torvalds snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) | 0x01); 29661da177e4SLinus Torvalds ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */ 29671da177e4SLinus Torvalds } else { 29681da177e4SLinus Torvalds ac97->ext_id &= ~AC97_EI_SPDIF; /* disable extended-id */ 29691da177e4SLinus Torvalds ac97->rates[AC97_RATES_SPDIF] = 0; 29701da177e4SLinus Torvalds } 29711da177e4SLinus Torvalds 29721da177e4SLinus Torvalds /* set-up multi channel */ 29731da177e4SLinus Torvalds /* bit 14: 0 = SPDIF, 1 = EAPD */ 29741da177e4SLinus Torvalds /* bit 13: enable internal vref output for mic */ 29751da177e4SLinus Torvalds /* bit 12: disable center/lfe (swithable) */ 29761da177e4SLinus Torvalds /* bit 10: disable surround/line (switchable) */ 29771da177e4SLinus Torvalds /* bit 9: mix 2 surround off */ 29781da177e4SLinus Torvalds /* bit 4: undocumented; 0 mutes the CM9739A, which defaults to 1 */ 29791da177e4SLinus Torvalds /* bit 3: undocumented; surround? */ 29801da177e4SLinus Torvalds /* bit 0: dB */ 29811da177e4SLinus Torvalds val = snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) & (1 << 4); 29821da177e4SLinus Torvalds val |= (1 << 3); 29831da177e4SLinus Torvalds val |= (1 << 13); 29841da177e4SLinus Torvalds if (! (ac97->ext_id & AC97_EI_SPDIF)) 29851da177e4SLinus Torvalds val |= (1 << 14); 29861da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, val); 29871da177e4SLinus Torvalds 29881da177e4SLinus Torvalds /* FIXME: set up GPIO */ 29891da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x70, 0x0100); 29901da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x72, 0x0020); 29911da177e4SLinus Torvalds /* Special exception for ASUS W1000/CMI9739. It does not have an SPDIF in. */ 29921da177e4SLinus Torvalds if (ac97->pci && 29931da177e4SLinus Torvalds ac97->subsystem_vendor == 0x1043 && 29941da177e4SLinus Torvalds ac97->subsystem_device == 0x1843) { 29951da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL, 29961da177e4SLinus Torvalds snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) & ~0x01); 29971da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, 29981da177e4SLinus Torvalds snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) | (1 << 14)); 29991da177e4SLinus Torvalds } 30001da177e4SLinus Torvalds 30011da177e4SLinus Torvalds return 0; 30021da177e4SLinus Torvalds } 30031da177e4SLinus Torvalds 30041da177e4SLinus Torvalds #define AC97_CM9761_MULTI_CHAN 0x64 30055f0dccf8STakashi Iwai #define AC97_CM9761_FUNC 0x66 30061da177e4SLinus Torvalds #define AC97_CM9761_SPDIF_CTRL 0x6c 30071da177e4SLinus Torvalds 3008ee42381eSTakashi Iwai static void cm9761_update_jacks(struct snd_ac97 *ac97) 30091da177e4SLinus Torvalds { 30104525c9f3STakashi Iwai /* FIXME: check the bits for each model 30114525c9f3STakashi Iwai * model 83 is confirmed to work 30124525c9f3STakashi Iwai */ 30134525c9f3STakashi Iwai static unsigned short surr_on[3][2] = { 30144525c9f3STakashi Iwai { 0x0008, 0x0000 }, /* 9761-78 & 82 */ 30154525c9f3STakashi Iwai { 0x0000, 0x0008 }, /* 9761-82 rev.B */ 30164525c9f3STakashi Iwai { 0x0000, 0x0008 }, /* 9761-83 */ 30171da177e4SLinus Torvalds }; 30184525c9f3STakashi Iwai static unsigned short clfe_on[3][2] = { 30194525c9f3STakashi Iwai { 0x0000, 0x1000 }, /* 9761-78 & 82 */ 30204525c9f3STakashi Iwai { 0x1000, 0x0000 }, /* 9761-82 rev.B */ 30214525c9f3STakashi Iwai { 0x0000, 0x1000 }, /* 9761-83 */ 30221da177e4SLinus Torvalds }; 30234525c9f3STakashi Iwai static unsigned short surr_shared[3][2] = { 30244525c9f3STakashi Iwai { 0x0000, 0x0400 }, /* 9761-78 & 82 */ 30254525c9f3STakashi Iwai { 0x0000, 0x0400 }, /* 9761-82 rev.B */ 30264525c9f3STakashi Iwai { 0x0000, 0x0400 }, /* 9761-83 */ 30274525c9f3STakashi Iwai }; 30284525c9f3STakashi Iwai static unsigned short clfe_shared[3][2] = { 30294525c9f3STakashi Iwai { 0x2000, 0x0880 }, /* 9761-78 & 82 */ 30304525c9f3STakashi Iwai { 0x0000, 0x2880 }, /* 9761-82 rev.B */ 30314525c9f3STakashi Iwai { 0x2000, 0x0800 }, /* 9761-83 */ 30324525c9f3STakashi Iwai }; 30334525c9f3STakashi Iwai unsigned short val = 0; 3034eb8caf30STakashi Iwai 30354525c9f3STakashi Iwai val |= surr_on[ac97->spec.dev_flags][is_surround_on(ac97)]; 30364525c9f3STakashi Iwai val |= clfe_on[ac97->spec.dev_flags][is_clfe_on(ac97)]; 3037831466f4SRandy Cushman val |= surr_shared[ac97->spec.dev_flags][is_shared_surrout(ac97)]; 3038831466f4SRandy Cushman val |= clfe_shared[ac97->spec.dev_flags][is_shared_clfeout(ac97)]; 30394525c9f3STakashi Iwai 30404525c9f3STakashi Iwai snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x3c88, val); 30411da177e4SLinus Torvalds } 30421da177e4SLinus Torvalds 3043ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_cm9761_controls[] = { 3044eb8caf30STakashi Iwai AC97_SURROUND_JACK_MODE_CTL, 3045eb8caf30STakashi Iwai AC97_CHANNEL_MODE_CTL, 30461da177e4SLinus Torvalds }; 30471da177e4SLinus Torvalds 3048ee42381eSTakashi Iwai static int cm9761_spdif_out_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 30495f0dccf8STakashi Iwai { 30505f0dccf8STakashi Iwai static char *texts[] = { "AC-Link", "ADC", "SPDIF-In" }; 30515f0dccf8STakashi Iwai 30525f0dccf8STakashi Iwai uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 30535f0dccf8STakashi Iwai uinfo->count = 1; 30545f0dccf8STakashi Iwai uinfo->value.enumerated.items = 3; 30555f0dccf8STakashi Iwai if (uinfo->value.enumerated.item > 2) 30565f0dccf8STakashi Iwai uinfo->value.enumerated.item = 2; 30575f0dccf8STakashi Iwai strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 30585f0dccf8STakashi Iwai return 0; 30595f0dccf8STakashi Iwai } 30605f0dccf8STakashi Iwai 3061ee42381eSTakashi Iwai static int cm9761_spdif_out_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 30625f0dccf8STakashi Iwai { 3063ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 30645f0dccf8STakashi Iwai 30655f0dccf8STakashi Iwai if (ac97->regs[AC97_CM9761_FUNC] & 0x1) 30665f0dccf8STakashi Iwai ucontrol->value.enumerated.item[0] = 2; /* SPDIF-loopback */ 30675f0dccf8STakashi Iwai else if (ac97->regs[AC97_CM9761_SPDIF_CTRL] & 0x2) 30685f0dccf8STakashi Iwai ucontrol->value.enumerated.item[0] = 1; /* ADC loopback */ 30695f0dccf8STakashi Iwai else 30705f0dccf8STakashi Iwai ucontrol->value.enumerated.item[0] = 0; /* AC-link */ 30715f0dccf8STakashi Iwai return 0; 30725f0dccf8STakashi Iwai } 30735f0dccf8STakashi Iwai 3074ee42381eSTakashi Iwai static int cm9761_spdif_out_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 30755f0dccf8STakashi Iwai { 3076ee42381eSTakashi Iwai struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 30775f0dccf8STakashi Iwai 30785f0dccf8STakashi Iwai if (ucontrol->value.enumerated.item[0] == 2) 30795f0dccf8STakashi Iwai return snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0x1); 30805f0dccf8STakashi Iwai snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0); 30815f0dccf8STakashi Iwai return snd_ac97_update_bits(ac97, AC97_CM9761_SPDIF_CTRL, 0x2, 30825f0dccf8STakashi Iwai ucontrol->value.enumerated.item[0] == 1 ? 0x2 : 0); 30835f0dccf8STakashi Iwai } 30845f0dccf8STakashi Iwai 30855f0dccf8STakashi Iwai static const char *cm9761_dac_clock[] = { "AC-Link", "SPDIF-In", "Both" }; 30865f0dccf8STakashi Iwai static const struct ac97_enum cm9761_dac_clock_enum = 30875f0dccf8STakashi Iwai AC97_ENUM_SINGLE(AC97_CM9761_SPDIF_CTRL, 9, 3, cm9761_dac_clock); 30885f0dccf8STakashi Iwai 3089ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_cm9761_controls_spdif[] = { 30905f0dccf8STakashi Iwai { /* BIT 1: SPDIFS */ 30915f0dccf8STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 30925f0dccf8STakashi Iwai .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source", 30935f0dccf8STakashi Iwai .info = cm9761_spdif_out_source_info, 30945f0dccf8STakashi Iwai .get = cm9761_spdif_out_source_get, 30955f0dccf8STakashi Iwai .put = cm9761_spdif_out_source_put, 30965f0dccf8STakashi Iwai }, 30975f0dccf8STakashi Iwai /* BIT 2: IG_SPIV */ 30985f0dccf8STakashi Iwai AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9761_SPDIF_CTRL, 2, 1, 0), 30995f0dccf8STakashi Iwai /* BIT 3: SPI2F */ 31005f0dccf8STakashi Iwai AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9761_SPDIF_CTRL, 3, 1, 0), 31015f0dccf8STakashi Iwai /* BIT 4: SPI2SDI */ 31025f0dccf8STakashi Iwai AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9761_SPDIF_CTRL, 4, 1, 0), 31035f0dccf8STakashi Iwai /* BIT 9-10: DAC_CTL */ 31045f0dccf8STakashi Iwai AC97_ENUM("DAC Clock Source", cm9761_dac_clock_enum), 31055f0dccf8STakashi Iwai }; 31065f0dccf8STakashi Iwai 3107ee42381eSTakashi Iwai static int patch_cm9761_post_spdif(struct snd_ac97 * ac97) 31085f0dccf8STakashi Iwai { 31095f0dccf8STakashi Iwai return patch_build_controls(ac97, snd_ac97_cm9761_controls_spdif, ARRAY_SIZE(snd_ac97_cm9761_controls_spdif)); 31105f0dccf8STakashi Iwai } 31115f0dccf8STakashi Iwai 3112ee42381eSTakashi Iwai static int patch_cm9761_specific(struct snd_ac97 * ac97) 31131da177e4SLinus Torvalds { 31141da177e4SLinus Torvalds return patch_build_controls(ac97, snd_ac97_cm9761_controls, ARRAY_SIZE(snd_ac97_cm9761_controls)); 31151da177e4SLinus Torvalds } 31161da177e4SLinus Torvalds 31171da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_cm9761_ops = { 31181da177e4SLinus Torvalds .build_specific = patch_cm9761_specific, 3119eb8caf30STakashi Iwai .build_post_spdif = patch_cm9761_post_spdif, 3120eb8caf30STakashi Iwai .update_jacks = cm9761_update_jacks 31211da177e4SLinus Torvalds }; 31221da177e4SLinus Torvalds 3123ac519028STakashi Iwai static int patch_cm9761(struct snd_ac97 *ac97) 31241da177e4SLinus Torvalds { 31251da177e4SLinus Torvalds unsigned short val; 31261da177e4SLinus Torvalds 31271da177e4SLinus Torvalds /* CM9761 has no PCM volume although the register reacts */ 31281da177e4SLinus Torvalds /* Master volume seems to have _some_ influence on the analog 31291da177e4SLinus Torvalds * input sounds 31301da177e4SLinus Torvalds */ 31311da177e4SLinus Torvalds ac97->flags |= /*AC97_HAS_NO_MASTER_VOL |*/ AC97_HAS_NO_PCM_VOL; 31321da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_MASTER, 0x8808); 31331da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_PCM, 0x8808); 31341da177e4SLinus Torvalds 31354525c9f3STakashi Iwai ac97->spec.dev_flags = 0; /* 1 = model 82 revision B, 2 = model 83 */ 31361da177e4SLinus Torvalds if (ac97->id == AC97_ID_CM9761_82) { 31371da177e4SLinus Torvalds unsigned short tmp; 31381da177e4SLinus Torvalds /* check page 1, reg 0x60 */ 31391da177e4SLinus Torvalds val = snd_ac97_read(ac97, AC97_INT_PAGING); 31401da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_INT_PAGING, (val & ~0x0f) | 0x01); 31411da177e4SLinus Torvalds tmp = snd_ac97_read(ac97, 0x60); 31421da177e4SLinus Torvalds ac97->spec.dev_flags = tmp & 1; /* revision B? */ 31431da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_INT_PAGING, val); 31444525c9f3STakashi Iwai } else if (ac97->id == AC97_ID_CM9761_83) 31454525c9f3STakashi Iwai ac97->spec.dev_flags = 2; 31461da177e4SLinus Torvalds 31471da177e4SLinus Torvalds ac97->build_ops = &patch_cm9761_ops; 31481da177e4SLinus Torvalds 31491da177e4SLinus Torvalds /* enable spdif */ 31501da177e4SLinus Torvalds /* force the SPDIF bit in ext_id - codec doesn't set this bit! */ 31511da177e4SLinus Torvalds ac97->ext_id |= AC97_EI_SPDIF; 31521da177e4SLinus Torvalds /* to be sure: we overwrite the ext status bits */ 31531da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, 0x05c0); 31541da177e4SLinus Torvalds /* Don't set 0x0200 here. This results in the silent analog output */ 31555f0dccf8STakashi Iwai snd_ac97_write_cache(ac97, AC97_CM9761_SPDIF_CTRL, 0x0001); /* enable spdif-in */ 31561da177e4SLinus Torvalds ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */ 31571da177e4SLinus Torvalds 31581da177e4SLinus Torvalds /* set-up multi channel */ 31591da177e4SLinus Torvalds /* bit 15: pc master beep off 31605f0dccf8STakashi Iwai * bit 14: pin47 = EAPD/SPDIF 31611da177e4SLinus Torvalds * bit 13: vref ctl [= cm9739] 31625f0dccf8STakashi Iwai * bit 12: CLFE control (reverted on rev B) 31635f0dccf8STakashi Iwai * bit 11: Mic/center share (reverted on rev B) 31645f0dccf8STakashi Iwai * bit 10: suddound/line share 31655f0dccf8STakashi Iwai * bit 9: Analog-in mix -> surround 31665f0dccf8STakashi Iwai * bit 8: Analog-in mix -> CLFE 31675f0dccf8STakashi Iwai * bit 7: Mic/LFE share (mic/center/lfe) 31685f0dccf8STakashi Iwai * bit 5: vref select (9761A) 31695f0dccf8STakashi Iwai * bit 4: front control 31705f0dccf8STakashi Iwai * bit 3: surround control (revereted with rev B) 31715f0dccf8STakashi Iwai * bit 2: front mic 31725f0dccf8STakashi Iwai * bit 1: stereo mic 31735f0dccf8STakashi Iwai * bit 0: mic boost level (0=20dB, 1=30dB) 31741da177e4SLinus Torvalds */ 31751da177e4SLinus Torvalds 31761da177e4SLinus Torvalds #if 0 31771da177e4SLinus Torvalds if (ac97->spec.dev_flags) 31781da177e4SLinus Torvalds val = 0x0214; 31791da177e4SLinus Torvalds else 31801da177e4SLinus Torvalds val = 0x321c; 31811da177e4SLinus Torvalds #endif 31821da177e4SLinus Torvalds val = snd_ac97_read(ac97, AC97_CM9761_MULTI_CHAN); 31831da177e4SLinus Torvalds val |= (1 << 4); /* front on */ 31841da177e4SLinus Torvalds snd_ac97_write_cache(ac97, AC97_CM9761_MULTI_CHAN, val); 31851da177e4SLinus Torvalds 31861da177e4SLinus Torvalds /* FIXME: set up GPIO */ 31871da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x70, 0x0100); 31881da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x72, 0x0020); 31891da177e4SLinus Torvalds 31901da177e4SLinus Torvalds return 0; 31911da177e4SLinus Torvalds } 31921da177e4SLinus Torvalds 31935f0dccf8STakashi Iwai #define AC97_CM9780_SIDE 0x60 31945f0dccf8STakashi Iwai #define AC97_CM9780_JACK 0x62 31955f0dccf8STakashi Iwai #define AC97_CM9780_MIXER 0x64 31965f0dccf8STakashi Iwai #define AC97_CM9780_MULTI_CHAN 0x66 31975f0dccf8STakashi Iwai #define AC97_CM9780_SPDIF 0x6c 31985f0dccf8STakashi Iwai 31995f0dccf8STakashi Iwai static const char *cm9780_ch_select[] = { "Front", "Side", "Center/LFE", "Rear" }; 32005f0dccf8STakashi Iwai static const struct ac97_enum cm9780_ch_select_enum = 32015f0dccf8STakashi Iwai AC97_ENUM_SINGLE(AC97_CM9780_MULTI_CHAN, 6, 4, cm9780_ch_select); 3202ee42381eSTakashi Iwai static const struct snd_kcontrol_new cm9780_controls[] = { 32035f0dccf8STakashi Iwai AC97_DOUBLE("Side Playback Switch", AC97_CM9780_SIDE, 15, 7, 1, 1), 32045f0dccf8STakashi Iwai AC97_DOUBLE("Side Playback Volume", AC97_CM9780_SIDE, 8, 0, 31, 0), 32055f0dccf8STakashi Iwai AC97_ENUM("Side Playback Route", cm9780_ch_select_enum), 32065f0dccf8STakashi Iwai }; 32075f0dccf8STakashi Iwai 3208ee42381eSTakashi Iwai static int patch_cm9780_specific(struct snd_ac97 *ac97) 32095f0dccf8STakashi Iwai { 32105f0dccf8STakashi Iwai return patch_build_controls(ac97, cm9780_controls, ARRAY_SIZE(cm9780_controls)); 32115f0dccf8STakashi Iwai } 32125f0dccf8STakashi Iwai 32135f0dccf8STakashi Iwai static struct snd_ac97_build_ops patch_cm9780_ops = { 32145f0dccf8STakashi Iwai .build_specific = patch_cm9780_specific, 32155f0dccf8STakashi Iwai .build_post_spdif = patch_cm9761_post_spdif /* identical with CM9761 */ 32165f0dccf8STakashi Iwai }; 32175f0dccf8STakashi Iwai 3218ac519028STakashi Iwai static int patch_cm9780(struct snd_ac97 *ac97) 32195f0dccf8STakashi Iwai { 32205f0dccf8STakashi Iwai unsigned short val; 32215f0dccf8STakashi Iwai 32225f0dccf8STakashi Iwai ac97->build_ops = &patch_cm9780_ops; 32235f0dccf8STakashi Iwai 32245f0dccf8STakashi Iwai /* enable spdif */ 32255f0dccf8STakashi Iwai if (ac97->ext_id & AC97_EI_SPDIF) { 32265f0dccf8STakashi Iwai ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */ 32275f0dccf8STakashi Iwai val = snd_ac97_read(ac97, AC97_CM9780_SPDIF); 32285f0dccf8STakashi Iwai val |= 0x1; /* SPDI_EN */ 32295f0dccf8STakashi Iwai snd_ac97_write_cache(ac97, AC97_CM9780_SPDIF, val); 32305f0dccf8STakashi Iwai } 32315f0dccf8STakashi Iwai 32325f0dccf8STakashi Iwai return 0; 32335f0dccf8STakashi Iwai } 32341da177e4SLinus Torvalds 32351da177e4SLinus Torvalds /* 32361da177e4SLinus Torvalds * VIA VT1616 codec 32371da177e4SLinus Torvalds */ 3238ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_vt1616[] = { 32391da177e4SLinus Torvalds AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0), 32401da177e4SLinus Torvalds AC97_SINGLE("Alternate Level to Surround Out", 0x5a, 15, 1, 0), 32411da177e4SLinus Torvalds AC97_SINGLE("Downmix LFE and Center to Front", 0x5a, 12, 1, 0), 32421da177e4SLinus Torvalds AC97_SINGLE("Downmix Surround to Front", 0x5a, 11, 1, 0), 32431da177e4SLinus Torvalds }; 32441da177e4SLinus Torvalds 3245ee42381eSTakashi Iwai static int patch_vt1616_specific(struct snd_ac97 * ac97) 32461da177e4SLinus Torvalds { 32471da177e4SLinus Torvalds int err; 32481da177e4SLinus Torvalds 32491da177e4SLinus Torvalds if (snd_ac97_try_bit(ac97, 0x5a, 9)) 32501da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[0], 1)) < 0) 32511da177e4SLinus Torvalds return err; 32521da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[1], ARRAY_SIZE(snd_ac97_controls_vt1616) - 1)) < 0) 32531da177e4SLinus Torvalds return err; 32541da177e4SLinus Torvalds return 0; 32551da177e4SLinus Torvalds } 32561da177e4SLinus Torvalds 32571da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_vt1616_ops = { 32581da177e4SLinus Torvalds .build_specific = patch_vt1616_specific 32591da177e4SLinus Torvalds }; 32601da177e4SLinus Torvalds 3261ac519028STakashi Iwai static int patch_vt1616(struct snd_ac97 * ac97) 32621da177e4SLinus Torvalds { 32631da177e4SLinus Torvalds ac97->build_ops = &patch_vt1616_ops; 32641da177e4SLinus Torvalds return 0; 32651da177e4SLinus Torvalds } 32661da177e4SLinus Torvalds 3267eb8caf30STakashi Iwai /* 32684b499486SPhilip Prindeville * VT1617A codec 32694b499486SPhilip Prindeville */ 3270e9024cccSJohn Utz 3271e9024cccSJohn Utz /* 3272e9024cccSJohn Utz * unfortunately, the vt1617a stashes the twiddlers required for 3273e9024cccSJohn Utz * nooding the i/o jacks on 2 different regs. * thameans that we cant 3274e9024cccSJohn Utz * use the easy way provided by AC97_ENUM_DOUBLE() we have to write 3275e9024cccSJohn Utz * are own funcs. 3276e9024cccSJohn Utz * 3277e9024cccSJohn Utz * NB: this is absolutely and utterly different from the vt1618. dunno 3278e9024cccSJohn Utz * about the 1616. 3279e9024cccSJohn Utz */ 3280e9024cccSJohn Utz 3281e9024cccSJohn Utz /* copied from ac97_surround_jack_mode_info() */ 3282e9024cccSJohn Utz static int snd_ac97_vt1617a_smart51_info(struct snd_kcontrol *kcontrol, 3283e9024cccSJohn Utz struct snd_ctl_elem_info *uinfo) 32844b499486SPhilip Prindeville { 3285e9024cccSJohn Utz /* ordering in this list reflects vt1617a docs for Reg 20 and 3286e9024cccSJohn Utz * 7a and Table 6 that lays out the matrix NB WRT Table6: SM51 3287e9024cccSJohn Utz * is SM51EN *AND* it's Bit14, not Bit15 so the table is very 3288e9024cccSJohn Utz * counter-intuitive */ 3289e9024cccSJohn Utz 3290e9024cccSJohn Utz static const char* texts[] = { "LineIn Mic1", "LineIn Mic1 Mic3", 3291e9024cccSJohn Utz "Surr LFE/C Mic3", "LineIn LFE/C Mic3", 3292e9024cccSJohn Utz "LineIn Mic2", "LineIn Mic2 Mic1", 3293e9024cccSJohn Utz "Surr LFE Mic1", "Surr LFE Mic1 Mic2"}; 3294e9024cccSJohn Utz return ac97_enum_text_info(kcontrol, uinfo, texts, 8); 3295e9024cccSJohn Utz } 3296e9024cccSJohn Utz 3297e9024cccSJohn Utz static int snd_ac97_vt1617a_smart51_get(struct snd_kcontrol *kcontrol, 3298e9024cccSJohn Utz struct snd_ctl_elem_value *ucontrol) 3299e9024cccSJohn Utz { 3300e9024cccSJohn Utz ushort usSM51, usMS; 3301e9024cccSJohn Utz 3302e9024cccSJohn Utz struct snd_ac97 *pac97; 3303e9024cccSJohn Utz 3304e9024cccSJohn Utz pac97 = snd_kcontrol_chip(kcontrol); /* grab codec handle */ 3305e9024cccSJohn Utz 3306e9024cccSJohn Utz /* grab our desirec bits, then mash them together in a manner 3307e9024cccSJohn Utz * consistent with Table 6 on page 17 in the 1617a docs */ 3308e9024cccSJohn Utz 3309e9024cccSJohn Utz usSM51 = snd_ac97_read(pac97, 0x7a) >> 14; 3310e9024cccSJohn Utz usMS = snd_ac97_read(pac97, 0x20) >> 8; 3311e9024cccSJohn Utz 3312e9024cccSJohn Utz ucontrol->value.enumerated.item[0] = (usSM51 << 1) + usMS; 3313e9024cccSJohn Utz 3314e9024cccSJohn Utz return 0; 3315e9024cccSJohn Utz } 3316e9024cccSJohn Utz 3317e9024cccSJohn Utz static int snd_ac97_vt1617a_smart51_put(struct snd_kcontrol *kcontrol, 3318e9024cccSJohn Utz struct snd_ctl_elem_value *ucontrol) 3319e9024cccSJohn Utz { 3320e9024cccSJohn Utz ushort usSM51, usMS, usReg; 3321e9024cccSJohn Utz 3322e9024cccSJohn Utz struct snd_ac97 *pac97; 3323e9024cccSJohn Utz 3324e9024cccSJohn Utz pac97 = snd_kcontrol_chip(kcontrol); /* grab codec handle */ 3325e9024cccSJohn Utz 3326e9024cccSJohn Utz usSM51 = ucontrol->value.enumerated.item[0] >> 1; 3327e9024cccSJohn Utz usMS = ucontrol->value.enumerated.item[0] & 1; 3328e9024cccSJohn Utz 3329e9024cccSJohn Utz /* push our values into the register - consider that things will be left 3330e9024cccSJohn Utz * in a funky state if the write fails */ 3331e9024cccSJohn Utz 3332e9024cccSJohn Utz usReg = snd_ac97_read(pac97, 0x7a); 3333e9024cccSJohn Utz snd_ac97_write_cache(pac97, 0x7a, (usReg & 0x3FFF) + (usSM51 << 14)); 3334e9024cccSJohn Utz usReg = snd_ac97_read(pac97, 0x20); 3335e9024cccSJohn Utz snd_ac97_write_cache(pac97, 0x20, (usReg & 0xFEFF) + (usMS << 8)); 3336e9024cccSJohn Utz 3337e9024cccSJohn Utz return 0; 3338e9024cccSJohn Utz } 3339e9024cccSJohn Utz 3340e9024cccSJohn Utz static const struct snd_kcontrol_new snd_ac97_controls_vt1617a[] = { 3341e9024cccSJohn Utz 3342e9024cccSJohn Utz AC97_SINGLE("Center/LFE Exchange", 0x5a, 8, 1, 0), 3343e9024cccSJohn Utz /* 3344e9024cccSJohn Utz * These are used to enable/disable surround sound on motherboards 3345e9024cccSJohn Utz * that have 3 bidirectional analog jacks 3346e9024cccSJohn Utz */ 3347e9024cccSJohn Utz { 3348e9024cccSJohn Utz .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 3349e9024cccSJohn Utz .name = "Smart 5.1 Select", 3350e9024cccSJohn Utz .info = snd_ac97_vt1617a_smart51_info, 3351e9024cccSJohn Utz .get = snd_ac97_vt1617a_smart51_get, 3352e9024cccSJohn Utz .put = snd_ac97_vt1617a_smart51_put, 3353e9024cccSJohn Utz }, 3354e9024cccSJohn Utz }; 3355e9024cccSJohn Utz 3356e9024cccSJohn Utz int patch_vt1617a(struct snd_ac97 * ac97) 3357e9024cccSJohn Utz { 3358e9024cccSJohn Utz int err = 0; 3359e9024cccSJohn Utz 3360e9024cccSJohn Utz /* we choose to not fail out at this point, but we tell the 3361e9024cccSJohn Utz caller when we return */ 3362e9024cccSJohn Utz 3363e9024cccSJohn Utz err = patch_build_controls(ac97, &snd_ac97_controls_vt1617a[0], 3364e9024cccSJohn Utz ARRAY_SIZE(snd_ac97_controls_vt1617a)); 3365e9024cccSJohn Utz 3366e9024cccSJohn Utz /* bring analog power consumption to normal by turning off the 3367e9024cccSJohn Utz * headphone amplifier, like WinXP driver for EPIA SP 33689f458e7fSAndrey Liakhovets */ 33699f458e7fSAndrey Liakhovets snd_ac97_write_cache(ac97, 0x5c, 0x20); 33704b499486SPhilip Prindeville ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */ 33714b499486SPhilip Prindeville ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000; 33729f428175SDaniel Jacobowitz ac97->build_ops = &patch_vt1616_ops; 3373e9024cccSJohn Utz 3374e9024cccSJohn Utz return err; 33754b499486SPhilip Prindeville } 33764b499486SPhilip Prindeville 33774b499486SPhilip Prindeville /* 3378eb8caf30STakashi Iwai */ 3379ee42381eSTakashi Iwai static void it2646_update_jacks(struct snd_ac97 *ac97) 3380eb8caf30STakashi Iwai { 3381831466f4SRandy Cushman /* shared Line-In / Surround Out */ 3382eb8caf30STakashi Iwai snd_ac97_update_bits(ac97, 0x76, 1 << 9, 3383831466f4SRandy Cushman is_shared_surrout(ac97) ? (1<<9) : 0); 3384831466f4SRandy Cushman /* shared Mic / Center/LFE Out */ 3385eb8caf30STakashi Iwai snd_ac97_update_bits(ac97, 0x76, 1 << 10, 3386831466f4SRandy Cushman is_shared_clfeout(ac97) ? (1<<10) : 0); 3387eb8caf30STakashi Iwai } 3388eb8caf30STakashi Iwai 3389ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_it2646[] = { 3390eb8caf30STakashi Iwai AC97_SURROUND_JACK_MODE_CTL, 3391eb8caf30STakashi Iwai AC97_CHANNEL_MODE_CTL, 33921da177e4SLinus Torvalds }; 33931da177e4SLinus Torvalds 3394ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_spdif_controls_it2646[] = { 339510e8d78aSClemens Ladisch AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 0x76, 11, 1, 0), 33961da177e4SLinus Torvalds AC97_SINGLE("Analog to IEC958 Output", 0x76, 12, 1, 0), 33971da177e4SLinus Torvalds AC97_SINGLE("IEC958 Input Monitor", 0x76, 13, 1, 0), 33981da177e4SLinus Torvalds }; 33991da177e4SLinus Torvalds 3400ee42381eSTakashi Iwai static int patch_it2646_specific(struct snd_ac97 * ac97) 34011da177e4SLinus Torvalds { 34021da177e4SLinus Torvalds int err; 34031da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, snd_ac97_controls_it2646, ARRAY_SIZE(snd_ac97_controls_it2646))) < 0) 34041da177e4SLinus Torvalds return err; 34051da177e4SLinus Torvalds if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_it2646, ARRAY_SIZE(snd_ac97_spdif_controls_it2646))) < 0) 34061da177e4SLinus Torvalds return err; 34071da177e4SLinus Torvalds return 0; 34081da177e4SLinus Torvalds } 34091da177e4SLinus Torvalds 34101da177e4SLinus Torvalds static struct snd_ac97_build_ops patch_it2646_ops = { 3411eb8caf30STakashi Iwai .build_specific = patch_it2646_specific, 3412eb8caf30STakashi Iwai .update_jacks = it2646_update_jacks 34131da177e4SLinus Torvalds }; 34141da177e4SLinus Torvalds 3415ac519028STakashi Iwai static int patch_it2646(struct snd_ac97 * ac97) 34161da177e4SLinus Torvalds { 34171da177e4SLinus Torvalds ac97->build_ops = &patch_it2646_ops; 34181da177e4SLinus Torvalds /* full DAC volume */ 34191da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x5E, 0x0808); 34201da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x7A, 0x0808); 34211da177e4SLinus Torvalds return 0; 34221da177e4SLinus Torvalds } 34231da177e4SLinus Torvalds 342487d61c29SSasha Khapyorsky /* 342587d61c29SSasha Khapyorsky * Si3036 codec 342687d61c29SSasha Khapyorsky */ 342787d61c29SSasha Khapyorsky 34281da177e4SLinus Torvalds #define AC97_SI3036_CHIP_ID 0x5a 342987d61c29SSasha Khapyorsky #define AC97_SI3036_LINE_CFG 0x5c 343087d61c29SSasha Khapyorsky 3431ee42381eSTakashi Iwai static const struct snd_kcontrol_new snd_ac97_controls_si3036[] = { 343287d61c29SSasha Khapyorsky AC97_DOUBLE("Modem Speaker Volume", 0x5c, 14, 12, 3, 1) 343387d61c29SSasha Khapyorsky }; 343487d61c29SSasha Khapyorsky 3435ee42381eSTakashi Iwai static int patch_si3036_specific(struct snd_ac97 * ac97) 343687d61c29SSasha Khapyorsky { 343727bcaa69SSasha Khapyorsky int idx, err; 343827bcaa69SSasha Khapyorsky for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_si3036); idx++) 343927bcaa69SSasha Khapyorsky if ((err = snd_ctl_add(ac97->bus->card, snd_ctl_new1(&snd_ac97_controls_si3036[idx], ac97))) < 0) 344027bcaa69SSasha Khapyorsky return err; 344127bcaa69SSasha Khapyorsky return 0; 344287d61c29SSasha Khapyorsky } 344387d61c29SSasha Khapyorsky 344487d61c29SSasha Khapyorsky static struct snd_ac97_build_ops patch_si3036_ops = { 344587d61c29SSasha Khapyorsky .build_specific = patch_si3036_specific, 344687d61c29SSasha Khapyorsky }; 34471da177e4SLinus Torvalds 3448ac519028STakashi Iwai static int mpatch_si3036(struct snd_ac97 * ac97) 34491da177e4SLinus Torvalds { 345087d61c29SSasha Khapyorsky ac97->build_ops = &patch_si3036_ops; 34511da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x5c, 0xf210 ); 34521da177e4SLinus Torvalds snd_ac97_write_cache(ac97, 0x68, 0); 34531da177e4SLinus Torvalds return 0; 34541da177e4SLinus Torvalds } 3455ba22429dSCharl Coetzee 3456ba22429dSCharl Coetzee /* 3457ba22429dSCharl Coetzee * LM 4550 Codec 3458ba22429dSCharl Coetzee * 3459ba22429dSCharl Coetzee * We use a static resolution table since LM4550 codec cannot be 3460ba22429dSCharl Coetzee * properly autoprobed to determine the resolution via 3461ba22429dSCharl Coetzee * check_volume_resolution(). 3462ba22429dSCharl Coetzee */ 3463ba22429dSCharl Coetzee 3464ba22429dSCharl Coetzee static struct snd_ac97_res_table lm4550_restbl[] = { 3465ba22429dSCharl Coetzee { AC97_MASTER, 0x1f1f }, 3466ba22429dSCharl Coetzee { AC97_HEADPHONE, 0x1f1f }, 3467ba22429dSCharl Coetzee { AC97_MASTER_MONO, 0x001f }, 3468ba22429dSCharl Coetzee { AC97_PC_BEEP, 0x001f }, /* LSB is ignored */ 3469ba22429dSCharl Coetzee { AC97_PHONE, 0x001f }, 3470ba22429dSCharl Coetzee { AC97_MIC, 0x001f }, 3471ba22429dSCharl Coetzee { AC97_LINE, 0x1f1f }, 3472ba22429dSCharl Coetzee { AC97_CD, 0x1f1f }, 3473ba22429dSCharl Coetzee { AC97_VIDEO, 0x1f1f }, 3474ba22429dSCharl Coetzee { AC97_AUX, 0x1f1f }, 3475ba22429dSCharl Coetzee { AC97_PCM, 0x1f1f }, 3476ba22429dSCharl Coetzee { AC97_REC_GAIN, 0x0f0f }, 3477ba22429dSCharl Coetzee { } /* terminator */ 3478ba22429dSCharl Coetzee }; 3479ba22429dSCharl Coetzee 3480ac519028STakashi Iwai static int patch_lm4550(struct snd_ac97 *ac97) 3481ba22429dSCharl Coetzee { 3482ba22429dSCharl Coetzee ac97->res_table = lm4550_restbl; 3483ba22429dSCharl Coetzee return 0; 3484ba22429dSCharl Coetzee } 348582466ad7SMike Rapoport 348682466ad7SMike Rapoport /* 348782466ad7SMike Rapoport * UCB1400 codec (http://www.semiconductors.philips.com/acrobat_download/datasheets/UCB1400-02.pdf) 348882466ad7SMike Rapoport */ 348982466ad7SMike Rapoport static const struct snd_kcontrol_new snd_ac97_controls_ucb1400[] = { 349082466ad7SMike Rapoport /* enable/disable headphone driver which allows direct connection to 349182466ad7SMike Rapoport stereo headphone without the use of external DC blocking 349282466ad7SMike Rapoport capacitors */ 349382466ad7SMike Rapoport AC97_SINGLE("Headphone Driver", 0x6a, 6, 1, 0), 349482466ad7SMike Rapoport /* Filter used to compensate the DC offset is added in the ADC to remove idle 349582466ad7SMike Rapoport tones from the audio band. */ 349682466ad7SMike Rapoport AC97_SINGLE("DC Filter", 0x6a, 4, 1, 0), 349782466ad7SMike Rapoport /* Control smart-low-power mode feature. Allows automatic power down 349882466ad7SMike Rapoport of unused blocks in the ADC analog front end and the PLL. */ 349982466ad7SMike Rapoport AC97_SINGLE("Smart Low Power Mode", 0x6c, 4, 3, 0), 350082466ad7SMike Rapoport }; 350182466ad7SMike Rapoport 350282466ad7SMike Rapoport static int patch_ucb1400_specific(struct snd_ac97 * ac97) 350382466ad7SMike Rapoport { 350482466ad7SMike Rapoport int idx, err; 350582466ad7SMike Rapoport for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_ucb1400); idx++) 350682466ad7SMike Rapoport if ((err = snd_ctl_add(ac97->bus->card, snd_ctl_new1(&snd_ac97_controls_ucb1400[idx], ac97))) < 0) 350782466ad7SMike Rapoport return err; 350882466ad7SMike Rapoport return 0; 350982466ad7SMike Rapoport } 351082466ad7SMike Rapoport 351182466ad7SMike Rapoport static struct snd_ac97_build_ops patch_ucb1400_ops = { 351282466ad7SMike Rapoport .build_specific = patch_ucb1400_specific, 351382466ad7SMike Rapoport }; 351482466ad7SMike Rapoport 3515ac519028STakashi Iwai static int patch_ucb1400(struct snd_ac97 * ac97) 351682466ad7SMike Rapoport { 351782466ad7SMike Rapoport ac97->build_ops = &patch_ucb1400_ops; 351882466ad7SMike Rapoport /* enable headphone driver and smart low power mode by default */ 351982466ad7SMike Rapoport snd_ac97_write(ac97, 0x6a, 0x0050); 352082466ad7SMike Rapoport snd_ac97_write(ac97, 0x6c, 0x0030); 352182466ad7SMike Rapoport return 0; 352282466ad7SMike Rapoport } 3523