Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 2 | * Copyright (c) by Jaroslav Kysela <perex@perex.cz> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Universal interface for Audio Codec '97 |
| 4 | * |
| 5 | * For more details look to AC '97 component specification revision 2.2 |
| 6 | * by Intel Corporation (http://developer.intel.com) and to datasheets |
| 7 | * for specific codecs. |
| 8 | * |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 | * |
| 24 | */ |
| 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include "ac97_local.h" |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 27 | #include "ac97_patch.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
| 29 | /* |
Andreas Mohr | 6ba9256 | 2011-02-19 00:49:48 +0100 | [diff] [blame] | 30 | * Forward declarations |
| 31 | */ |
| 32 | |
| 33 | static struct snd_kcontrol *snd_ac97_find_mixer_ctl(struct snd_ac97 *ac97, |
| 34 | const char *name); |
| 35 | static int snd_ac97_add_vmaster(struct snd_ac97 *ac97, char *name, |
| 36 | const unsigned int *tlv, const char **slaves); |
| 37 | |
| 38 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | * Chip specific initialization |
| 40 | */ |
| 41 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 42 | static int patch_build_controls(struct snd_ac97 * ac97, const struct snd_kcontrol_new *controls, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | { |
| 44 | int idx, err; |
| 45 | |
| 46 | for (idx = 0; idx < count; idx++) |
| 47 | if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&controls[idx], ac97))) < 0) |
| 48 | return err; |
| 49 | return 0; |
| 50 | } |
| 51 | |
Takashi Iwai | 2f3482f | 2006-08-21 18:44:31 +0200 | [diff] [blame] | 52 | /* replace with a new TLV */ |
| 53 | static void reset_tlv(struct snd_ac97 *ac97, const char *name, |
Takashi Iwai | 0cb29ea | 2007-01-29 15:33:49 +0100 | [diff] [blame] | 54 | const unsigned int *tlv) |
Takashi Iwai | 2f3482f | 2006-08-21 18:44:31 +0200 | [diff] [blame] | 55 | { |
| 56 | struct snd_ctl_elem_id sid; |
| 57 | struct snd_kcontrol *kctl; |
| 58 | memset(&sid, 0, sizeof(sid)); |
| 59 | strcpy(sid.name, name); |
| 60 | sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 61 | kctl = snd_ctl_find_id(ac97->bus->card, &sid); |
| 62 | if (kctl && kctl->tlv.p) |
| 63 | kctl->tlv.p = tlv; |
| 64 | } |
| 65 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | /* set to the page, update bits and restore the page */ |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 67 | static int ac97_update_bits_page(struct snd_ac97 *ac97, unsigned short reg, unsigned short mask, unsigned short value, unsigned short page) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | { |
| 69 | unsigned short page_save; |
| 70 | int ret; |
| 71 | |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 72 | mutex_lock(&ac97->page_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | page_save = snd_ac97_read(ac97, AC97_INT_PAGING) & AC97_PAGE_MASK; |
| 74 | snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page); |
| 75 | ret = snd_ac97_update_bits(ac97, reg, mask, value); |
| 76 | snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page_save); |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 77 | mutex_unlock(&ac97->page_mutex); /* unlock paging */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | return ret; |
| 79 | } |
| 80 | |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 81 | /* |
| 82 | * shared line-in/mic controls |
| 83 | */ |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 84 | static int ac97_surround_jack_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 85 | { |
Takashi Iwai | 3b7a00d | 2014-10-20 18:15:36 +0200 | [diff] [blame^] | 86 | static const char * const texts[] = { "Shared", "Independent" }; |
| 87 | |
| 88 | return snd_ctl_enum_info(uinfo, 1, 2, texts); |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 89 | } |
| 90 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 91 | static int ac97_surround_jack_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 92 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 93 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 94 | |
| 95 | ucontrol->value.enumerated.item[0] = ac97->indep_surround; |
| 96 | return 0; |
| 97 | } |
| 98 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 99 | static int ac97_surround_jack_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 100 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 101 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 102 | unsigned char indep = !!ucontrol->value.enumerated.item[0]; |
| 103 | |
| 104 | if (indep != ac97->indep_surround) { |
| 105 | ac97->indep_surround = indep; |
| 106 | if (ac97->build_ops->update_jacks) |
| 107 | ac97->build_ops->update_jacks(ac97); |
| 108 | return 1; |
| 109 | } |
| 110 | return 0; |
| 111 | } |
| 112 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 113 | static int ac97_channel_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 114 | { |
Takashi Iwai | 3b7a00d | 2014-10-20 18:15:36 +0200 | [diff] [blame^] | 115 | static const char * const texts[] = { "2ch", "4ch", "6ch", "8ch" }; |
| 116 | |
| 117 | return snd_ctl_enum_info(uinfo, 1, kcontrol->private_value, texts); |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 118 | } |
| 119 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 120 | static int ac97_channel_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 121 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 122 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 123 | |
| 124 | ucontrol->value.enumerated.item[0] = ac97->channel_mode; |
| 125 | return 0; |
| 126 | } |
| 127 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 128 | static int ac97_channel_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 129 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 130 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 131 | unsigned char mode = ucontrol->value.enumerated.item[0]; |
| 132 | |
Takashi Iwai | 4235a31 | 2008-02-18 12:23:13 +0100 | [diff] [blame] | 133 | if (mode >= kcontrol->private_value) |
| 134 | return -EINVAL; |
Takashi Iwai | 4e98d6a | 2007-11-15 15:58:13 +0100 | [diff] [blame] | 135 | |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 136 | if (mode != ac97->channel_mode) { |
| 137 | ac97->channel_mode = mode; |
| 138 | if (ac97->build_ops->update_jacks) |
| 139 | ac97->build_ops->update_jacks(ac97); |
| 140 | return 1; |
| 141 | } |
| 142 | return 0; |
| 143 | } |
| 144 | |
| 145 | #define AC97_SURROUND_JACK_MODE_CTL \ |
| 146 | { \ |
| 147 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 148 | .name = "Surround Jack Mode", \ |
| 149 | .info = ac97_surround_jack_mode_info, \ |
| 150 | .get = ac97_surround_jack_mode_get, \ |
| 151 | .put = ac97_surround_jack_mode_put, \ |
| 152 | } |
Takashi Iwai | 4235a31 | 2008-02-18 12:23:13 +0100 | [diff] [blame] | 153 | /* 6ch */ |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 154 | #define AC97_CHANNEL_MODE_CTL \ |
| 155 | { \ |
| 156 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 157 | .name = "Channel Mode", \ |
| 158 | .info = ac97_channel_mode_info, \ |
| 159 | .get = ac97_channel_mode_get, \ |
| 160 | .put = ac97_channel_mode_put, \ |
Takashi Iwai | 4235a31 | 2008-02-18 12:23:13 +0100 | [diff] [blame] | 161 | .private_value = 3, \ |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 162 | } |
Takashi Iwai | 4235a31 | 2008-02-18 12:23:13 +0100 | [diff] [blame] | 163 | /* 4ch */ |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 164 | #define AC97_CHANNEL_MODE_4CH_CTL \ |
| 165 | { \ |
| 166 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 167 | .name = "Channel Mode", \ |
| 168 | .info = ac97_channel_mode_info, \ |
| 169 | .get = ac97_channel_mode_get, \ |
| 170 | .put = ac97_channel_mode_put, \ |
Takashi Iwai | 4235a31 | 2008-02-18 12:23:13 +0100 | [diff] [blame] | 171 | .private_value = 2, \ |
| 172 | } |
| 173 | /* 8ch */ |
| 174 | #define AC97_CHANNEL_MODE_8CH_CTL \ |
| 175 | { \ |
| 176 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 177 | .name = "Channel Mode", \ |
| 178 | .info = ac97_channel_mode_info, \ |
| 179 | .get = ac97_channel_mode_get, \ |
| 180 | .put = ac97_channel_mode_put, \ |
| 181 | .private_value = 4, \ |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 182 | } |
| 183 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 184 | static inline int is_surround_on(struct snd_ac97 *ac97) |
Takashi Iwai | 4525c9f | 2005-09-13 11:47:07 +0200 | [diff] [blame] | 185 | { |
| 186 | return ac97->channel_mode >= 1; |
| 187 | } |
| 188 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 189 | static inline int is_clfe_on(struct snd_ac97 *ac97) |
Takashi Iwai | 4525c9f | 2005-09-13 11:47:07 +0200 | [diff] [blame] | 190 | { |
Takashi Iwai | eb9b414 | 2005-09-13 18:39:21 +0200 | [diff] [blame] | 191 | return ac97->channel_mode >= 2; |
Takashi Iwai | 4525c9f | 2005-09-13 11:47:07 +0200 | [diff] [blame] | 192 | } |
| 193 | |
Randy Cushman | 831466f | 2006-12-19 18:42:16 +0100 | [diff] [blame] | 194 | /* system has shared jacks with surround out enabled */ |
| 195 | static inline int is_shared_surrout(struct snd_ac97 *ac97) |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 196 | { |
Randy Cushman | 831466f | 2006-12-19 18:42:16 +0100 | [diff] [blame] | 197 | return !ac97->indep_surround && is_surround_on(ac97); |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 198 | } |
| 199 | |
Randy Cushman | 831466f | 2006-12-19 18:42:16 +0100 | [diff] [blame] | 200 | /* system has shared jacks with center/lfe out enabled */ |
| 201 | static inline int is_shared_clfeout(struct snd_ac97 *ac97) |
| 202 | { |
| 203 | return !ac97->indep_surround && is_clfe_on(ac97); |
| 204 | } |
| 205 | |
| 206 | /* system has shared jacks with line in enabled */ |
| 207 | static inline int is_shared_linein(struct snd_ac97 *ac97) |
| 208 | { |
| 209 | return !ac97->indep_surround && !is_surround_on(ac97); |
| 210 | } |
| 211 | |
| 212 | /* system has shared jacks with mic in enabled */ |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 213 | static inline int is_shared_micin(struct snd_ac97 *ac97) |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 214 | { |
Randy Cushman | 831466f | 2006-12-19 18:42:16 +0100 | [diff] [blame] | 215 | return !ac97->indep_surround && !is_clfe_on(ac97); |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 216 | } |
| 217 | |
Takashi Iwai | 4235a31 | 2008-02-18 12:23:13 +0100 | [diff] [blame] | 218 | static inline int alc850_is_aux_back_surround(struct snd_ac97 *ac97) |
| 219 | { |
| 220 | return is_surround_on(ac97); |
| 221 | } |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 222 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | /* The following snd_ac97_ymf753_... items added by David Shust (dshust@shustring.com) */ |
Keita Maehara | 43115f5 | 2007-09-19 14:29:37 +0200 | [diff] [blame] | 224 | /* Modified for YMF743 by Keita Maehara <maehara@debian.org> */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | |
Keita Maehara | 1304398 | 2007-09-19 14:27:38 +0200 | [diff] [blame] | 226 | /* It is possible to indicate to the Yamaha YMF7x3 the type of |
| 227 | speakers being used. */ |
| 228 | |
| 229 | static int snd_ac97_ymf7x3_info_speaker(struct snd_kcontrol *kcontrol, |
| 230 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | { |
Takashi Iwai | 3b7a00d | 2014-10-20 18:15:36 +0200 | [diff] [blame^] | 232 | static const char * const texts[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | "Standard", "Small", "Smaller" |
| 234 | }; |
| 235 | |
Takashi Iwai | 3b7a00d | 2014-10-20 18:15:36 +0200 | [diff] [blame^] | 236 | return snd_ctl_enum_info(uinfo, 1, 3, texts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | } |
| 238 | |
Keita Maehara | 1304398 | 2007-09-19 14:27:38 +0200 | [diff] [blame] | 239 | static int snd_ac97_ymf7x3_get_speaker(struct snd_kcontrol *kcontrol, |
| 240 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 242 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | unsigned short val; |
| 244 | |
Keita Maehara | 1304398 | 2007-09-19 14:27:38 +0200 | [diff] [blame] | 245 | val = ac97->regs[AC97_YMF7X3_3D_MODE_SEL]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | val = (val >> 10) & 3; |
| 247 | if (val > 0) /* 0 = invalid */ |
| 248 | val--; |
| 249 | ucontrol->value.enumerated.item[0] = val; |
| 250 | return 0; |
| 251 | } |
| 252 | |
Keita Maehara | 1304398 | 2007-09-19 14:27:38 +0200 | [diff] [blame] | 253 | static int snd_ac97_ymf7x3_put_speaker(struct snd_kcontrol *kcontrol, |
| 254 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 256 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | unsigned short val; |
| 258 | |
| 259 | if (ucontrol->value.enumerated.item[0] > 2) |
| 260 | return -EINVAL; |
| 261 | val = (ucontrol->value.enumerated.item[0] + 1) << 10; |
Keita Maehara | 1304398 | 2007-09-19 14:27:38 +0200 | [diff] [blame] | 262 | return snd_ac97_update(ac97, AC97_YMF7X3_3D_MODE_SEL, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Keita Maehara | 1304398 | 2007-09-19 14:27:38 +0200 | [diff] [blame] | 265 | static const struct snd_kcontrol_new snd_ac97_ymf7x3_controls_speaker = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | { |
| 267 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 268 | .name = "3D Control - Speaker", |
Keita Maehara | 1304398 | 2007-09-19 14:27:38 +0200 | [diff] [blame] | 269 | .info = snd_ac97_ymf7x3_info_speaker, |
| 270 | .get = snd_ac97_ymf7x3_get_speaker, |
| 271 | .put = snd_ac97_ymf7x3_put_speaker, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | }; |
| 273 | |
Keita Maehara | 1304398 | 2007-09-19 14:27:38 +0200 | [diff] [blame] | 274 | /* It is possible to indicate to the Yamaha YMF7x3 the source to |
| 275 | direct to the S/PDIF output. */ |
| 276 | static int snd_ac97_ymf7x3_spdif_source_info(struct snd_kcontrol *kcontrol, |
| 277 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | { |
Takashi Iwai | 3b7a00d | 2014-10-20 18:15:36 +0200 | [diff] [blame^] | 279 | static const char * const texts[2] = { "AC-Link", "A/D Converter" }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | |
Takashi Iwai | 3b7a00d | 2014-10-20 18:15:36 +0200 | [diff] [blame^] | 281 | return snd_ctl_enum_info(uinfo, 1, 2, texts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | } |
| 283 | |
Keita Maehara | 1304398 | 2007-09-19 14:27:38 +0200 | [diff] [blame] | 284 | static int snd_ac97_ymf7x3_spdif_source_get(struct snd_kcontrol *kcontrol, |
| 285 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 287 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | unsigned short val; |
| 289 | |
Keita Maehara | 1304398 | 2007-09-19 14:27:38 +0200 | [diff] [blame] | 290 | val = ac97->regs[AC97_YMF7X3_DIT_CTRL]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | ucontrol->value.enumerated.item[0] = (val >> 1) & 1; |
| 292 | return 0; |
| 293 | } |
| 294 | |
Keita Maehara | 1304398 | 2007-09-19 14:27:38 +0200 | [diff] [blame] | 295 | static int snd_ac97_ymf7x3_spdif_source_put(struct snd_kcontrol *kcontrol, |
| 296 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 298 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | unsigned short val; |
| 300 | |
| 301 | if (ucontrol->value.enumerated.item[0] > 1) |
| 302 | return -EINVAL; |
| 303 | val = ucontrol->value.enumerated.item[0] << 1; |
Keita Maehara | 1304398 | 2007-09-19 14:27:38 +0200 | [diff] [blame] | 304 | return snd_ac97_update_bits(ac97, AC97_YMF7X3_DIT_CTRL, 0x0002, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | } |
| 306 | |
Keita Maehara | 43115f5 | 2007-09-19 14:29:37 +0200 | [diff] [blame] | 307 | static int patch_yamaha_ymf7x3_3d(struct snd_ac97 *ac97) |
| 308 | { |
| 309 | struct snd_kcontrol *kctl; |
| 310 | int err; |
| 311 | |
| 312 | kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97); |
| 313 | err = snd_ctl_add(ac97->bus->card, kctl); |
| 314 | if (err < 0) |
| 315 | return err; |
| 316 | strcpy(kctl->id.name, "3D Control - Wide"); |
| 317 | kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 9, 7, 0); |
| 318 | snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000); |
| 319 | err = snd_ctl_add(ac97->bus->card, |
| 320 | snd_ac97_cnew(&snd_ac97_ymf7x3_controls_speaker, |
| 321 | ac97)); |
| 322 | if (err < 0) |
| 323 | return err; |
| 324 | snd_ac97_write_cache(ac97, AC97_YMF7X3_3D_MODE_SEL, 0x0c00); |
| 325 | return 0; |
| 326 | } |
| 327 | |
| 328 | static const struct snd_kcontrol_new snd_ac97_yamaha_ymf743_controls_spdif[3] = |
| 329 | { |
| 330 | AC97_SINGLE(SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH), |
| 331 | AC97_YMF7X3_DIT_CTRL, 0, 1, 0), |
| 332 | { |
| 333 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 334 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, NONE) "Source", |
| 335 | .info = snd_ac97_ymf7x3_spdif_source_info, |
| 336 | .get = snd_ac97_ymf7x3_spdif_source_get, |
| 337 | .put = snd_ac97_ymf7x3_spdif_source_put, |
| 338 | }, |
| 339 | AC97_SINGLE(SNDRV_CTL_NAME_IEC958("", NONE, NONE) "Mute", |
| 340 | AC97_YMF7X3_DIT_CTRL, 2, 1, 1) |
| 341 | }; |
| 342 | |
| 343 | static int patch_yamaha_ymf743_build_spdif(struct snd_ac97 *ac97) |
| 344 | { |
| 345 | int err; |
| 346 | |
| 347 | err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3); |
| 348 | if (err < 0) |
| 349 | return err; |
| 350 | err = patch_build_controls(ac97, |
| 351 | snd_ac97_yamaha_ymf743_controls_spdif, 3); |
| 352 | if (err < 0) |
| 353 | return err; |
| 354 | /* set default PCM S/PDIF params */ |
| 355 | /* PCM audio,no copyright,no preemphasis,PCM coder,original */ |
| 356 | snd_ac97_write_cache(ac97, AC97_YMF7X3_DIT_CTRL, 0xa201); |
| 357 | return 0; |
| 358 | } |
| 359 | |
Hanno Boeck | 3e8b3b9 | 2011-01-14 19:14:47 +0100 | [diff] [blame] | 360 | static const struct snd_ac97_build_ops patch_yamaha_ymf743_ops = { |
Keita Maehara | 43115f5 | 2007-09-19 14:29:37 +0200 | [diff] [blame] | 361 | .build_spdif = patch_yamaha_ymf743_build_spdif, |
| 362 | .build_3d = patch_yamaha_ymf7x3_3d, |
| 363 | }; |
| 364 | |
| 365 | static int patch_yamaha_ymf743(struct snd_ac97 *ac97) |
| 366 | { |
| 367 | ac97->build_ops = &patch_yamaha_ymf743_ops; |
| 368 | ac97->caps |= AC97_BC_BASS_TREBLE; |
| 369 | ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */ |
| 370 | ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */ |
| 371 | ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */ |
| 372 | return 0; |
| 373 | } |
| 374 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | /* The AC'97 spec states that the S/PDIF signal is to be output at pin 48. |
| 376 | The YMF753 will output the S/PDIF signal to pin 43, 47 (EAPD), or 48. |
| 377 | By default, no output pin is selected, and the S/PDIF signal is not output. |
| 378 | There is also a bit to mute S/PDIF output in a vendor-specific register. */ |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 379 | static int snd_ac97_ymf753_spdif_output_pin_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | { |
Takashi Iwai | 3b7a00d | 2014-10-20 18:15:36 +0200 | [diff] [blame^] | 381 | static const char * const texts[3] = { "Disabled", "Pin 43", "Pin 48" }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | |
Takashi Iwai | 3b7a00d | 2014-10-20 18:15:36 +0200 | [diff] [blame^] | 383 | return snd_ctl_enum_info(uinfo, 1, 3, texts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | } |
| 385 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 386 | static int snd_ac97_ymf753_spdif_output_pin_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 388 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | unsigned short val; |
| 390 | |
Keita Maehara | 1304398 | 2007-09-19 14:27:38 +0200 | [diff] [blame] | 391 | val = ac97->regs[AC97_YMF7X3_DIT_CTRL]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | ucontrol->value.enumerated.item[0] = (val & 0x0008) ? 2 : (val & 0x0020) ? 1 : 0; |
| 393 | return 0; |
| 394 | } |
| 395 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 396 | static int snd_ac97_ymf753_spdif_output_pin_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 398 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | unsigned short val; |
| 400 | |
| 401 | if (ucontrol->value.enumerated.item[0] > 2) |
| 402 | return -EINVAL; |
| 403 | val = (ucontrol->value.enumerated.item[0] == 2) ? 0x0008 : |
| 404 | (ucontrol->value.enumerated.item[0] == 1) ? 0x0020 : 0; |
Keita Maehara | 1304398 | 2007-09-19 14:27:38 +0200 | [diff] [blame] | 405 | return snd_ac97_update_bits(ac97, AC97_YMF7X3_DIT_CTRL, 0x0028, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | /* The following can be used to direct S/PDIF output to pin 47 (EAPD). |
| 407 | snd_ac97_write_cache(ac97, 0x62, snd_ac97_read(ac97, 0x62) | 0x0008); */ |
| 408 | } |
| 409 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 410 | static const struct snd_kcontrol_new snd_ac97_ymf753_controls_spdif[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | { |
| 412 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 413 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source", |
Keita Maehara | 1304398 | 2007-09-19 14:27:38 +0200 | [diff] [blame] | 414 | .info = snd_ac97_ymf7x3_spdif_source_info, |
| 415 | .get = snd_ac97_ymf7x3_spdif_source_get, |
| 416 | .put = snd_ac97_ymf7x3_spdif_source_put, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | }, |
| 418 | { |
| 419 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 420 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Output Pin", |
| 421 | .info = snd_ac97_ymf753_spdif_output_pin_info, |
| 422 | .get = snd_ac97_ymf753_spdif_output_pin_get, |
| 423 | .put = snd_ac97_ymf753_spdif_output_pin_put, |
| 424 | }, |
Keita Maehara | 1304398 | 2007-09-19 14:27:38 +0200 | [diff] [blame] | 425 | AC97_SINGLE(SNDRV_CTL_NAME_IEC958("", NONE, NONE) "Mute", |
| 426 | AC97_YMF7X3_DIT_CTRL, 2, 1, 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | }; |
| 428 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 429 | static int patch_yamaha_ymf753_post_spdif(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | { |
| 431 | int err; |
| 432 | |
| 433 | if ((err = patch_build_controls(ac97, snd_ac97_ymf753_controls_spdif, ARRAY_SIZE(snd_ac97_ymf753_controls_spdif))) < 0) |
| 434 | return err; |
| 435 | return 0; |
| 436 | } |
| 437 | |
Hanno Boeck | 3e8b3b9 | 2011-01-14 19:14:47 +0100 | [diff] [blame] | 438 | static const struct snd_ac97_build_ops patch_yamaha_ymf753_ops = { |
Keita Maehara | 1304398 | 2007-09-19 14:27:38 +0200 | [diff] [blame] | 439 | .build_3d = patch_yamaha_ymf7x3_3d, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | .build_post_spdif = patch_yamaha_ymf753_post_spdif |
| 441 | }; |
| 442 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 443 | static int patch_yamaha_ymf753(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | { |
| 445 | /* Patch for Yamaha YMF753, Copyright (c) by David Shust, dshust@shustring.com. |
| 446 | This chip has nonstandard and extended behaviour with regard to its S/PDIF output. |
| 447 | The AC'97 spec states that the S/PDIF signal is to be output at pin 48. |
| 448 | The YMF753 will ouput the S/PDIF signal to pin 43, 47 (EAPD), or 48. |
| 449 | By default, no output pin is selected, and the S/PDIF signal is not output. |
| 450 | There is also a bit to mute S/PDIF output in a vendor-specific register. |
| 451 | */ |
| 452 | ac97->build_ops = &patch_yamaha_ymf753_ops; |
| 453 | ac97->caps |= AC97_BC_BASS_TREBLE; |
| 454 | ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */ |
| 455 | return 0; |
| 456 | } |
| 457 | |
| 458 | /* |
Liam Girdwood | d331124 | 2008-10-12 13:17:36 +0100 | [diff] [blame] | 459 | * May 2, 2003 Liam Girdwood <lrg@slimlogic.co.uk> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | * removed broken wolfson00 patch. |
| 461 | * added support for WM9705,WM9708,WM9709,WM9710,WM9711,WM9712 and WM9717. |
| 462 | */ |
| 463 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 464 | static const struct snd_kcontrol_new wm97xx_snd_ac97_controls[] = { |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 465 | AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1), |
| 466 | AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1), |
| 467 | }; |
| 468 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 469 | static int patch_wolfson_wm9703_specific(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | { |
| 471 | /* This is known to work for the ViewSonic ViewPad 1000 |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 472 | * Randolph Bentson <bentson@holmsjoen.com> |
| 473 | * WM9703/9707/9708/9717 |
| 474 | */ |
| 475 | int err, i; |
| 476 | |
| 477 | for (i = 0; i < ARRAY_SIZE(wm97xx_snd_ac97_controls); i++) { |
| 478 | if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm97xx_snd_ac97_controls[i], ac97))) < 0) |
| 479 | return err; |
| 480 | } |
| 481 | snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | return 0; |
| 483 | } |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 484 | |
Hanno Boeck | 3e8b3b9 | 2011-01-14 19:14:47 +0100 | [diff] [blame] | 485 | static const struct snd_ac97_build_ops patch_wolfson_wm9703_ops = { |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 486 | .build_specific = patch_wolfson_wm9703_specific, |
| 487 | }; |
| 488 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 489 | static int patch_wolfson03(struct snd_ac97 * ac97) |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 490 | { |
| 491 | ac97->build_ops = &patch_wolfson_wm9703_ops; |
| 492 | return 0; |
| 493 | } |
| 494 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 495 | static const struct snd_kcontrol_new wm9704_snd_ac97_controls[] = { |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 496 | AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1), |
| 497 | AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1), |
| 498 | AC97_DOUBLE("Rear Playback Volume", AC97_WM9704_RMIXER_VOL, 8, 0, 31, 1), |
| 499 | AC97_SINGLE("Rear Playback Switch", AC97_WM9704_RMIXER_VOL, 15, 1, 1), |
| 500 | AC97_DOUBLE("Rear DAC Volume", AC97_WM9704_RPCM_VOL, 8, 0, 31, 1), |
| 501 | AC97_DOUBLE("Surround Volume", AC97_SURROUND_MASTER, 8, 0, 31, 1), |
| 502 | }; |
| 503 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 504 | static int patch_wolfson_wm9704_specific(struct snd_ac97 * ac97) |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 505 | { |
| 506 | int err, i; |
| 507 | for (i = 0; i < ARRAY_SIZE(wm9704_snd_ac97_controls); i++) { |
| 508 | if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9704_snd_ac97_controls[i], ac97))) < 0) |
| 509 | return err; |
| 510 | } |
| 511 | /* patch for DVD noise */ |
| 512 | snd_ac97_write_cache(ac97, AC97_WM9704_TEST, 0x0200); |
| 513 | return 0; |
| 514 | } |
| 515 | |
Hanno Boeck | 3e8b3b9 | 2011-01-14 19:14:47 +0100 | [diff] [blame] | 516 | static const struct snd_ac97_build_ops patch_wolfson_wm9704_ops = { |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 517 | .build_specific = patch_wolfson_wm9704_specific, |
| 518 | }; |
| 519 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 520 | static int patch_wolfson04(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | { |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 522 | /* WM9704M/9704Q */ |
| 523 | ac97->build_ops = &patch_wolfson_wm9704_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | return 0; |
| 525 | } |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 526 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 527 | static int patch_wolfson05(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | { |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 529 | /* WM9705, WM9710 */ |
Krzysztof Helt | dd3533e | 2010-01-01 19:05:43 +0100 | [diff] [blame] | 530 | ac97->build_ops = &patch_wolfson_wm9703_ops; |
Rodolfo Giometti | 1459c78 | 2006-06-19 15:04:54 +0200 | [diff] [blame] | 531 | #ifdef CONFIG_TOUCHSCREEN_WM9705 |
| 532 | /* WM9705 touchscreen uses AUX and VIDEO for touch */ |
Liam Girdwood | 8f88820 | 2006-09-07 18:07:46 +0200 | [diff] [blame] | 533 | ac97->flags |= AC97_HAS_NO_VIDEO | AC97_HAS_NO_AUX; |
Rodolfo Giometti | 1459c78 | 2006-06-19 15:04:54 +0200 | [diff] [blame] | 534 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | return 0; |
| 536 | } |
| 537 | |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 538 | static const char* wm9711_alc_select[] = {"None", "Left", "Right", "Stereo"}; |
| 539 | static const char* wm9711_alc_mix[] = {"Stereo", "Right", "Left", "None"}; |
| 540 | static const char* wm9711_out3_src[] = {"Left", "VREF", "Left + Right", "Mono"}; |
| 541 | static const char* wm9711_out3_lrsrc[] = {"Master Mix", "Headphone Mix"}; |
| 542 | static const char* wm9711_rec_adc[] = {"Stereo", "Left", "Right", "Mute"}; |
| 543 | static const char* wm9711_base[] = {"Linear Control", "Adaptive Boost"}; |
| 544 | static const char* wm9711_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"}; |
| 545 | static const char* wm9711_mic[] = {"Mic 1", "Differential", "Mic 2", "Stereo"}; |
| 546 | static const char* wm9711_rec_sel[] = |
| 547 | {"Mic 1", "NC", "NC", "Master Mix", "Line", "Headphone Mix", "Phone Mix", "Phone"}; |
| 548 | static const char* wm9711_ng_type[] = {"Constant Gain", "Mute"}; |
| 549 | |
| 550 | static const struct ac97_enum wm9711_enum[] = { |
| 551 | AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9711_alc_select), |
| 552 | AC97_ENUM_SINGLE(AC97_VIDEO, 10, 4, wm9711_alc_mix), |
| 553 | AC97_ENUM_SINGLE(AC97_AUX, 9, 4, wm9711_out3_src), |
| 554 | AC97_ENUM_SINGLE(AC97_AUX, 8, 2, wm9711_out3_lrsrc), |
| 555 | AC97_ENUM_SINGLE(AC97_REC_SEL, 12, 4, wm9711_rec_adc), |
| 556 | AC97_ENUM_SINGLE(AC97_MASTER_TONE, 15, 2, wm9711_base), |
| 557 | AC97_ENUM_DOUBLE(AC97_REC_GAIN, 14, 6, 2, wm9711_rec_gain), |
| 558 | AC97_ENUM_SINGLE(AC97_MIC, 5, 4, wm9711_mic), |
| 559 | AC97_ENUM_DOUBLE(AC97_REC_SEL, 8, 0, 8, wm9711_rec_sel), |
| 560 | AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9711_ng_type), |
| 561 | }; |
| 562 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 563 | static const struct snd_kcontrol_new wm9711_snd_ac97_controls[] = { |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 564 | AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0), |
| 565 | AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0), |
| 566 | AC97_SINGLE("ALC Decay Time", AC97_CODEC_CLASS_REV, 4, 15, 0), |
| 567 | AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0), |
| 568 | AC97_ENUM("ALC Function", wm9711_enum[0]), |
| 569 | AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 1), |
| 570 | AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 1), |
| 571 | AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0), |
| 572 | AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0), |
| 573 | AC97_ENUM("ALC NG Type", wm9711_enum[9]), |
| 574 | AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 1), |
| 575 | |
| 576 | AC97_SINGLE("Side Tone Switch", AC97_VIDEO, 15, 1, 1), |
| 577 | AC97_SINGLE("Side Tone Volume", AC97_VIDEO, 12, 7, 1), |
| 578 | AC97_ENUM("ALC Headphone Mux", wm9711_enum[1]), |
| 579 | AC97_SINGLE("ALC Headphone Volume", AC97_VIDEO, 7, 7, 1), |
| 580 | |
| 581 | AC97_SINGLE("Out3 Switch", AC97_AUX, 15, 1, 1), |
Luke Zhang | 2aedbda | 2006-09-26 15:28:41 +0200 | [diff] [blame] | 582 | AC97_SINGLE("Out3 ZC Switch", AC97_AUX, 7, 1, 0), |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 583 | AC97_ENUM("Out3 Mux", wm9711_enum[2]), |
| 584 | AC97_ENUM("Out3 LR Mux", wm9711_enum[3]), |
| 585 | AC97_SINGLE("Out3 Volume", AC97_AUX, 0, 31, 1), |
| 586 | |
| 587 | AC97_SINGLE("Beep to Headphone Switch", AC97_PC_BEEP, 15, 1, 1), |
| 588 | AC97_SINGLE("Beep to Headphone Volume", AC97_PC_BEEP, 12, 7, 1), |
| 589 | AC97_SINGLE("Beep to Side Tone Switch", AC97_PC_BEEP, 11, 1, 1), |
| 590 | AC97_SINGLE("Beep to Side Tone Volume", AC97_PC_BEEP, 8, 7, 1), |
| 591 | AC97_SINGLE("Beep to Phone Switch", AC97_PC_BEEP, 7, 1, 1), |
| 592 | AC97_SINGLE("Beep to Phone Volume", AC97_PC_BEEP, 4, 7, 1), |
| 593 | |
| 594 | AC97_SINGLE("Aux to Headphone Switch", AC97_CD, 15, 1, 1), |
| 595 | AC97_SINGLE("Aux to Headphone Volume", AC97_CD, 12, 7, 1), |
| 596 | AC97_SINGLE("Aux to Side Tone Switch", AC97_CD, 11, 1, 1), |
| 597 | AC97_SINGLE("Aux to Side Tone Volume", AC97_CD, 8, 7, 1), |
| 598 | AC97_SINGLE("Aux to Phone Switch", AC97_CD, 7, 1, 1), |
| 599 | AC97_SINGLE("Aux to Phone Volume", AC97_CD, 4, 7, 1), |
| 600 | |
| 601 | AC97_SINGLE("Phone to Headphone Switch", AC97_PHONE, 15, 1, 1), |
| 602 | AC97_SINGLE("Phone to Master Switch", AC97_PHONE, 14, 1, 1), |
| 603 | |
| 604 | AC97_SINGLE("Line to Headphone Switch", AC97_LINE, 15, 1, 1), |
| 605 | AC97_SINGLE("Line to Master Switch", AC97_LINE, 14, 1, 1), |
| 606 | AC97_SINGLE("Line to Phone Switch", AC97_LINE, 13, 1, 1), |
| 607 | |
| 608 | AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PCM, 15, 1, 1), |
| 609 | AC97_SINGLE("PCM Playback to Master Switch", AC97_PCM, 14, 1, 1), |
| 610 | AC97_SINGLE("PCM Playback to Phone Switch", AC97_PCM, 13, 1, 1), |
| 611 | |
| 612 | AC97_SINGLE("Capture 20dB Boost Switch", AC97_REC_SEL, 14, 1, 0), |
| 613 | AC97_ENUM("Capture to Phone Mux", wm9711_enum[4]), |
| 614 | AC97_SINGLE("Capture to Phone 20dB Boost Switch", AC97_REC_SEL, 11, 1, 1), |
| 615 | AC97_ENUM("Capture Select", wm9711_enum[8]), |
| 616 | |
| 617 | AC97_SINGLE("3D Upper Cut-off Switch", AC97_3D_CONTROL, 5, 1, 1), |
| 618 | AC97_SINGLE("3D Lower Cut-off Switch", AC97_3D_CONTROL, 4, 1, 1), |
| 619 | |
| 620 | AC97_ENUM("Bass Control", wm9711_enum[5]), |
| 621 | AC97_SINGLE("Bass Cut-off Switch", AC97_MASTER_TONE, 12, 1, 1), |
| 622 | AC97_SINGLE("Tone Cut-off Switch", AC97_MASTER_TONE, 4, 1, 1), |
| 623 | AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_MASTER_TONE, 6, 1, 0), |
| 624 | |
| 625 | AC97_SINGLE("ADC Switch", AC97_REC_GAIN, 15, 1, 1), |
| 626 | AC97_ENUM("Capture Volume Steps", wm9711_enum[6]), |
Luke Zhang | 2aedbda | 2006-09-26 15:28:41 +0200 | [diff] [blame] | 627 | AC97_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 63, 1), |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 628 | AC97_SINGLE("Capture ZC Switch", AC97_REC_GAIN, 7, 1, 0), |
| 629 | |
| 630 | AC97_SINGLE("Mic 1 to Phone Switch", AC97_MIC, 14, 1, 1), |
| 631 | AC97_SINGLE("Mic 2 to Phone Switch", AC97_MIC, 13, 1, 1), |
| 632 | AC97_ENUM("Mic Select Source", wm9711_enum[7]), |
Luke Zhang | 2aedbda | 2006-09-26 15:28:41 +0200 | [diff] [blame] | 633 | AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1), |
| 634 | AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1), |
James Courtier-Dutton | d7f6f11 | 2006-04-11 21:47:27 +0100 | [diff] [blame] | 635 | AC97_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 7, 1, 0), |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 636 | |
Juergen Beisert | 0264b3b | 2008-06-06 17:02:57 +0200 | [diff] [blame] | 637 | AC97_SINGLE("Master Left Inv Switch", AC97_MASTER, 6, 1, 0), |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 638 | AC97_SINGLE("Master ZC Switch", AC97_MASTER, 7, 1, 0), |
| 639 | AC97_SINGLE("Headphone ZC Switch", AC97_HEADPHONE, 7, 1, 0), |
| 640 | AC97_SINGLE("Mono ZC Switch", AC97_MASTER_MONO, 7, 1, 0), |
| 641 | }; |
| 642 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 643 | static int patch_wolfson_wm9711_specific(struct snd_ac97 * ac97) |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 644 | { |
| 645 | int err, i; |
| 646 | |
| 647 | for (i = 0; i < ARRAY_SIZE(wm9711_snd_ac97_controls); i++) { |
| 648 | if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9711_snd_ac97_controls[i], ac97))) < 0) |
| 649 | return err; |
| 650 | } |
| 651 | snd_ac97_write_cache(ac97, AC97_CODEC_CLASS_REV, 0x0808); |
| 652 | snd_ac97_write_cache(ac97, AC97_PCI_SVID, 0x0808); |
| 653 | snd_ac97_write_cache(ac97, AC97_VIDEO, 0x0808); |
| 654 | snd_ac97_write_cache(ac97, AC97_AUX, 0x0808); |
| 655 | snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808); |
| 656 | snd_ac97_write_cache(ac97, AC97_CD, 0x0000); |
| 657 | return 0; |
| 658 | } |
| 659 | |
Hanno Boeck | 3e8b3b9 | 2011-01-14 19:14:47 +0100 | [diff] [blame] | 660 | static const struct snd_ac97_build_ops patch_wolfson_wm9711_ops = { |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 661 | .build_specific = patch_wolfson_wm9711_specific, |
| 662 | }; |
| 663 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 664 | static int patch_wolfson11(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | { |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 666 | /* WM9711, WM9712 */ |
| 667 | ac97->build_ops = &patch_wolfson_wm9711_ops; |
| 668 | |
| 669 | ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_MIC | |
| 670 | AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD; |
| 671 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | return 0; |
| 673 | } |
| 674 | |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 675 | static const char* wm9713_mic_mixer[] = {"Stereo", "Mic 1", "Mic 2", "Mute"}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | static const char* wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"}; |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 677 | static const char* wm9713_rec_src[] = |
| 678 | {"Mic 1", "Mic 2", "Line", "Mono In", "Headphone Mix", "Master Mix", |
| 679 | "Mono Mix", "Zh"}; |
| 680 | static const char* wm9713_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"}; |
| 681 | static const char* wm9713_alc_select[] = {"None", "Left", "Right", "Stereo"}; |
| 682 | static const char* wm9713_mono_pga[] = {"Vmid", "Zh", "Mono Mix", "Inv 1"}; |
| 683 | static const char* wm9713_spk_pga[] = |
| 684 | {"Vmid", "Zh", "Headphone Mix", "Master Mix", "Inv", "NC", "NC", "NC"}; |
| 685 | static const char* wm9713_hp_pga[] = {"Vmid", "Zh", "Headphone Mix", "NC"}; |
| 686 | static const char* wm9713_out3_pga[] = {"Vmid", "Zh", "Inv 1", "NC"}; |
| 687 | static const char* wm9713_out4_pga[] = {"Vmid", "Zh", "Inv 2", "NC"}; |
| 688 | static const char* wm9713_dac_inv[] = |
| 689 | {"Off", "Mono Mix", "Master Mix", "Headphone Mix L", "Headphone Mix R", |
| 690 | "Headphone Mix Mono", "NC", "Vmid"}; |
| 691 | static const char* wm9713_base[] = {"Linear Control", "Adaptive Boost"}; |
| 692 | static const char* wm9713_ng_type[] = {"Constant Gain", "Mute"}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | |
| 694 | static const struct ac97_enum wm9713_enum[] = { |
| 695 | AC97_ENUM_SINGLE(AC97_LINE, 3, 4, wm9713_mic_mixer), |
| 696 | AC97_ENUM_SINGLE(AC97_VIDEO, 14, 4, wm9713_rec_mux), |
| 697 | AC97_ENUM_SINGLE(AC97_VIDEO, 9, 4, wm9713_rec_mux), |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 698 | AC97_ENUM_DOUBLE(AC97_VIDEO, 3, 0, 8, wm9713_rec_src), |
| 699 | AC97_ENUM_DOUBLE(AC97_CD, 14, 6, 2, wm9713_rec_gain), |
| 700 | AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9713_alc_select), |
| 701 | AC97_ENUM_SINGLE(AC97_REC_GAIN, 14, 4, wm9713_mono_pga), |
| 702 | AC97_ENUM_DOUBLE(AC97_REC_GAIN, 11, 8, 8, wm9713_spk_pga), |
| 703 | AC97_ENUM_DOUBLE(AC97_REC_GAIN, 6, 4, 4, wm9713_hp_pga), |
| 704 | AC97_ENUM_SINGLE(AC97_REC_GAIN, 2, 4, wm9713_out3_pga), |
| 705 | AC97_ENUM_SINGLE(AC97_REC_GAIN, 0, 4, wm9713_out4_pga), |
| 706 | AC97_ENUM_DOUBLE(AC97_REC_GAIN_MIC, 13, 10, 8, wm9713_dac_inv), |
| 707 | AC97_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, wm9713_base), |
| 708 | AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9713_ng_type), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | }; |
| 710 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 711 | static const struct snd_kcontrol_new wm13_snd_ac97_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | AC97_DOUBLE("Line In Volume", AC97_PC_BEEP, 8, 0, 31, 1), |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 713 | AC97_SINGLE("Line In to Headphone Switch", AC97_PC_BEEP, 15, 1, 1), |
| 714 | AC97_SINGLE("Line In to Master Switch", AC97_PC_BEEP, 14, 1, 1), |
| 715 | AC97_SINGLE("Line In to Mono Switch", AC97_PC_BEEP, 13, 1, 1), |
| 716 | |
| 717 | AC97_DOUBLE("PCM Playback Volume", AC97_PHONE, 8, 0, 31, 1), |
| 718 | AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PHONE, 15, 1, 1), |
| 719 | AC97_SINGLE("PCM Playback to Master Switch", AC97_PHONE, 14, 1, 1), |
| 720 | AC97_SINGLE("PCM Playback to Mono Switch", AC97_PHONE, 13, 1, 1), |
| 721 | |
| 722 | AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1), |
| 723 | AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1), |
| 724 | AC97_SINGLE("Mic 1 to Mono Switch", AC97_LINE, 7, 1, 1), |
| 725 | AC97_SINGLE("Mic 2 to Mono Switch", AC97_LINE, 6, 1, 1), |
James Courtier-Dutton | d7f6f11 | 2006-04-11 21:47:27 +0100 | [diff] [blame] | 726 | AC97_SINGLE("Mic Boost (+20dB) Switch", AC97_LINE, 5, 1, 0), |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 727 | AC97_ENUM("Mic to Headphone Mux", wm9713_enum[0]), |
| 728 | AC97_SINGLE("Mic Headphone Mixer Volume", AC97_LINE, 0, 7, 1), |
| 729 | |
| 730 | AC97_SINGLE("Capture Switch", AC97_CD, 15, 1, 1), |
| 731 | AC97_ENUM("Capture Volume Steps", wm9713_enum[4]), |
| 732 | AC97_DOUBLE("Capture Volume", AC97_CD, 8, 0, 15, 0), |
| 733 | AC97_SINGLE("Capture ZC Switch", AC97_CD, 7, 1, 0), |
| 734 | |
| 735 | AC97_ENUM("Capture to Headphone Mux", wm9713_enum[1]), |
| 736 | AC97_SINGLE("Capture to Headphone Volume", AC97_VIDEO, 11, 7, 1), |
| 737 | AC97_ENUM("Capture to Mono Mux", wm9713_enum[2]), |
| 738 | AC97_SINGLE("Capture to Mono Boost (+20dB) Switch", AC97_VIDEO, 8, 1, 0), |
| 739 | AC97_SINGLE("Capture ADC Boost (+20dB) Switch", AC97_VIDEO, 6, 1, 0), |
| 740 | AC97_ENUM("Capture Select", wm9713_enum[3]), |
| 741 | |
| 742 | AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0), |
| 743 | AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0), |
| 744 | AC97_SINGLE("ALC Decay Time ", AC97_CODEC_CLASS_REV, 4, 15, 0), |
| 745 | AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0), |
| 746 | AC97_ENUM("ALC Function", wm9713_enum[5]), |
| 747 | AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 0), |
| 748 | AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 0), |
| 749 | AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0), |
| 750 | AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0), |
| 751 | AC97_ENUM("ALC NG Type", wm9713_enum[13]), |
| 752 | AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 0), |
| 753 | |
| 754 | AC97_DOUBLE("Master ZC Switch", AC97_MASTER, 14, 6, 1, 0), |
| 755 | AC97_DOUBLE("Headphone ZC Switch", AC97_HEADPHONE, 14, 6, 1, 0), |
| 756 | AC97_DOUBLE("Out3/4 ZC Switch", AC97_MASTER_MONO, 14, 6, 1, 0), |
| 757 | AC97_SINGLE("Master Right Switch", AC97_MASTER, 7, 1, 1), |
| 758 | AC97_SINGLE("Headphone Right Switch", AC97_HEADPHONE, 7, 1, 1), |
| 759 | AC97_SINGLE("Out3/4 Right Switch", AC97_MASTER_MONO, 7, 1, 1), |
| 760 | |
| 761 | AC97_SINGLE("Mono In to Headphone Switch", AC97_MASTER_TONE, 15, 1, 1), |
| 762 | AC97_SINGLE("Mono In to Master Switch", AC97_MASTER_TONE, 14, 1, 1), |
| 763 | AC97_SINGLE("Mono In Volume", AC97_MASTER_TONE, 8, 31, 1), |
| 764 | AC97_SINGLE("Mono Switch", AC97_MASTER_TONE, 7, 1, 1), |
| 765 | AC97_SINGLE("Mono ZC Switch", AC97_MASTER_TONE, 6, 1, 0), |
| 766 | AC97_SINGLE("Mono Volume", AC97_MASTER_TONE, 0, 31, 1), |
| 767 | |
Jaroslav Kysela | d355c82a | 2009-11-03 15:47:25 +0100 | [diff] [blame] | 768 | AC97_SINGLE("Beep to Headphone Switch", AC97_AUX, 15, 1, 1), |
| 769 | AC97_SINGLE("Beep to Headphone Volume", AC97_AUX, 12, 7, 1), |
| 770 | AC97_SINGLE("Beep to Master Switch", AC97_AUX, 11, 1, 1), |
| 771 | AC97_SINGLE("Beep to Master Volume", AC97_AUX, 8, 7, 1), |
| 772 | AC97_SINGLE("Beep to Mono Switch", AC97_AUX, 7, 1, 1), |
| 773 | AC97_SINGLE("Beep to Mono Volume", AC97_AUX, 4, 7, 1), |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 774 | |
| 775 | AC97_SINGLE("Voice to Headphone Switch", AC97_PCM, 15, 1, 1), |
| 776 | AC97_SINGLE("Voice to Headphone Volume", AC97_PCM, 12, 7, 1), |
| 777 | AC97_SINGLE("Voice to Master Switch", AC97_PCM, 11, 1, 1), |
| 778 | AC97_SINGLE("Voice to Master Volume", AC97_PCM, 8, 7, 1), |
| 779 | AC97_SINGLE("Voice to Mono Switch", AC97_PCM, 7, 1, 1), |
| 780 | AC97_SINGLE("Voice to Mono Volume", AC97_PCM, 4, 7, 1), |
| 781 | |
| 782 | AC97_SINGLE("Aux to Headphone Switch", AC97_REC_SEL, 15, 1, 1), |
| 783 | AC97_SINGLE("Aux to Headphone Volume", AC97_REC_SEL, 12, 7, 1), |
| 784 | AC97_SINGLE("Aux to Master Switch", AC97_REC_SEL, 11, 1, 1), |
| 785 | AC97_SINGLE("Aux to Master Volume", AC97_REC_SEL, 8, 7, 1), |
| 786 | AC97_SINGLE("Aux to Mono Switch", AC97_REC_SEL, 7, 1, 1), |
| 787 | AC97_SINGLE("Aux to Mono Volume", AC97_REC_SEL, 4, 7, 1), |
| 788 | |
| 789 | AC97_ENUM("Mono Input Mux", wm9713_enum[6]), |
| 790 | AC97_ENUM("Master Input Mux", wm9713_enum[7]), |
| 791 | AC97_ENUM("Headphone Input Mux", wm9713_enum[8]), |
| 792 | AC97_ENUM("Out 3 Input Mux", wm9713_enum[9]), |
| 793 | AC97_ENUM("Out 4 Input Mux", wm9713_enum[10]), |
| 794 | |
| 795 | AC97_ENUM("Bass Control", wm9713_enum[12]), |
| 796 | AC97_SINGLE("Bass Cut-off Switch", AC97_GENERAL_PURPOSE, 12, 1, 1), |
| 797 | AC97_SINGLE("Tone Cut-off Switch", AC97_GENERAL_PURPOSE, 4, 1, 1), |
| 798 | AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_GENERAL_PURPOSE, 6, 1, 0), |
| 799 | AC97_SINGLE("Bass Volume", AC97_GENERAL_PURPOSE, 8, 15, 1), |
| 800 | AC97_SINGLE("Tone Volume", AC97_GENERAL_PURPOSE, 0, 15, 1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | }; |
| 802 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 803 | static const struct snd_kcontrol_new wm13_snd_ac97_controls_3d[] = { |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 804 | AC97_ENUM("Inv Input Mux", wm9713_enum[11]), |
| 805 | AC97_SINGLE("3D Upper Cut-off Switch", AC97_REC_GAIN_MIC, 5, 1, 0), |
| 806 | AC97_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC, 4, 1, 0), |
| 807 | AC97_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | }; |
| 809 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 810 | static int patch_wolfson_wm9713_3d (struct snd_ac97 * ac97) |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 811 | { |
| 812 | int err, i; |
| 813 | |
| 814 | for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_3d); i++) { |
| 815 | if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_3d[i], ac97))) < 0) |
| 816 | return err; |
| 817 | } |
| 818 | return 0; |
| 819 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 821 | static int patch_wolfson_wm9713_specific(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | { |
| 823 | int err, i; |
| 824 | |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 825 | for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls); i++) { |
| 826 | if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls[i], ac97))) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | return err; |
| 828 | } |
| 829 | snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | snd_ac97_write_cache(ac97, AC97_PHONE, 0x0808); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | snd_ac97_write_cache(ac97, AC97_MIC, 0x0808); |
| 832 | snd_ac97_write_cache(ac97, AC97_LINE, 0x00da); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | snd_ac97_write_cache(ac97, AC97_CD, 0x0808); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | snd_ac97_write_cache(ac97, AC97_VIDEO, 0xd612); |
| 835 | snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x1ba0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | return 0; |
| 837 | } |
| 838 | |
| 839 | #ifdef CONFIG_PM |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 840 | static void patch_wolfson_wm9713_suspend (struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | { |
| 842 | snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xfeff); |
| 843 | snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0xffff); |
| 844 | } |
| 845 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 846 | static void patch_wolfson_wm9713_resume (struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | { |
| 848 | snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00); |
| 849 | snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810); |
| 850 | snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0); |
| 851 | } |
| 852 | #endif |
| 853 | |
Hanno Boeck | 3e8b3b9 | 2011-01-14 19:14:47 +0100 | [diff] [blame] | 854 | static const struct snd_ac97_build_ops patch_wolfson_wm9713_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | .build_specific = patch_wolfson_wm9713_specific, |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 856 | .build_3d = patch_wolfson_wm9713_3d, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | #ifdef CONFIG_PM |
| 858 | .suspend = patch_wolfson_wm9713_suspend, |
| 859 | .resume = patch_wolfson_wm9713_resume |
| 860 | #endif |
| 861 | }; |
| 862 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 863 | static int patch_wolfson13(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | { |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 865 | /* WM9713, WM9714 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | ac97->build_ops = &patch_wolfson_wm9713_ops; |
| 867 | |
| 868 | ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_PHONE | |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 869 | AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD | AC97_HAS_NO_TONE | |
| 870 | AC97_HAS_NO_STD_PCM; |
Liam Girdwood | 064d211 | 2005-08-05 10:25:08 +0200 | [diff] [blame] | 871 | ac97->scaps &= ~AC97_SCAP_MODEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | |
| 873 | snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00); |
| 874 | snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810); |
| 875 | snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0); |
| 876 | |
| 877 | return 0; |
| 878 | } |
| 879 | |
| 880 | /* |
| 881 | * Tritech codec |
| 882 | */ |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 883 | static int patch_tritech_tr28028(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | { |
| 885 | snd_ac97_write_cache(ac97, 0x26, 0x0300); |
| 886 | snd_ac97_write_cache(ac97, 0x26, 0x0000); |
| 887 | snd_ac97_write_cache(ac97, AC97_SURROUND_MASTER, 0x0000); |
| 888 | snd_ac97_write_cache(ac97, AC97_SPDIF, 0x0000); |
| 889 | return 0; |
| 890 | } |
| 891 | |
| 892 | /* |
| 893 | * Sigmatel STAC97xx codecs |
| 894 | */ |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 895 | static int patch_sigmatel_stac9700_3d(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 897 | struct snd_kcontrol *kctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | int err; |
| 899 | |
| 900 | if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0) |
| 901 | return err; |
| 902 | strcpy(kctl->id.name, "3D Control Sigmatel - Depth"); |
| 903 | kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0); |
| 904 | snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000); |
| 905 | return 0; |
| 906 | } |
| 907 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 908 | static int patch_sigmatel_stac9708_3d(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 910 | struct snd_kcontrol *kctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | int err; |
| 912 | |
| 913 | if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0) |
| 914 | return err; |
| 915 | strcpy(kctl->id.name, "3D Control Sigmatel - Depth"); |
| 916 | kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 0, 3, 0); |
| 917 | if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0) |
| 918 | return err; |
| 919 | strcpy(kctl->id.name, "3D Control Sigmatel - Rear Depth"); |
| 920 | kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0); |
| 921 | snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000); |
| 922 | return 0; |
| 923 | } |
| 924 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 925 | static const struct snd_kcontrol_new snd_ac97_sigmatel_4speaker = |
Andreas Mohr | afe6d7e | 2009-05-22 17:48:58 +0200 | [diff] [blame] | 926 | AC97_SINGLE("Sigmatel 4-Speaker Stereo Playback Switch", |
| 927 | AC97_SIGMATEL_DAC2INVERT, 2, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | |
Andreas Mohr | afe6d7e | 2009-05-22 17:48:58 +0200 | [diff] [blame] | 929 | /* "Sigmatel " removed due to excessive name length: */ |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 930 | static const struct snd_kcontrol_new snd_ac97_sigmatel_phaseinvert = |
Andreas Mohr | afe6d7e | 2009-05-22 17:48:58 +0200 | [diff] [blame] | 931 | AC97_SINGLE("Surround Phase Inversion Playback Switch", |
| 932 | AC97_SIGMATEL_DAC2INVERT, 3, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 934 | static const struct snd_kcontrol_new snd_ac97_sigmatel_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | AC97_SINGLE("Sigmatel DAC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 1, 1, 0), |
| 936 | AC97_SINGLE("Sigmatel ADC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 0, 1, 0) |
| 937 | }; |
| 938 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 939 | static int patch_sigmatel_stac97xx_specific(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | { |
| 941 | int err; |
| 942 | |
| 943 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_ANALOG, snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) & ~0x0003); |
| 944 | if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 1)) |
| 945 | if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[0], 1)) < 0) |
| 946 | return err; |
| 947 | if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 0)) |
| 948 | if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[1], 1)) < 0) |
| 949 | return err; |
| 950 | if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 2)) |
| 951 | if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_4speaker, 1)) < 0) |
| 952 | return err; |
| 953 | if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 3)) |
| 954 | if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_phaseinvert, 1)) < 0) |
| 955 | return err; |
| 956 | return 0; |
| 957 | } |
| 958 | |
Hanno Boeck | 3e8b3b9 | 2011-01-14 19:14:47 +0100 | [diff] [blame] | 959 | static const struct snd_ac97_build_ops patch_sigmatel_stac9700_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | .build_3d = patch_sigmatel_stac9700_3d, |
| 961 | .build_specific = patch_sigmatel_stac97xx_specific |
| 962 | }; |
| 963 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 964 | static int patch_sigmatel_stac9700(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | { |
| 966 | ac97->build_ops = &patch_sigmatel_stac9700_ops; |
| 967 | return 0; |
| 968 | } |
| 969 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 970 | static int snd_ac97_stac9708_put_bias(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 972 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | int err; |
| 974 | |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 975 | mutex_lock(&ac97->page_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0xabba); |
| 977 | err = snd_ac97_update_bits(ac97, AC97_SIGMATEL_BIAS2, 0x0010, |
| 978 | (ucontrol->value.integer.value[0] & 1) << 4); |
| 979 | snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0); |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 980 | mutex_unlock(&ac97->page_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | return err; |
| 982 | } |
| 983 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 984 | static const struct snd_kcontrol_new snd_ac97_stac9708_bias_control = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 986 | .name = "Sigmatel Output Bias Switch", |
| 987 | .info = snd_ac97_info_volsw, |
| 988 | .get = snd_ac97_get_volsw, |
| 989 | .put = snd_ac97_stac9708_put_bias, |
| 990 | .private_value = AC97_SINGLE_VALUE(AC97_SIGMATEL_BIAS2, 4, 1, 0), |
| 991 | }; |
| 992 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 993 | static int patch_sigmatel_stac9708_specific(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | { |
| 995 | int err; |
| 996 | |
James C Georgas | e4c3bf0 | 2006-12-19 11:09:41 +0100 | [diff] [blame] | 997 | /* the register bit is writable, but the function is not implemented: */ |
| 998 | snd_ac97_remove_ctl(ac97, "PCM Out Path & Mute", NULL); |
| 999 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Sigmatel Surround Playback"); |
| 1001 | if ((err = patch_build_controls(ac97, &snd_ac97_stac9708_bias_control, 1)) < 0) |
| 1002 | return err; |
| 1003 | return patch_sigmatel_stac97xx_specific(ac97); |
| 1004 | } |
| 1005 | |
Hanno Boeck | 3e8b3b9 | 2011-01-14 19:14:47 +0100 | [diff] [blame] | 1006 | static const struct snd_ac97_build_ops patch_sigmatel_stac9708_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | .build_3d = patch_sigmatel_stac9708_3d, |
| 1008 | .build_specific = patch_sigmatel_stac9708_specific |
| 1009 | }; |
| 1010 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 1011 | static int patch_sigmatel_stac9708(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | { |
| 1013 | unsigned int codec72, codec6c; |
| 1014 | |
| 1015 | ac97->build_ops = &patch_sigmatel_stac9708_ops; |
| 1016 | ac97->caps |= 0x10; /* HP (sigmatel surround) support */ |
| 1017 | |
| 1018 | codec72 = snd_ac97_read(ac97, AC97_SIGMATEL_BIAS2) & 0x8000; |
| 1019 | codec6c = snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG); |
| 1020 | |
| 1021 | if ((codec72==0) && (codec6c==0)) { |
| 1022 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); |
| 1023 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1000); |
| 1024 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba); |
| 1025 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0007); |
| 1026 | } else if ((codec72==0x8000) && (codec6c==0)) { |
| 1027 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); |
| 1028 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1001); |
| 1029 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_DAC2INVERT, 0x0008); |
| 1030 | } else if ((codec72==0x8000) && (codec6c==0x0080)) { |
| 1031 | /* nothing */ |
| 1032 | } |
| 1033 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000); |
| 1034 | return 0; |
| 1035 | } |
| 1036 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 1037 | static int patch_sigmatel_stac9721(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | { |
| 1039 | ac97->build_ops = &patch_sigmatel_stac9700_ops; |
| 1040 | if (snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) == 0) { |
| 1041 | // patch for SigmaTel |
| 1042 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); |
| 1043 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x4000); |
| 1044 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba); |
| 1045 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002); |
| 1046 | } |
| 1047 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000); |
| 1048 | return 0; |
| 1049 | } |
| 1050 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 1051 | static int patch_sigmatel_stac9744(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | { |
| 1053 | // patch for SigmaTel |
| 1054 | ac97->build_ops = &patch_sigmatel_stac9700_ops; |
| 1055 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); |
| 1056 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */ |
| 1057 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba); |
| 1058 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002); |
| 1059 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000); |
| 1060 | return 0; |
| 1061 | } |
| 1062 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 1063 | static int patch_sigmatel_stac9756(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | { |
| 1065 | // patch for SigmaTel |
| 1066 | ac97->build_ops = &patch_sigmatel_stac9700_ops; |
| 1067 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); |
| 1068 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */ |
| 1069 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba); |
| 1070 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002); |
| 1071 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000); |
| 1072 | return 0; |
| 1073 | } |
| 1074 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1075 | static int snd_ac97_stac9758_output_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | { |
Takashi Iwai | 3b7a00d | 2014-10-20 18:15:36 +0200 | [diff] [blame^] | 1077 | static const char * const texts[5] = { |
| 1078 | "Input/Disabled", "Front Output", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | "Rear Output", "Center/LFE Output", "Mixer Output" }; |
| 1080 | |
Takashi Iwai | 3b7a00d | 2014-10-20 18:15:36 +0200 | [diff] [blame^] | 1081 | return snd_ctl_enum_info(uinfo, 1, 5, texts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | } |
| 1083 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1084 | static int snd_ac97_stac9758_output_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1086 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | int shift = kcontrol->private_value; |
| 1088 | unsigned short val; |
| 1089 | |
| 1090 | val = ac97->regs[AC97_SIGMATEL_OUTSEL] >> shift; |
| 1091 | if (!(val & 4)) |
| 1092 | ucontrol->value.enumerated.item[0] = 0; |
| 1093 | else |
| 1094 | ucontrol->value.enumerated.item[0] = 1 + (val & 3); |
| 1095 | return 0; |
| 1096 | } |
| 1097 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1098 | static int snd_ac97_stac9758_output_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1100 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | int shift = kcontrol->private_value; |
| 1102 | unsigned short val; |
| 1103 | |
| 1104 | if (ucontrol->value.enumerated.item[0] > 4) |
| 1105 | return -EINVAL; |
| 1106 | if (ucontrol->value.enumerated.item[0] == 0) |
| 1107 | val = 0; |
| 1108 | else |
| 1109 | val = 4 | (ucontrol->value.enumerated.item[0] - 1); |
| 1110 | return ac97_update_bits_page(ac97, AC97_SIGMATEL_OUTSEL, |
| 1111 | 7 << shift, val << shift, 0); |
| 1112 | } |
| 1113 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1114 | static int snd_ac97_stac9758_input_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | { |
Takashi Iwai | 3b7a00d | 2014-10-20 18:15:36 +0200 | [diff] [blame^] | 1116 | static const char * const texts[7] = { |
| 1117 | "Mic2 Jack", "Mic1 Jack", "Line In Jack", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | "Front Jack", "Rear Jack", "Center/LFE Jack", "Mute" }; |
| 1119 | |
Takashi Iwai | 3b7a00d | 2014-10-20 18:15:36 +0200 | [diff] [blame^] | 1120 | return snd_ctl_enum_info(uinfo, 1, 7, texts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | } |
| 1122 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1123 | static int snd_ac97_stac9758_input_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1125 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | int shift = kcontrol->private_value; |
| 1127 | unsigned short val; |
| 1128 | |
| 1129 | val = ac97->regs[AC97_SIGMATEL_INSEL]; |
| 1130 | ucontrol->value.enumerated.item[0] = (val >> shift) & 7; |
| 1131 | return 0; |
| 1132 | } |
| 1133 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1134 | static int snd_ac97_stac9758_input_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1136 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | int shift = kcontrol->private_value; |
| 1138 | |
| 1139 | return ac97_update_bits_page(ac97, AC97_SIGMATEL_INSEL, 7 << shift, |
| 1140 | ucontrol->value.enumerated.item[0] << shift, 0); |
| 1141 | } |
| 1142 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1143 | static int snd_ac97_stac9758_phonesel_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1144 | { |
Takashi Iwai | 3b7a00d | 2014-10-20 18:15:36 +0200 | [diff] [blame^] | 1145 | static const char * const texts[3] = { |
| 1146 | "None", "Front Jack", "Rear Jack" |
| 1147 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | |
Takashi Iwai | 3b7a00d | 2014-10-20 18:15:36 +0200 | [diff] [blame^] | 1149 | return snd_ctl_enum_info(uinfo, 1, 3, texts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | } |
| 1151 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1152 | static int snd_ac97_stac9758_phonesel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1154 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | |
| 1156 | ucontrol->value.enumerated.item[0] = ac97->regs[AC97_SIGMATEL_IOMISC] & 3; |
| 1157 | return 0; |
| 1158 | } |
| 1159 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1160 | static int snd_ac97_stac9758_phonesel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1161 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1162 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1163 | |
| 1164 | return ac97_update_bits_page(ac97, AC97_SIGMATEL_IOMISC, 3, |
| 1165 | ucontrol->value.enumerated.item[0], 0); |
| 1166 | } |
| 1167 | |
| 1168 | #define STAC9758_OUTPUT_JACK(xname, shift) \ |
| 1169 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ |
| 1170 | .info = snd_ac97_stac9758_output_jack_info, \ |
| 1171 | .get = snd_ac97_stac9758_output_jack_get, \ |
| 1172 | .put = snd_ac97_stac9758_output_jack_put, \ |
| 1173 | .private_value = shift } |
| 1174 | #define STAC9758_INPUT_JACK(xname, shift) \ |
| 1175 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ |
| 1176 | .info = snd_ac97_stac9758_input_jack_info, \ |
| 1177 | .get = snd_ac97_stac9758_input_jack_get, \ |
| 1178 | .put = snd_ac97_stac9758_input_jack_put, \ |
| 1179 | .private_value = shift } |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1180 | static const struct snd_kcontrol_new snd_ac97_sigmatel_stac9758_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | STAC9758_OUTPUT_JACK("Mic1 Jack", 1), |
| 1182 | STAC9758_OUTPUT_JACK("LineIn Jack", 4), |
| 1183 | STAC9758_OUTPUT_JACK("Front Jack", 7), |
| 1184 | STAC9758_OUTPUT_JACK("Rear Jack", 10), |
| 1185 | STAC9758_OUTPUT_JACK("Center/LFE Jack", 13), |
| 1186 | STAC9758_INPUT_JACK("Mic Input Source", 0), |
| 1187 | STAC9758_INPUT_JACK("Line Input Source", 8), |
| 1188 | { |
| 1189 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1190 | .name = "Headphone Amp", |
| 1191 | .info = snd_ac97_stac9758_phonesel_info, |
| 1192 | .get = snd_ac97_stac9758_phonesel_get, |
| 1193 | .put = snd_ac97_stac9758_phonesel_put |
| 1194 | }, |
| 1195 | AC97_SINGLE("Exchange Center/LFE", AC97_SIGMATEL_IOMISC, 4, 1, 0), |
| 1196 | AC97_SINGLE("Headphone +3dB Boost", AC97_SIGMATEL_IOMISC, 8, 1, 0) |
| 1197 | }; |
| 1198 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1199 | static int patch_sigmatel_stac9758_specific(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | { |
| 1201 | int err; |
| 1202 | |
| 1203 | err = patch_sigmatel_stac97xx_specific(ac97); |
| 1204 | if (err < 0) |
| 1205 | return err; |
| 1206 | err = patch_build_controls(ac97, snd_ac97_sigmatel_stac9758_controls, |
| 1207 | ARRAY_SIZE(snd_ac97_sigmatel_stac9758_controls)); |
| 1208 | if (err < 0) |
| 1209 | return err; |
| 1210 | /* DAC-A direct */ |
| 1211 | snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Front Playback"); |
| 1212 | /* DAC-A to Mix = PCM */ |
| 1213 | /* DAC-B direct = Surround */ |
| 1214 | /* DAC-B to Mix */ |
| 1215 | snd_ac97_rename_vol_ctl(ac97, "Video Playback", "Surround Mix Playback"); |
| 1216 | /* DAC-C direct = Center/LFE */ |
| 1217 | |
| 1218 | return 0; |
| 1219 | } |
| 1220 | |
Hanno Boeck | 3e8b3b9 | 2011-01-14 19:14:47 +0100 | [diff] [blame] | 1221 | static const struct snd_ac97_build_ops patch_sigmatel_stac9758_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | .build_3d = patch_sigmatel_stac9700_3d, |
| 1223 | .build_specific = patch_sigmatel_stac9758_specific |
| 1224 | }; |
| 1225 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 1226 | static int patch_sigmatel_stac9758(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | { |
| 1228 | static unsigned short regs[4] = { |
| 1229 | AC97_SIGMATEL_OUTSEL, |
| 1230 | AC97_SIGMATEL_IOMISC, |
| 1231 | AC97_SIGMATEL_INSEL, |
| 1232 | AC97_SIGMATEL_VARIOUS |
| 1233 | }; |
| 1234 | static unsigned short def_regs[4] = { |
| 1235 | /* OUTSEL */ 0xd794, /* CL:CL, SR:SR, LO:MX, LI:DS, MI:DS */ |
| 1236 | /* IOMISC */ 0x2001, |
| 1237 | /* INSEL */ 0x0201, /* LI:LI, MI:M1 */ |
| 1238 | /* VARIOUS */ 0x0040 |
| 1239 | }; |
| 1240 | static unsigned short m675_regs[4] = { |
| 1241 | /* OUTSEL */ 0xfc70, /* CL:MX, SR:MX, LO:DS, LI:MX, MI:DS */ |
| 1242 | /* IOMISC */ 0x2102, /* HP amp on */ |
| 1243 | /* INSEL */ 0x0203, /* LI:LI, MI:FR */ |
| 1244 | /* VARIOUS */ 0x0041 /* stereo mic */ |
| 1245 | }; |
| 1246 | unsigned short *pregs = def_regs; |
| 1247 | int i; |
| 1248 | |
| 1249 | /* Gateway M675 notebook */ |
| 1250 | if (ac97->pci && |
| 1251 | ac97->subsystem_vendor == 0x107b && |
| 1252 | ac97->subsystem_device == 0x0601) |
| 1253 | pregs = m675_regs; |
| 1254 | |
| 1255 | // patch for SigmaTel |
| 1256 | ac97->build_ops = &patch_sigmatel_stac9758_ops; |
| 1257 | /* FIXME: assume only page 0 for writing cache */ |
| 1258 | snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR); |
| 1259 | for (i = 0; i < 4; i++) |
| 1260 | snd_ac97_write_cache(ac97, regs[i], pregs[i]); |
| 1261 | |
| 1262 | ac97->flags |= AC97_STEREO_MUTES; |
| 1263 | return 0; |
| 1264 | } |
| 1265 | |
| 1266 | /* |
| 1267 | * Cirrus Logic CS42xx codecs |
| 1268 | */ |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1269 | static const struct snd_kcontrol_new snd_ac97_cirrus_controls_spdif[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CSR_SPDIF, 15, 1, 0), |
| 1271 | AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "AC97-SPSA", AC97_CSR_ACMODE, 0, 3, 0) |
| 1272 | }; |
| 1273 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1274 | static int patch_cirrus_build_spdif(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | { |
| 1276 | int err; |
| 1277 | |
| 1278 | /* con mask, pro mask, default */ |
| 1279 | if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0) |
| 1280 | return err; |
| 1281 | /* switch, spsa */ |
| 1282 | if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[0], 1)) < 0) |
| 1283 | return err; |
| 1284 | switch (ac97->id & AC97_ID_CS_MASK) { |
| 1285 | case AC97_ID_CS4205: |
| 1286 | if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[1], 1)) < 0) |
| 1287 | return err; |
| 1288 | break; |
| 1289 | } |
| 1290 | /* set default PCM S/PDIF params */ |
| 1291 | /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */ |
| 1292 | snd_ac97_write_cache(ac97, AC97_CSR_SPDIF, 0x0a20); |
| 1293 | return 0; |
| 1294 | } |
| 1295 | |
Hanno Boeck | 3e8b3b9 | 2011-01-14 19:14:47 +0100 | [diff] [blame] | 1296 | static const struct snd_ac97_build_ops patch_cirrus_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | .build_spdif = patch_cirrus_build_spdif |
| 1298 | }; |
| 1299 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 1300 | static int patch_cirrus_spdif(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | { |
| 1302 | /* Basically, the cs4201/cs4205/cs4297a has non-standard sp/dif registers. |
| 1303 | WHY CAN'T ANYONE FOLLOW THE BLOODY SPEC? *sigh* |
| 1304 | - sp/dif EA ID is not set, but sp/dif is always present. |
| 1305 | - enable/disable is spdif register bit 15. |
| 1306 | - sp/dif control register is 0x68. differs from AC97: |
| 1307 | - valid is bit 14 (vs 15) |
| 1308 | - no DRS |
| 1309 | - only 44.1/48k [00 = 48, 01=44,1] (AC97 is 00=44.1, 10=48) |
| 1310 | - sp/dif ssource select is in 0x5e bits 0,1. |
| 1311 | */ |
| 1312 | |
| 1313 | ac97->build_ops = &patch_cirrus_ops; |
| 1314 | ac97->flags |= AC97_CS_SPDIF; |
| 1315 | ac97->rates[AC97_RATES_SPDIF] &= ~SNDRV_PCM_RATE_32000; |
| 1316 | ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */ |
| 1317 | snd_ac97_write_cache(ac97, AC97_CSR_ACMODE, 0x0080); |
| 1318 | return 0; |
| 1319 | } |
| 1320 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 1321 | static int patch_cirrus_cs4299(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1322 | { |
| 1323 | /* force the detection of PC Beep */ |
| 1324 | ac97->flags |= AC97_HAS_PC_BEEP; |
| 1325 | |
| 1326 | return patch_cirrus_spdif(ac97); |
| 1327 | } |
| 1328 | |
| 1329 | /* |
| 1330 | * Conexant codecs |
| 1331 | */ |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1332 | static const struct snd_kcontrol_new snd_ac97_conexant_controls_spdif[1] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CXR_AUDIO_MISC, 3, 1, 0), |
| 1334 | }; |
| 1335 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1336 | static int patch_conexant_build_spdif(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | { |
| 1338 | int err; |
| 1339 | |
| 1340 | /* con mask, pro mask, default */ |
| 1341 | if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0) |
| 1342 | return err; |
| 1343 | /* switch */ |
| 1344 | if ((err = patch_build_controls(ac97, &snd_ac97_conexant_controls_spdif[0], 1)) < 0) |
| 1345 | return err; |
| 1346 | /* set default PCM S/PDIF params */ |
| 1347 | /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */ |
| 1348 | snd_ac97_write_cache(ac97, AC97_CXR_AUDIO_MISC, |
| 1349 | snd_ac97_read(ac97, AC97_CXR_AUDIO_MISC) & ~(AC97_CXR_SPDIFEN|AC97_CXR_COPYRGT|AC97_CXR_SPDIF_MASK)); |
| 1350 | return 0; |
| 1351 | } |
| 1352 | |
Hanno Boeck | 3e8b3b9 | 2011-01-14 19:14:47 +0100 | [diff] [blame] | 1353 | static const struct snd_ac97_build_ops patch_conexant_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | .build_spdif = patch_conexant_build_spdif |
| 1355 | }; |
| 1356 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 1357 | static int patch_conexant(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | { |
| 1359 | ac97->build_ops = &patch_conexant_ops; |
| 1360 | ac97->flags |= AC97_CX_SPDIF; |
| 1361 | ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */ |
| 1362 | ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */ |
| 1363 | return 0; |
| 1364 | } |
| 1365 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 1366 | static int patch_cx20551(struct snd_ac97 *ac97) |
Takashi Iwai | 9e292c0 | 2007-02-09 12:42:03 +0100 | [diff] [blame] | 1367 | { |
| 1368 | snd_ac97_update_bits(ac97, 0x5c, 0x01, 0x01); |
| 1369 | return 0; |
| 1370 | } |
| 1371 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | /* |
| 1373 | * Analog Device AD18xx, AD19xx codecs |
| 1374 | */ |
| 1375 | #ifdef CONFIG_PM |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1376 | static void ad18xx_resume(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | { |
| 1378 | static unsigned short setup_regs[] = { |
| 1379 | AC97_AD_MISC, AC97_AD_SERIAL_CFG, AC97_AD_JACK_SPDIF, |
| 1380 | }; |
| 1381 | int i, codec; |
| 1382 | |
| 1383 | for (i = 0; i < (int)ARRAY_SIZE(setup_regs); i++) { |
| 1384 | unsigned short reg = setup_regs[i]; |
| 1385 | if (test_bit(reg, ac97->reg_accessed)) { |
| 1386 | snd_ac97_write(ac97, reg, ac97->regs[reg]); |
| 1387 | snd_ac97_read(ac97, reg); |
| 1388 | } |
| 1389 | } |
| 1390 | |
| 1391 | if (! (ac97->flags & AC97_AD_MULTI)) |
| 1392 | /* normal restore */ |
| 1393 | snd_ac97_restore_status(ac97); |
| 1394 | else { |
| 1395 | /* restore the AD18xx codec configurations */ |
| 1396 | for (codec = 0; codec < 3; codec++) { |
| 1397 | if (! ac97->spec.ad18xx.id[codec]) |
| 1398 | continue; |
| 1399 | /* select single codec */ |
| 1400 | snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, |
| 1401 | ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]); |
| 1402 | ac97->bus->ops->write(ac97, AC97_AD_CODEC_CFG, ac97->spec.ad18xx.codec_cfg[codec]); |
| 1403 | } |
| 1404 | /* select all codecs */ |
| 1405 | snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000); |
| 1406 | |
| 1407 | /* restore status */ |
| 1408 | for (i = 2; i < 0x7c ; i += 2) { |
| 1409 | if (i == AC97_POWERDOWN || i == AC97_EXTENDED_ID) |
| 1410 | continue; |
| 1411 | if (test_bit(i, ac97->reg_accessed)) { |
| 1412 | /* handle multi codecs for AD18xx */ |
| 1413 | if (i == AC97_PCM) { |
| 1414 | for (codec = 0; codec < 3; codec++) { |
| 1415 | if (! ac97->spec.ad18xx.id[codec]) |
| 1416 | continue; |
| 1417 | /* select single codec */ |
| 1418 | snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, |
| 1419 | ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]); |
| 1420 | /* update PCM bits */ |
| 1421 | ac97->bus->ops->write(ac97, AC97_PCM, ac97->spec.ad18xx.pcmreg[codec]); |
| 1422 | } |
| 1423 | /* select all codecs */ |
| 1424 | snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000); |
| 1425 | continue; |
| 1426 | } else if (i == AC97_AD_TEST || |
| 1427 | i == AC97_AD_CODEC_CFG || |
| 1428 | i == AC97_AD_SERIAL_CFG) |
| 1429 | continue; /* ignore */ |
| 1430 | } |
| 1431 | snd_ac97_write(ac97, i, ac97->regs[i]); |
| 1432 | snd_ac97_read(ac97, i); |
| 1433 | } |
| 1434 | } |
| 1435 | |
| 1436 | snd_ac97_restore_iec958(ac97); |
| 1437 | } |
Jaya Kumar | 1561f09 | 2006-06-19 15:06:14 +0200 | [diff] [blame] | 1438 | |
| 1439 | static void ad1888_resume(struct snd_ac97 *ac97) |
| 1440 | { |
| 1441 | ad18xx_resume(ac97); |
| 1442 | snd_ac97_write_cache(ac97, AC97_CODEC_CLASS_REV, 0x8080); |
| 1443 | } |
| 1444 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 | #endif |
| 1446 | |
Ville Syrjala | bd25b7c | 2006-09-04 12:28:24 +0200 | [diff] [blame] | 1447 | static const struct snd_ac97_res_table ad1819_restbl[] = { |
| 1448 | { AC97_PHONE, 0x9f1f }, |
| 1449 | { AC97_MIC, 0x9f1f }, |
| 1450 | { AC97_LINE, 0x9f1f }, |
| 1451 | { AC97_CD, 0x9f1f }, |
| 1452 | { AC97_VIDEO, 0x9f1f }, |
| 1453 | { AC97_AUX, 0x9f1f }, |
| 1454 | { AC97_PCM, 0x9f1f }, |
| 1455 | { } /* terminator */ |
| 1456 | }; |
| 1457 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 1458 | static int patch_ad1819(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1459 | { |
| 1460 | unsigned short scfg; |
| 1461 | |
| 1462 | // patch for Analog Devices |
| 1463 | scfg = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG); |
| 1464 | snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, scfg | 0x7000); /* select all codecs */ |
Ville Syrjala | bd25b7c | 2006-09-04 12:28:24 +0200 | [diff] [blame] | 1465 | ac97->res_table = ad1819_restbl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1466 | return 0; |
| 1467 | } |
| 1468 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1469 | static unsigned short patch_ad1881_unchained(struct snd_ac97 * ac97, int idx, unsigned short mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1470 | { |
| 1471 | unsigned short val; |
| 1472 | |
| 1473 | // test for unchained codec |
| 1474 | snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, mask); |
| 1475 | snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000); /* ID0C, ID1C, SDIE = off */ |
| 1476 | val = snd_ac97_read(ac97, AC97_VENDOR_ID2); |
| 1477 | if ((val & 0xff40) != 0x5340) |
| 1478 | return 0; |
| 1479 | ac97->spec.ad18xx.unchained[idx] = mask; |
| 1480 | ac97->spec.ad18xx.id[idx] = val; |
| 1481 | ac97->spec.ad18xx.codec_cfg[idx] = 0x0000; |
| 1482 | return mask; |
| 1483 | } |
| 1484 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1485 | static int patch_ad1881_chained1(struct snd_ac97 * ac97, int idx, unsigned short codec_bits) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1486 | { |
| 1487 | static int cfg_bits[3] = { 1<<12, 1<<14, 1<<13 }; |
| 1488 | unsigned short val; |
| 1489 | |
| 1490 | snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, cfg_bits[idx]); |
| 1491 | snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0004); // SDIE |
| 1492 | val = snd_ac97_read(ac97, AC97_VENDOR_ID2); |
| 1493 | if ((val & 0xff40) != 0x5340) |
| 1494 | return 0; |
| 1495 | if (codec_bits) |
| 1496 | snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, codec_bits); |
| 1497 | ac97->spec.ad18xx.chained[idx] = cfg_bits[idx]; |
| 1498 | ac97->spec.ad18xx.id[idx] = val; |
| 1499 | ac97->spec.ad18xx.codec_cfg[idx] = codec_bits ? codec_bits : 0x0004; |
| 1500 | return 1; |
| 1501 | } |
| 1502 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1503 | static void patch_ad1881_chained(struct snd_ac97 * ac97, int unchained_idx, int cidx1, int cidx2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | { |
| 1505 | // already detected? |
| 1506 | if (ac97->spec.ad18xx.unchained[cidx1] || ac97->spec.ad18xx.chained[cidx1]) |
| 1507 | cidx1 = -1; |
| 1508 | if (ac97->spec.ad18xx.unchained[cidx2] || ac97->spec.ad18xx.chained[cidx2]) |
| 1509 | cidx2 = -1; |
| 1510 | if (cidx1 < 0 && cidx2 < 0) |
| 1511 | return; |
| 1512 | // test for chained codecs |
| 1513 | snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, |
| 1514 | ac97->spec.ad18xx.unchained[unchained_idx]); |
| 1515 | snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0002); // ID1C |
| 1516 | ac97->spec.ad18xx.codec_cfg[unchained_idx] = 0x0002; |
| 1517 | if (cidx1 >= 0) { |
Takashi Iwai | c19bcdc | 2006-11-08 15:48:43 +0100 | [diff] [blame] | 1518 | if (cidx2 < 0) |
| 1519 | patch_ad1881_chained1(ac97, cidx1, 0); |
| 1520 | else if (patch_ad1881_chained1(ac97, cidx1, 0x0006)) // SDIE | ID1C |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1521 | patch_ad1881_chained1(ac97, cidx2, 0); |
| 1522 | else if (patch_ad1881_chained1(ac97, cidx2, 0x0006)) // SDIE | ID1C |
| 1523 | patch_ad1881_chained1(ac97, cidx1, 0); |
| 1524 | } else if (cidx2 >= 0) { |
| 1525 | patch_ad1881_chained1(ac97, cidx2, 0); |
| 1526 | } |
| 1527 | } |
| 1528 | |
Hanno Boeck | 3e8b3b9 | 2011-01-14 19:14:47 +0100 | [diff] [blame] | 1529 | static const struct snd_ac97_build_ops patch_ad1881_build_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1530 | #ifdef CONFIG_PM |
| 1531 | .resume = ad18xx_resume |
| 1532 | #endif |
| 1533 | }; |
| 1534 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 1535 | static int patch_ad1881(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | { |
| 1537 | static const char cfg_idxs[3][2] = { |
| 1538 | {2, 1}, |
| 1539 | {0, 2}, |
| 1540 | {0, 1} |
| 1541 | }; |
| 1542 | |
| 1543 | // patch for Analog Devices |
| 1544 | unsigned short codecs[3]; |
| 1545 | unsigned short val; |
| 1546 | int idx, num; |
| 1547 | |
| 1548 | val = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG); |
| 1549 | snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, val); |
| 1550 | codecs[0] = patch_ad1881_unchained(ac97, 0, (1<<12)); |
| 1551 | codecs[1] = patch_ad1881_unchained(ac97, 1, (1<<14)); |
| 1552 | codecs[2] = patch_ad1881_unchained(ac97, 2, (1<<13)); |
| 1553 | |
Takashi Iwai | 7c22f1a | 2005-10-10 11:46:31 +0200 | [diff] [blame] | 1554 | if (! (codecs[0] || codecs[1] || codecs[2])) |
| 1555 | goto __end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1556 | |
| 1557 | for (idx = 0; idx < 3; idx++) |
| 1558 | if (ac97->spec.ad18xx.unchained[idx]) |
| 1559 | patch_ad1881_chained(ac97, idx, cfg_idxs[idx][0], cfg_idxs[idx][1]); |
| 1560 | |
| 1561 | if (ac97->spec.ad18xx.id[1]) { |
| 1562 | ac97->flags |= AC97_AD_MULTI; |
| 1563 | ac97->scaps |= AC97_SCAP_SURROUND_DAC; |
| 1564 | } |
| 1565 | if (ac97->spec.ad18xx.id[2]) { |
| 1566 | ac97->flags |= AC97_AD_MULTI; |
| 1567 | ac97->scaps |= AC97_SCAP_CENTER_LFE_DAC; |
| 1568 | } |
| 1569 | |
| 1570 | __end: |
| 1571 | /* select all codecs */ |
| 1572 | snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000); |
| 1573 | /* check if only one codec is present */ |
| 1574 | for (idx = num = 0; idx < 3; idx++) |
| 1575 | if (ac97->spec.ad18xx.id[idx]) |
| 1576 | num++; |
| 1577 | if (num == 1) { |
| 1578 | /* ok, deselect all ID bits */ |
| 1579 | snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000); |
| 1580 | ac97->spec.ad18xx.codec_cfg[0] = |
| 1581 | ac97->spec.ad18xx.codec_cfg[1] = |
| 1582 | ac97->spec.ad18xx.codec_cfg[2] = 0x0000; |
| 1583 | } |
| 1584 | /* required for AD1886/AD1885 combination */ |
| 1585 | ac97->ext_id = snd_ac97_read(ac97, AC97_EXTENDED_ID); |
| 1586 | if (ac97->spec.ad18xx.id[0]) { |
| 1587 | ac97->id &= 0xffff0000; |
| 1588 | ac97->id |= ac97->spec.ad18xx.id[0]; |
| 1589 | } |
| 1590 | ac97->build_ops = &patch_ad1881_build_ops; |
| 1591 | return 0; |
| 1592 | } |
| 1593 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1594 | static const struct snd_kcontrol_new snd_ac97_controls_ad1885[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | AC97_SINGLE("Digital Mono Direct", AC97_AD_MISC, 11, 1, 0), |
| 1596 | /* AC97_SINGLE("Digital Audio Mode", AC97_AD_MISC, 12, 1, 0), */ /* seems problematic */ |
| 1597 | AC97_SINGLE("Low Power Mixer", AC97_AD_MISC, 14, 1, 0), |
| 1598 | AC97_SINGLE("Zero Fill DAC", AC97_AD_MISC, 15, 1, 0), |
| 1599 | AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 9, 1, 1), /* inverted */ |
| 1600 | AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 8, 1, 1), /* inverted */ |
| 1601 | }; |
| 1602 | |
Takashi Iwai | 0cb29ea | 2007-01-29 15:33:49 +0100 | [diff] [blame] | 1603 | static const DECLARE_TLV_DB_SCALE(db_scale_6bit_6db_max, -8850, 150, 0); |
Takashi Iwai | 2f3482f | 2006-08-21 18:44:31 +0200 | [diff] [blame] | 1604 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1605 | static int patch_ad1885_specific(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | { |
| 1607 | int err; |
| 1608 | |
| 1609 | if ((err = patch_build_controls(ac97, snd_ac97_controls_ad1885, ARRAY_SIZE(snd_ac97_controls_ad1885))) < 0) |
| 1610 | return err; |
Takashi Iwai | 2f3482f | 2006-08-21 18:44:31 +0200 | [diff] [blame] | 1611 | reset_tlv(ac97, "Headphone Playback Volume", |
| 1612 | db_scale_6bit_6db_max); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1613 | return 0; |
| 1614 | } |
| 1615 | |
Hanno Boeck | 3e8b3b9 | 2011-01-14 19:14:47 +0100 | [diff] [blame] | 1616 | static const struct snd_ac97_build_ops patch_ad1885_build_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1617 | .build_specific = &patch_ad1885_specific, |
| 1618 | #ifdef CONFIG_PM |
| 1619 | .resume = ad18xx_resume |
| 1620 | #endif |
| 1621 | }; |
| 1622 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 1623 | static int patch_ad1885(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1624 | { |
| 1625 | patch_ad1881(ac97); |
| 1626 | /* This is required to deal with the Intel D815EEAL2 */ |
| 1627 | /* i.e. Line out is actually headphone out from codec */ |
| 1628 | |
| 1629 | /* set default */ |
| 1630 | snd_ac97_write_cache(ac97, AC97_AD_MISC, 0x0404); |
| 1631 | |
| 1632 | ac97->build_ops = &patch_ad1885_build_ops; |
| 1633 | return 0; |
| 1634 | } |
| 1635 | |
Takashi Iwai | 2f3482f | 2006-08-21 18:44:31 +0200 | [diff] [blame] | 1636 | static int patch_ad1886_specific(struct snd_ac97 * ac97) |
| 1637 | { |
| 1638 | reset_tlv(ac97, "Headphone Playback Volume", |
| 1639 | db_scale_6bit_6db_max); |
| 1640 | return 0; |
| 1641 | } |
| 1642 | |
Hanno Boeck | 3e8b3b9 | 2011-01-14 19:14:47 +0100 | [diff] [blame] | 1643 | static const struct snd_ac97_build_ops patch_ad1886_build_ops = { |
Takashi Iwai | 2f3482f | 2006-08-21 18:44:31 +0200 | [diff] [blame] | 1644 | .build_specific = &patch_ad1886_specific, |
| 1645 | #ifdef CONFIG_PM |
| 1646 | .resume = ad18xx_resume |
| 1647 | #endif |
| 1648 | }; |
| 1649 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 1650 | static int patch_ad1886(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1651 | { |
| 1652 | patch_ad1881(ac97); |
| 1653 | /* Presario700 workaround */ |
| 1654 | /* for Jack Sense/SPDIF Register misetting causing */ |
| 1655 | snd_ac97_write_cache(ac97, AC97_AD_JACK_SPDIF, 0x0010); |
Takashi Iwai | 2f3482f | 2006-08-21 18:44:31 +0200 | [diff] [blame] | 1656 | ac97->build_ops = &patch_ad1886_build_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1657 | return 0; |
| 1658 | } |
| 1659 | |
Randy Cushman | 67e9f4b | 2006-12-22 12:44:25 +0100 | [diff] [blame] | 1660 | /* MISC bits (AD1888/AD1980/AD1985 register 0x76) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1661 | #define AC97_AD198X_MBC 0x0003 /* mic boost */ |
| 1662 | #define AC97_AD198X_MBC_20 0x0000 /* +20dB */ |
| 1663 | #define AC97_AD198X_MBC_10 0x0001 /* +10dB */ |
| 1664 | #define AC97_AD198X_MBC_30 0x0002 /* +30dB */ |
| 1665 | #define AC97_AD198X_VREFD 0x0004 /* VREF high-Z */ |
Randy Cushman | 6428ea1 | 2006-12-21 19:17:29 +0100 | [diff] [blame] | 1666 | #define AC97_AD198X_VREFH 0x0008 /* 0=2.25V, 1=3.7V */ |
| 1667 | #define AC97_AD198X_VREF_0 0x000c /* 0V (AD1985 only) */ |
| 1668 | #define AC97_AD198X_VREF_MASK (AC97_AD198X_VREFH | AC97_AD198X_VREFD) |
| 1669 | #define AC97_AD198X_VREF_SHIFT 2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1670 | #define AC97_AD198X_SRU 0x0010 /* sample rate unlock */ |
| 1671 | #define AC97_AD198X_LOSEL 0x0020 /* LINE_OUT amplifiers input select */ |
| 1672 | #define AC97_AD198X_2MIC 0x0040 /* 2-channel mic select */ |
| 1673 | #define AC97_AD198X_SPRD 0x0080 /* SPREAD enable */ |
Randy Cushman | 6428ea1 | 2006-12-21 19:17:29 +0100 | [diff] [blame] | 1674 | #define AC97_AD198X_DMIX0 0x0100 /* downmix mode: */ |
| 1675 | /* 0 = 6-to-4, 1 = 6-to-2 downmix */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1676 | #define AC97_AD198X_DMIX1 0x0200 /* downmix mode: 1 = enabled */ |
| 1677 | #define AC97_AD198X_HPSEL 0x0400 /* headphone amplifier input select */ |
| 1678 | #define AC97_AD198X_CLDIS 0x0800 /* center/lfe disable */ |
| 1679 | #define AC97_AD198X_LODIS 0x1000 /* LINE_OUT disable */ |
| 1680 | #define AC97_AD198X_MSPLT 0x2000 /* mute split */ |
| 1681 | #define AC97_AD198X_AC97NC 0x4000 /* AC97 no compatible mode */ |
| 1682 | #define AC97_AD198X_DACZ 0x8000 /* DAC zero-fill mode */ |
| 1683 | |
Randy Cushman | 67e9f4b | 2006-12-22 12:44:25 +0100 | [diff] [blame] | 1684 | /* MISC 1 bits (AD1986 register 0x76) */ |
| 1685 | #define AC97_AD1986_MBC 0x0003 /* mic boost */ |
| 1686 | #define AC97_AD1986_MBC_20 0x0000 /* +20dB */ |
| 1687 | #define AC97_AD1986_MBC_10 0x0001 /* +10dB */ |
| 1688 | #define AC97_AD1986_MBC_30 0x0002 /* +30dB */ |
| 1689 | #define AC97_AD1986_LISEL0 0x0004 /* LINE_IN select bit 0 */ |
| 1690 | #define AC97_AD1986_LISEL1 0x0008 /* LINE_IN select bit 1 */ |
| 1691 | #define AC97_AD1986_LISEL_MASK (AC97_AD1986_LISEL1 | AC97_AD1986_LISEL0) |
| 1692 | #define AC97_AD1986_LISEL_LI 0x0000 /* LINE_IN pins as LINE_IN source */ |
| 1693 | #define AC97_AD1986_LISEL_SURR 0x0004 /* SURROUND pins as LINE_IN source */ |
| 1694 | #define AC97_AD1986_LISEL_MIC 0x0008 /* MIC_1/2 pins as LINE_IN source */ |
| 1695 | #define AC97_AD1986_SRU 0x0010 /* sample rate unlock */ |
| 1696 | #define AC97_AD1986_SOSEL 0x0020 /* SURROUND_OUT amplifiers input sel */ |
| 1697 | #define AC97_AD1986_2MIC 0x0040 /* 2-channel mic select */ |
| 1698 | #define AC97_AD1986_SPRD 0x0080 /* SPREAD enable */ |
| 1699 | #define AC97_AD1986_DMIX0 0x0100 /* downmix mode: */ |
| 1700 | /* 0 = 6-to-4, 1 = 6-to-2 downmix */ |
| 1701 | #define AC97_AD1986_DMIX1 0x0200 /* downmix mode: 1 = enabled */ |
| 1702 | #define AC97_AD1986_CLDIS 0x0800 /* center/lfe disable */ |
| 1703 | #define AC97_AD1986_SODIS 0x1000 /* SURROUND_OUT disable */ |
| 1704 | #define AC97_AD1986_MSPLT 0x2000 /* mute split (read only 1) */ |
| 1705 | #define AC97_AD1986_AC97NC 0x4000 /* AC97 no compatible mode (r/o 1) */ |
| 1706 | #define AC97_AD1986_DACZ 0x8000 /* DAC zero-fill mode */ |
| 1707 | |
| 1708 | /* MISC 2 bits (AD1986 register 0x70) */ |
| 1709 | #define AC97_AD_MISC2 0x70 /* Misc Control Bits 2 (AD1986) */ |
| 1710 | |
| 1711 | #define AC97_AD1986_CVREF0 0x0004 /* C/LFE VREF_OUT 2.25V */ |
| 1712 | #define AC97_AD1986_CVREF1 0x0008 /* C/LFE VREF_OUT 0V */ |
| 1713 | #define AC97_AD1986_CVREF2 0x0010 /* C/LFE VREF_OUT 3.7V */ |
| 1714 | #define AC97_AD1986_CVREF_MASK \ |
| 1715 | (AC97_AD1986_CVREF2 | AC97_AD1986_CVREF1 | AC97_AD1986_CVREF0) |
| 1716 | #define AC97_AD1986_JSMAP 0x0020 /* Jack Sense Mapping 1 = alternate */ |
| 1717 | #define AC97_AD1986_MMDIS 0x0080 /* Mono Mute Disable */ |
| 1718 | #define AC97_AD1986_MVREF0 0x0400 /* MIC VREF_OUT 2.25V */ |
| 1719 | #define AC97_AD1986_MVREF1 0x0800 /* MIC VREF_OUT 0V */ |
| 1720 | #define AC97_AD1986_MVREF2 0x1000 /* MIC VREF_OUT 3.7V */ |
| 1721 | #define AC97_AD1986_MVREF_MASK \ |
| 1722 | (AC97_AD1986_MVREF2 | AC97_AD1986_MVREF1 | AC97_AD1986_MVREF0) |
| 1723 | |
| 1724 | /* MISC 3 bits (AD1986 register 0x7a) */ |
| 1725 | #define AC97_AD_MISC3 0x7a /* Misc Control Bits 3 (AD1986) */ |
| 1726 | |
| 1727 | #define AC97_AD1986_MMIX 0x0004 /* Mic Mix, left/right */ |
| 1728 | #define AC97_AD1986_GPO 0x0008 /* General Purpose Out */ |
| 1729 | #define AC97_AD1986_LOHPEN 0x0010 /* LINE_OUT headphone drive */ |
| 1730 | #define AC97_AD1986_LVREF0 0x0100 /* LINE_OUT VREF_OUT 2.25V */ |
| 1731 | #define AC97_AD1986_LVREF1 0x0200 /* LINE_OUT VREF_OUT 0V */ |
| 1732 | #define AC97_AD1986_LVREF2 0x0400 /* LINE_OUT VREF_OUT 3.7V */ |
| 1733 | #define AC97_AD1986_LVREF_MASK \ |
| 1734 | (AC97_AD1986_LVREF2 | AC97_AD1986_LVREF1 | AC97_AD1986_LVREF0) |
| 1735 | #define AC97_AD1986_JSINVA 0x0800 /* Jack Sense Invert SENSE_A */ |
| 1736 | #define AC97_AD1986_LOSEL 0x1000 /* LINE_OUT amplifiers input select */ |
| 1737 | #define AC97_AD1986_HPSEL0 0x2000 /* Headphone amplifiers */ |
| 1738 | /* input select Surround DACs */ |
| 1739 | #define AC97_AD1986_HPSEL1 0x4000 /* Headphone amplifiers input */ |
| 1740 | /* select C/LFE DACs */ |
| 1741 | #define AC97_AD1986_JSINVB 0x8000 /* Jack Sense Invert SENSE_B */ |
| 1742 | |
| 1743 | /* Serial Config bits (AD1986 register 0x74) (incomplete) */ |
| 1744 | #define AC97_AD1986_OMS0 0x0100 /* Optional Mic Selector bit 0 */ |
| 1745 | #define AC97_AD1986_OMS1 0x0200 /* Optional Mic Selector bit 1 */ |
| 1746 | #define AC97_AD1986_OMS2 0x0400 /* Optional Mic Selector bit 2 */ |
| 1747 | #define AC97_AD1986_OMS_MASK \ |
| 1748 | (AC97_AD1986_OMS2 | AC97_AD1986_OMS1 | AC97_AD1986_OMS0) |
| 1749 | #define AC97_AD1986_OMS_M 0x0000 /* MIC_1/2 pins are MIC sources */ |
| 1750 | #define AC97_AD1986_OMS_L 0x0100 /* LINE_IN pins are MIC sources */ |
| 1751 | #define AC97_AD1986_OMS_C 0x0200 /* Center/LFE pins are MCI sources */ |
| 1752 | #define AC97_AD1986_OMS_MC 0x0400 /* Mix of MIC and C/LFE pins */ |
| 1753 | /* are MIC sources */ |
| 1754 | #define AC97_AD1986_OMS_ML 0x0500 /* MIX of MIC and LINE_IN pins */ |
| 1755 | /* are MIC sources */ |
| 1756 | #define AC97_AD1986_OMS_LC 0x0600 /* MIX of LINE_IN and C/LFE pins */ |
| 1757 | /* are MIC sources */ |
| 1758 | #define AC97_AD1986_OMS_MLC 0x0700 /* MIX of MIC, LINE_IN, C/LFE pins */ |
| 1759 | /* are MIC sources */ |
| 1760 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1762 | static int snd_ac97_ad198x_spdif_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1763 | { |
Takashi Iwai | 3b7a00d | 2014-10-20 18:15:36 +0200 | [diff] [blame^] | 1764 | static const char * const texts[2] = { "AC-Link", "A/D Converter" }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1765 | |
Takashi Iwai | 3b7a00d | 2014-10-20 18:15:36 +0200 | [diff] [blame^] | 1766 | return snd_ctl_enum_info(uinfo, 1, 2, texts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1767 | } |
| 1768 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1769 | static int snd_ac97_ad198x_spdif_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1771 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1772 | unsigned short val; |
| 1773 | |
| 1774 | val = ac97->regs[AC97_AD_SERIAL_CFG]; |
| 1775 | ucontrol->value.enumerated.item[0] = (val >> 2) & 1; |
| 1776 | return 0; |
| 1777 | } |
| 1778 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1779 | static int snd_ac97_ad198x_spdif_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1780 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1781 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1782 | unsigned short val; |
| 1783 | |
| 1784 | if (ucontrol->value.enumerated.item[0] > 1) |
| 1785 | return -EINVAL; |
| 1786 | val = ucontrol->value.enumerated.item[0] << 2; |
| 1787 | return snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x0004, val); |
| 1788 | } |
| 1789 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1790 | static const struct snd_kcontrol_new snd_ac97_ad198x_spdif_source = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1791 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1792 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source", |
| 1793 | .info = snd_ac97_ad198x_spdif_source_info, |
| 1794 | .get = snd_ac97_ad198x_spdif_source_get, |
| 1795 | .put = snd_ac97_ad198x_spdif_source_put, |
| 1796 | }; |
| 1797 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1798 | static int patch_ad198x_post_spdif(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1799 | { |
| 1800 | return patch_build_controls(ac97, &snd_ac97_ad198x_spdif_source, 1); |
| 1801 | } |
| 1802 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1803 | static const struct snd_kcontrol_new snd_ac97_ad1981x_jack_sense[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 11, 1, 0), |
| 1805 | AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0), |
| 1806 | }; |
| 1807 | |
Takashi Iwai | 128a46a | 2006-01-11 18:15:43 +0100 | [diff] [blame] | 1808 | /* black list to avoid HP/Line jack-sense controls |
| 1809 | * (SS vendor << 16 | device) |
| 1810 | */ |
| 1811 | static unsigned int ad1981_jacks_blacklist[] = { |
Takashi Iwai | a31e8c7 | 2007-02-22 12:47:25 +0100 | [diff] [blame] | 1812 | 0x10140523, /* Thinkpad R40 */ |
| 1813 | 0x10140534, /* Thinkpad X31 */ |
Takashi Iwai | a43c4d4 | 2006-06-01 17:16:41 +0200 | [diff] [blame] | 1814 | 0x10140537, /* Thinkpad T41p */ |
Daniel T Chen | e1f7f02 | 2010-03-25 22:38:15 -0700 | [diff] [blame] | 1815 | 0x1014053e, /* Thinkpad R40e */ |
Takashi Iwai | 128a46a | 2006-01-11 18:15:43 +0100 | [diff] [blame] | 1816 | 0x10140554, /* Thinkpad T42p/R50p */ |
Daniel T Chen | 8286c53 | 2007-05-15 11:46:23 +0200 | [diff] [blame] | 1817 | 0x10140567, /* Thinkpad T43p 2668-G7U */ |
| 1818 | 0x10140581, /* Thinkpad X41-2527 */ |
Daniel T Chen | af9a75d | 2010-01-09 01:22:29 -0500 | [diff] [blame] | 1819 | 0x10280160, /* Dell Dimension 2400 */ |
Daniel T Chen | 8286c53 | 2007-05-15 11:46:23 +0200 | [diff] [blame] | 1820 | 0x104380b0, /* Asus A7V8X-MX */ |
| 1821 | 0x11790241, /* Toshiba Satellite A-15 S127 */ |
Daniel Chen | 5cd165e | 2010-03-28 13:32:34 -0700 | [diff] [blame] | 1822 | 0x1179ff10, /* Toshiba P500 */ |
Daniel T Chen | 8286c53 | 2007-05-15 11:46:23 +0200 | [diff] [blame] | 1823 | 0x144dc01a, /* Samsung NP-X20C004/SEG */ |
Takashi Iwai | 128a46a | 2006-01-11 18:15:43 +0100 | [diff] [blame] | 1824 | 0 /* end */ |
| 1825 | }; |
| 1826 | |
| 1827 | static int check_list(struct snd_ac97 *ac97, const unsigned int *list) |
| 1828 | { |
| 1829 | u32 subid = ((u32)ac97->subsystem_vendor << 16) | ac97->subsystem_device; |
| 1830 | for (; *list; list++) |
| 1831 | if (*list == subid) |
| 1832 | return 1; |
| 1833 | return 0; |
| 1834 | } |
| 1835 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1836 | static int patch_ad1981a_specific(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | { |
Takashi Iwai | 128a46a | 2006-01-11 18:15:43 +0100 | [diff] [blame] | 1838 | if (check_list(ac97, ad1981_jacks_blacklist)) |
| 1839 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense, |
| 1841 | ARRAY_SIZE(snd_ac97_ad1981x_jack_sense)); |
| 1842 | } |
| 1843 | |
Hanno Boeck | 3e8b3b9 | 2011-01-14 19:14:47 +0100 | [diff] [blame] | 1844 | static const struct snd_ac97_build_ops patch_ad1981a_build_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | .build_post_spdif = patch_ad198x_post_spdif, |
| 1846 | .build_specific = patch_ad1981a_specific, |
| 1847 | #ifdef CONFIG_PM |
| 1848 | .resume = ad18xx_resume |
| 1849 | #endif |
| 1850 | }; |
| 1851 | |
Takashi Iwai | 128a46a | 2006-01-11 18:15:43 +0100 | [diff] [blame] | 1852 | /* white list to enable HP jack-sense bits |
| 1853 | * (SS vendor << 16 | device) |
| 1854 | */ |
| 1855 | static unsigned int ad1981_jacks_whitelist[] = { |
| 1856 | 0x0e11005a, /* HP nc4000/4010 */ |
| 1857 | 0x103c0890, /* HP nc6000 */ |
| 1858 | 0x103c0938, /* HP nc4220 */ |
| 1859 | 0x103c099c, /* HP nx6110 */ |
| 1860 | 0x103c0944, /* HP nc6220 */ |
| 1861 | 0x103c0934, /* HP nc8220 */ |
| 1862 | 0x103c006d, /* HP nx9105 */ |
Daniel T Chen | eade7b2 | 2011-08-14 22:43:01 -0400 | [diff] [blame] | 1863 | 0x103c300d, /* HP Compaq dc5100 SFF(PT003AW) */ |
Takashi Iwai | 128a46a | 2006-01-11 18:15:43 +0100 | [diff] [blame] | 1864 | 0x17340088, /* FSC Scenic-W */ |
| 1865 | 0 /* end */ |
| 1866 | }; |
| 1867 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1868 | static void check_ad1981_hp_jack_sense(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1869 | { |
Takashi Iwai | 128a46a | 2006-01-11 18:15:43 +0100 | [diff] [blame] | 1870 | if (check_list(ac97, ad1981_jacks_whitelist)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1871 | /* enable headphone jack sense */ |
| 1872 | snd_ac97_update_bits(ac97, AC97_AD_JACK_SPDIF, 1<<11, 1<<11); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1873 | } |
| 1874 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 1875 | static int patch_ad1981a(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | { |
| 1877 | patch_ad1881(ac97); |
| 1878 | ac97->build_ops = &patch_ad1981a_build_ops; |
| 1879 | snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT); |
| 1880 | ac97->flags |= AC97_STEREO_MUTES; |
| 1881 | check_ad1981_hp_jack_sense(ac97); |
| 1882 | return 0; |
| 1883 | } |
| 1884 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1885 | static const struct snd_kcontrol_new snd_ac97_ad198x_2cmic = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1886 | AC97_SINGLE("Stereo Mic", AC97_AD_MISC, 6, 1, 0); |
| 1887 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1888 | static int patch_ad1981b_specific(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | { |
| 1890 | int err; |
| 1891 | |
| 1892 | if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0) |
| 1893 | return err; |
Takashi Iwai | 128a46a | 2006-01-11 18:15:43 +0100 | [diff] [blame] | 1894 | if (check_list(ac97, ad1981_jacks_blacklist)) |
| 1895 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1896 | return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense, |
| 1897 | ARRAY_SIZE(snd_ac97_ad1981x_jack_sense)); |
| 1898 | } |
| 1899 | |
Hanno Boeck | 3e8b3b9 | 2011-01-14 19:14:47 +0100 | [diff] [blame] | 1900 | static const struct snd_ac97_build_ops patch_ad1981b_build_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1901 | .build_post_spdif = patch_ad198x_post_spdif, |
| 1902 | .build_specific = patch_ad1981b_specific, |
| 1903 | #ifdef CONFIG_PM |
| 1904 | .resume = ad18xx_resume |
| 1905 | #endif |
| 1906 | }; |
| 1907 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 1908 | static int patch_ad1981b(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | { |
| 1910 | patch_ad1881(ac97); |
| 1911 | ac97->build_ops = &patch_ad1981b_build_ops; |
| 1912 | snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT); |
| 1913 | ac97->flags |= AC97_STEREO_MUTES; |
| 1914 | check_ad1981_hp_jack_sense(ac97); |
| 1915 | return 0; |
| 1916 | } |
| 1917 | |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 1918 | #define snd_ac97_ad1888_lohpsel_info snd_ctl_boolean_mono_info |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1920 | static int snd_ac97_ad1888_lohpsel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1922 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1923 | unsigned short val; |
| 1924 | |
| 1925 | val = ac97->regs[AC97_AD_MISC]; |
| 1926 | ucontrol->value.integer.value[0] = !(val & AC97_AD198X_LOSEL); |
Takashi Iwai | e48d6d9 | 2008-05-29 08:16:56 +0200 | [diff] [blame] | 1927 | if (ac97->spec.ad18xx.lo_as_master) |
| 1928 | ucontrol->value.integer.value[0] = |
| 1929 | !ucontrol->value.integer.value[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1930 | return 0; |
| 1931 | } |
| 1932 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1933 | static int snd_ac97_ad1888_lohpsel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1934 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1935 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | unsigned short val; |
| 1937 | |
Takashi Iwai | e48d6d9 | 2008-05-29 08:16:56 +0200 | [diff] [blame] | 1938 | val = !ucontrol->value.integer.value[0]; |
| 1939 | if (ac97->spec.ad18xx.lo_as_master) |
| 1940 | val = !val; |
| 1941 | val = val ? (AC97_AD198X_LOSEL | AC97_AD198X_HPSEL) : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1942 | return snd_ac97_update_bits(ac97, AC97_AD_MISC, |
| 1943 | AC97_AD198X_LOSEL | AC97_AD198X_HPSEL, val); |
| 1944 | } |
| 1945 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1946 | static int snd_ac97_ad1888_downmix_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1947 | { |
Takashi Iwai | 3b7a00d | 2014-10-20 18:15:36 +0200 | [diff] [blame^] | 1948 | static const char * const texts[3] = {"Off", "6 -> 4", "6 -> 2"}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1949 | |
Takashi Iwai | 3b7a00d | 2014-10-20 18:15:36 +0200 | [diff] [blame^] | 1950 | return snd_ctl_enum_info(uinfo, 1, 3, texts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1951 | } |
| 1952 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1953 | static int snd_ac97_ad1888_downmix_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1954 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1955 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1956 | unsigned short val; |
| 1957 | |
| 1958 | val = ac97->regs[AC97_AD_MISC]; |
| 1959 | if (!(val & AC97_AD198X_DMIX1)) |
| 1960 | ucontrol->value.enumerated.item[0] = 0; |
| 1961 | else |
| 1962 | ucontrol->value.enumerated.item[0] = 1 + ((val >> 8) & 1); |
| 1963 | return 0; |
| 1964 | } |
| 1965 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1966 | static int snd_ac97_ad1888_downmix_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1968 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1969 | unsigned short val; |
| 1970 | |
| 1971 | if (ucontrol->value.enumerated.item[0] > 2) |
| 1972 | return -EINVAL; |
| 1973 | if (ucontrol->value.enumerated.item[0] == 0) |
| 1974 | val = 0; |
| 1975 | else |
| 1976 | val = AC97_AD198X_DMIX1 | |
| 1977 | ((ucontrol->value.enumerated.item[0] - 1) << 8); |
| 1978 | return snd_ac97_update_bits(ac97, AC97_AD_MISC, |
| 1979 | AC97_AD198X_DMIX0 | AC97_AD198X_DMIX1, val); |
| 1980 | } |
| 1981 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1982 | static void ad1888_update_jacks(struct snd_ac97 *ac97) |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 1983 | { |
Takashi Iwai | 4525c9f | 2005-09-13 11:47:07 +0200 | [diff] [blame] | 1984 | unsigned short val = 0; |
Randy Cushman | c26a8de | 2007-03-09 11:32:22 +0100 | [diff] [blame] | 1985 | /* clear LODIS if shared jack is to be used for Surround out */ |
Takashi Iwai | e48d6d9 | 2008-05-29 08:16:56 +0200 | [diff] [blame] | 1986 | if (!ac97->spec.ad18xx.lo_as_master && is_shared_linein(ac97)) |
Takashi Iwai | 4525c9f | 2005-09-13 11:47:07 +0200 | [diff] [blame] | 1987 | val |= (1 << 12); |
Randy Cushman | c26a8de | 2007-03-09 11:32:22 +0100 | [diff] [blame] | 1988 | /* clear CLDIS if shared jack is to be used for C/LFE out */ |
| 1989 | if (is_shared_micin(ac97)) |
Takashi Iwai | 4525c9f | 2005-09-13 11:47:07 +0200 | [diff] [blame] | 1990 | val |= (1 << 11); |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 1991 | /* shared Line-In */ |
Takashi Iwai | 4525c9f | 2005-09-13 11:47:07 +0200 | [diff] [blame] | 1992 | snd_ac97_update_bits(ac97, AC97_AD_MISC, (1 << 11) | (1 << 12), val); |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 1993 | } |
| 1994 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1995 | static const struct snd_kcontrol_new snd_ac97_ad1888_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1996 | { |
| 1997 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1998 | .name = "Exchange Front/Surround", |
| 1999 | .info = snd_ac97_ad1888_lohpsel_info, |
| 2000 | .get = snd_ac97_ad1888_lohpsel_get, |
| 2001 | .put = snd_ac97_ad1888_lohpsel_put |
| 2002 | }, |
Andres Salomon | 0bed7b2 | 2008-11-05 17:29:53 -0500 | [diff] [blame] | 2003 | AC97_SINGLE("V_REFOUT Enable", AC97_AD_MISC, AC97_AD_VREFD_SHIFT, 1, 1), |
| 2004 | AC97_SINGLE("High Pass Filter Enable", AC97_AD_TEST2, |
| 2005 | AC97_AD_HPFD_SHIFT, 1, 1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2006 | AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC, 7, 1, 0), |
| 2007 | { |
| 2008 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2009 | .name = "Downmix", |
| 2010 | .info = snd_ac97_ad1888_downmix_info, |
| 2011 | .get = snd_ac97_ad1888_downmix_get, |
| 2012 | .put = snd_ac97_ad1888_downmix_put |
| 2013 | }, |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2014 | AC97_SURROUND_JACK_MODE_CTL, |
| 2015 | AC97_CHANNEL_MODE_CTL, |
Sergey Ulanov | eeacb54 | 2005-07-27 17:28:58 +0200 | [diff] [blame] | 2016 | |
| 2017 | AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0), |
| 2018 | AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2019 | }; |
| 2020 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2021 | static int patch_ad1888_specific(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2022 | { |
Takashi Iwai | e48d6d9 | 2008-05-29 08:16:56 +0200 | [diff] [blame] | 2023 | if (!ac97->spec.ad18xx.lo_as_master) { |
| 2024 | /* rename 0x04 as "Master" and 0x02 as "Master Surround" */ |
| 2025 | snd_ac97_rename_vol_ctl(ac97, "Master Playback", |
| 2026 | "Master Surround Playback"); |
| 2027 | snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", |
| 2028 | "Master Playback"); |
| 2029 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | return patch_build_controls(ac97, snd_ac97_ad1888_controls, ARRAY_SIZE(snd_ac97_ad1888_controls)); |
| 2031 | } |
| 2032 | |
Hanno Boeck | 3e8b3b9 | 2011-01-14 19:14:47 +0100 | [diff] [blame] | 2033 | static const struct snd_ac97_build_ops patch_ad1888_build_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2034 | .build_post_spdif = patch_ad198x_post_spdif, |
| 2035 | .build_specific = patch_ad1888_specific, |
| 2036 | #ifdef CONFIG_PM |
Jaya Kumar | 1561f09 | 2006-06-19 15:06:14 +0200 | [diff] [blame] | 2037 | .resume = ad1888_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | #endif |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2039 | .update_jacks = ad1888_update_jacks, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | }; |
| 2041 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 2042 | static int patch_ad1888(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2043 | { |
| 2044 | unsigned short misc; |
| 2045 | |
| 2046 | patch_ad1881(ac97); |
| 2047 | ac97->build_ops = &patch_ad1888_build_ops; |
Takashi Iwai | e48d6d9 | 2008-05-29 08:16:56 +0200 | [diff] [blame] | 2048 | |
| 2049 | /* |
| 2050 | * LO can be used as a real line-out on some devices, |
| 2051 | * and we need to revert the front/surround mixer switches |
| 2052 | */ |
| 2053 | if (ac97->subsystem_vendor == 0x1043 && |
| 2054 | ac97->subsystem_device == 0x1193) /* ASUS A9T laptop */ |
| 2055 | ac97->spec.ad18xx.lo_as_master = 1; |
| 2056 | |
| 2057 | misc = snd_ac97_read(ac97, AC97_AD_MISC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2058 | /* AD-compatible mode */ |
| 2059 | /* Stereo mutes enabled */ |
Takashi Iwai | e48d6d9 | 2008-05-29 08:16:56 +0200 | [diff] [blame] | 2060 | misc |= AC97_AD198X_MSPLT | AC97_AD198X_AC97NC; |
| 2061 | if (!ac97->spec.ad18xx.lo_as_master) |
| 2062 | /* Switch FRONT/SURROUND LINE-OUT/HP-OUT default connection */ |
| 2063 | /* it seems that most vendors connect line-out connector to |
| 2064 | * headphone out of AC'97 |
| 2065 | */ |
| 2066 | misc |= AC97_AD198X_LOSEL | AC97_AD198X_HPSEL; |
| 2067 | |
| 2068 | snd_ac97_write_cache(ac97, AC97_AD_MISC, misc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2069 | ac97->flags |= AC97_STEREO_MUTES; |
| 2070 | return 0; |
| 2071 | } |
| 2072 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2073 | static int patch_ad1980_specific(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 | { |
| 2075 | int err; |
| 2076 | |
| 2077 | if ((err = patch_ad1888_specific(ac97)) < 0) |
| 2078 | return err; |
| 2079 | return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1); |
| 2080 | } |
| 2081 | |
Hanno Boeck | 3e8b3b9 | 2011-01-14 19:14:47 +0100 | [diff] [blame] | 2082 | static const struct snd_ac97_build_ops patch_ad1980_build_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2083 | .build_post_spdif = patch_ad198x_post_spdif, |
| 2084 | .build_specific = patch_ad1980_specific, |
| 2085 | #ifdef CONFIG_PM |
Clemens Ladisch | 462c417 | 2005-05-10 14:50:31 +0200 | [diff] [blame] | 2086 | .resume = ad18xx_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2087 | #endif |
Clemens Ladisch | 462c417 | 2005-05-10 14:50:31 +0200 | [diff] [blame] | 2088 | .update_jacks = ad1888_update_jacks, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2089 | }; |
| 2090 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 2091 | static int patch_ad1980(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2092 | { |
| 2093 | patch_ad1888(ac97); |
| 2094 | ac97->build_ops = &patch_ad1980_build_ops; |
| 2095 | return 0; |
| 2096 | } |
| 2097 | |
Randy Cushman | 6428ea1 | 2006-12-21 19:17:29 +0100 | [diff] [blame] | 2098 | static int snd_ac97_ad1985_vrefout_info(struct snd_kcontrol *kcontrol, |
| 2099 | struct snd_ctl_elem_info *uinfo) |
| 2100 | { |
Takashi Iwai | 3b7a00d | 2014-10-20 18:15:36 +0200 | [diff] [blame^] | 2101 | static const char * const texts[4] = { |
| 2102 | "High-Z", "3.7 V", "2.25 V", "0 V" |
| 2103 | }; |
Randy Cushman | 6428ea1 | 2006-12-21 19:17:29 +0100 | [diff] [blame] | 2104 | |
Takashi Iwai | 3b7a00d | 2014-10-20 18:15:36 +0200 | [diff] [blame^] | 2105 | return snd_ctl_enum_info(uinfo, 1, 4, texts); |
Randy Cushman | 6428ea1 | 2006-12-21 19:17:29 +0100 | [diff] [blame] | 2106 | } |
| 2107 | |
| 2108 | static int snd_ac97_ad1985_vrefout_get(struct snd_kcontrol *kcontrol, |
| 2109 | struct snd_ctl_elem_value *ucontrol) |
| 2110 | { |
| 2111 | static const int reg2ctrl[4] = {2, 0, 1, 3}; |
| 2112 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
| 2113 | unsigned short val; |
| 2114 | val = (ac97->regs[AC97_AD_MISC] & AC97_AD198X_VREF_MASK) |
| 2115 | >> AC97_AD198X_VREF_SHIFT; |
| 2116 | ucontrol->value.enumerated.item[0] = reg2ctrl[val]; |
| 2117 | return 0; |
| 2118 | } |
| 2119 | |
| 2120 | static int snd_ac97_ad1985_vrefout_put(struct snd_kcontrol *kcontrol, |
| 2121 | struct snd_ctl_elem_value *ucontrol) |
| 2122 | { |
| 2123 | static const int ctrl2reg[4] = {1, 2, 0, 3}; |
| 2124 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
| 2125 | unsigned short val; |
| 2126 | |
Takashi Iwai | 4e98d6a | 2007-11-15 15:58:13 +0100 | [diff] [blame] | 2127 | if (ucontrol->value.enumerated.item[0] > 3) |
Randy Cushman | 6428ea1 | 2006-12-21 19:17:29 +0100 | [diff] [blame] | 2128 | return -EINVAL; |
| 2129 | val = ctrl2reg[ucontrol->value.enumerated.item[0]] |
| 2130 | << AC97_AD198X_VREF_SHIFT; |
| 2131 | return snd_ac97_update_bits(ac97, AC97_AD_MISC, |
| 2132 | AC97_AD198X_VREF_MASK, val); |
| 2133 | } |
| 2134 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2135 | static const struct snd_kcontrol_new snd_ac97_ad1985_controls[] = { |
Randy Cushman | 6428ea1 | 2006-12-21 19:17:29 +0100 | [diff] [blame] | 2136 | AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0), |
| 2137 | { |
| 2138 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2139 | .name = "Exchange Front/Surround", |
| 2140 | .info = snd_ac97_ad1888_lohpsel_info, |
| 2141 | .get = snd_ac97_ad1888_lohpsel_get, |
| 2142 | .put = snd_ac97_ad1888_lohpsel_put |
| 2143 | }, |
| 2144 | AC97_SINGLE("High Pass Filter Enable", AC97_AD_TEST2, 12, 1, 1), |
| 2145 | AC97_SINGLE("Spread Front to Surround and Center/LFE", |
| 2146 | AC97_AD_MISC, 7, 1, 0), |
| 2147 | { |
| 2148 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2149 | .name = "Downmix", |
| 2150 | .info = snd_ac97_ad1888_downmix_info, |
| 2151 | .get = snd_ac97_ad1888_downmix_get, |
| 2152 | .put = snd_ac97_ad1888_downmix_put |
| 2153 | }, |
| 2154 | { |
| 2155 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2156 | .name = "V_REFOUT", |
| 2157 | .info = snd_ac97_ad1985_vrefout_info, |
| 2158 | .get = snd_ac97_ad1985_vrefout_get, |
| 2159 | .put = snd_ac97_ad1985_vrefout_put |
| 2160 | }, |
| 2161 | AC97_SURROUND_JACK_MODE_CTL, |
| 2162 | AC97_CHANNEL_MODE_CTL, |
| 2163 | |
| 2164 | AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0), |
| 2165 | AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2166 | }; |
| 2167 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2168 | static void ad1985_update_jacks(struct snd_ac97 *ac97) |
Takashi Iwai | e5b3f45 | 2005-05-17 17:17:57 +0200 | [diff] [blame] | 2169 | { |
Takashi Iwai | 4525c9f | 2005-09-13 11:47:07 +0200 | [diff] [blame] | 2170 | ad1888_update_jacks(ac97); |
Randy Cushman | c26a8de | 2007-03-09 11:32:22 +0100 | [diff] [blame] | 2171 | /* clear OMS if shared jack is to be used for C/LFE out */ |
Takashi Iwai | fc232c6 | 2005-05-27 10:42:45 +0200 | [diff] [blame] | 2172 | snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 1 << 9, |
Randy Cushman | c26a8de | 2007-03-09 11:32:22 +0100 | [diff] [blame] | 2173 | is_shared_micin(ac97) ? 1 << 9 : 0); |
Takashi Iwai | e5b3f45 | 2005-05-17 17:17:57 +0200 | [diff] [blame] | 2174 | } |
| 2175 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2176 | static int patch_ad1985_specific(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2177 | { |
| 2178 | int err; |
| 2179 | |
Randy Cushman | 6428ea1 | 2006-12-21 19:17:29 +0100 | [diff] [blame] | 2180 | /* rename 0x04 as "Master" and 0x02 as "Master Surround" */ |
| 2181 | snd_ac97_rename_vol_ctl(ac97, "Master Playback", |
| 2182 | "Master Surround Playback"); |
| 2183 | snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback"); |
| 2184 | |
| 2185 | if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2186 | return err; |
Randy Cushman | 6428ea1 | 2006-12-21 19:17:29 +0100 | [diff] [blame] | 2187 | |
| 2188 | return patch_build_controls(ac97, snd_ac97_ad1985_controls, |
| 2189 | ARRAY_SIZE(snd_ac97_ad1985_controls)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2190 | } |
| 2191 | |
Hanno Boeck | 3e8b3b9 | 2011-01-14 19:14:47 +0100 | [diff] [blame] | 2192 | static const struct snd_ac97_build_ops patch_ad1985_build_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2193 | .build_post_spdif = patch_ad198x_post_spdif, |
| 2194 | .build_specific = patch_ad1985_specific, |
| 2195 | #ifdef CONFIG_PM |
Clemens Ladisch | 462c417 | 2005-05-10 14:50:31 +0200 | [diff] [blame] | 2196 | .resume = ad18xx_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2197 | #endif |
Takashi Iwai | e5b3f45 | 2005-05-17 17:17:57 +0200 | [diff] [blame] | 2198 | .update_jacks = ad1985_update_jacks, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2199 | }; |
| 2200 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 2201 | static int patch_ad1985(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2202 | { |
| 2203 | unsigned short misc; |
| 2204 | |
| 2205 | patch_ad1881(ac97); |
| 2206 | ac97->build_ops = &patch_ad1985_build_ops; |
| 2207 | misc = snd_ac97_read(ac97, AC97_AD_MISC); |
| 2208 | /* switch front/surround line-out/hp-out */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2209 | /* AD-compatible mode */ |
| 2210 | /* Stereo mutes enabled */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2211 | snd_ac97_write_cache(ac97, AC97_AD_MISC, misc | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2212 | AC97_AD198X_LOSEL | |
| 2213 | AC97_AD198X_HPSEL | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2214 | AC97_AD198X_MSPLT | |
| 2215 | AC97_AD198X_AC97NC); |
| 2216 | ac97->flags |= AC97_STEREO_MUTES; |
Randy Cushman | 6428ea1 | 2006-12-21 19:17:29 +0100 | [diff] [blame] | 2217 | |
| 2218 | /* update current jack configuration */ |
| 2219 | ad1985_update_jacks(ac97); |
| 2220 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2221 | /* on AD1985 rev. 3, AC'97 revision bits are zero */ |
| 2222 | ac97->ext_id = (ac97->ext_id & ~AC97_EI_REV_MASK) | AC97_EI_REV_23; |
| 2223 | return 0; |
| 2224 | } |
| 2225 | |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 2226 | #define snd_ac97_ad1986_bool_info snd_ctl_boolean_mono_info |
Randy Cushman | 67e9f4b | 2006-12-22 12:44:25 +0100 | [diff] [blame] | 2227 | |
| 2228 | static int snd_ac97_ad1986_lososel_get(struct snd_kcontrol *kcontrol, |
| 2229 | struct snd_ctl_elem_value *ucontrol) |
| 2230 | { |
| 2231 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
| 2232 | unsigned short val; |
| 2233 | |
| 2234 | val = ac97->regs[AC97_AD_MISC3]; |
| 2235 | ucontrol->value.integer.value[0] = (val & AC97_AD1986_LOSEL) != 0; |
| 2236 | return 0; |
| 2237 | } |
| 2238 | |
| 2239 | static int snd_ac97_ad1986_lososel_put(struct snd_kcontrol *kcontrol, |
| 2240 | struct snd_ctl_elem_value *ucontrol) |
| 2241 | { |
| 2242 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
| 2243 | int ret0; |
| 2244 | int ret1; |
| 2245 | int sprd = (ac97->regs[AC97_AD_MISC] & AC97_AD1986_SPRD) != 0; |
| 2246 | |
| 2247 | ret0 = snd_ac97_update_bits(ac97, AC97_AD_MISC3, AC97_AD1986_LOSEL, |
| 2248 | ucontrol->value.integer.value[0] != 0 |
| 2249 | ? AC97_AD1986_LOSEL : 0); |
| 2250 | if (ret0 < 0) |
| 2251 | return ret0; |
| 2252 | |
| 2253 | /* SOSEL is set to values of "Spread" or "Exchange F/S" controls */ |
| 2254 | ret1 = snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD1986_SOSEL, |
| 2255 | (ucontrol->value.integer.value[0] != 0 |
| 2256 | || sprd) |
| 2257 | ? AC97_AD1986_SOSEL : 0); |
| 2258 | if (ret1 < 0) |
| 2259 | return ret1; |
| 2260 | |
| 2261 | return (ret0 > 0 || ret1 > 0) ? 1 : 0; |
| 2262 | } |
| 2263 | |
| 2264 | static int snd_ac97_ad1986_spread_get(struct snd_kcontrol *kcontrol, |
| 2265 | struct snd_ctl_elem_value *ucontrol) |
| 2266 | { |
| 2267 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
| 2268 | unsigned short val; |
| 2269 | |
| 2270 | val = ac97->regs[AC97_AD_MISC]; |
| 2271 | ucontrol->value.integer.value[0] = (val & AC97_AD1986_SPRD) != 0; |
| 2272 | return 0; |
| 2273 | } |
| 2274 | |
| 2275 | static int snd_ac97_ad1986_spread_put(struct snd_kcontrol *kcontrol, |
| 2276 | struct snd_ctl_elem_value *ucontrol) |
| 2277 | { |
| 2278 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
| 2279 | int ret0; |
| 2280 | int ret1; |
| 2281 | int sprd = (ac97->regs[AC97_AD_MISC3] & AC97_AD1986_LOSEL) != 0; |
| 2282 | |
| 2283 | ret0 = snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD1986_SPRD, |
| 2284 | ucontrol->value.integer.value[0] != 0 |
| 2285 | ? AC97_AD1986_SPRD : 0); |
| 2286 | if (ret0 < 0) |
| 2287 | return ret0; |
| 2288 | |
| 2289 | /* SOSEL is set to values of "Spread" or "Exchange F/S" controls */ |
| 2290 | ret1 = snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD1986_SOSEL, |
| 2291 | (ucontrol->value.integer.value[0] != 0 |
| 2292 | || sprd) |
| 2293 | ? AC97_AD1986_SOSEL : 0); |
| 2294 | if (ret1 < 0) |
| 2295 | return ret1; |
| 2296 | |
| 2297 | return (ret0 > 0 || ret1 > 0) ? 1 : 0; |
| 2298 | } |
| 2299 | |
| 2300 | static int snd_ac97_ad1986_miclisel_get(struct snd_kcontrol *kcontrol, |
| 2301 | struct snd_ctl_elem_value *ucontrol) |
| 2302 | { |
| 2303 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
| 2304 | |
| 2305 | ucontrol->value.integer.value[0] = ac97->spec.ad18xx.swap_mic_linein; |
| 2306 | return 0; |
| 2307 | } |
| 2308 | |
| 2309 | static int snd_ac97_ad1986_miclisel_put(struct snd_kcontrol *kcontrol, |
| 2310 | struct snd_ctl_elem_value *ucontrol) |
| 2311 | { |
| 2312 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
| 2313 | unsigned char swap = ucontrol->value.integer.value[0] != 0; |
| 2314 | |
| 2315 | if (swap != ac97->spec.ad18xx.swap_mic_linein) { |
| 2316 | ac97->spec.ad18xx.swap_mic_linein = swap; |
| 2317 | if (ac97->build_ops->update_jacks) |
| 2318 | ac97->build_ops->update_jacks(ac97); |
| 2319 | return 1; |
| 2320 | } |
| 2321 | return 0; |
| 2322 | } |
| 2323 | |
| 2324 | static int snd_ac97_ad1986_vrefout_get(struct snd_kcontrol *kcontrol, |
| 2325 | struct snd_ctl_elem_value *ucontrol) |
| 2326 | { |
| 2327 | /* Use MIC_1/2 V_REFOUT as the "get" value */ |
| 2328 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
| 2329 | unsigned short val; |
| 2330 | unsigned short reg = ac97->regs[AC97_AD_MISC2]; |
| 2331 | if ((reg & AC97_AD1986_MVREF0) != 0) |
| 2332 | val = 2; |
| 2333 | else if ((reg & AC97_AD1986_MVREF1) != 0) |
| 2334 | val = 3; |
| 2335 | else if ((reg & AC97_AD1986_MVREF2) != 0) |
| 2336 | val = 1; |
| 2337 | else |
| 2338 | val = 0; |
| 2339 | ucontrol->value.enumerated.item[0] = val; |
| 2340 | return 0; |
| 2341 | } |
| 2342 | |
| 2343 | static int snd_ac97_ad1986_vrefout_put(struct snd_kcontrol *kcontrol, |
| 2344 | struct snd_ctl_elem_value *ucontrol) |
| 2345 | { |
| 2346 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
| 2347 | unsigned short cval; |
| 2348 | unsigned short lval; |
| 2349 | unsigned short mval; |
| 2350 | int cret; |
| 2351 | int lret; |
| 2352 | int mret; |
| 2353 | |
| 2354 | switch (ucontrol->value.enumerated.item[0]) |
| 2355 | { |
| 2356 | case 0: /* High-Z */ |
| 2357 | cval = 0; |
| 2358 | lval = 0; |
| 2359 | mval = 0; |
| 2360 | break; |
| 2361 | case 1: /* 3.7 V */ |
| 2362 | cval = AC97_AD1986_CVREF2; |
| 2363 | lval = AC97_AD1986_LVREF2; |
| 2364 | mval = AC97_AD1986_MVREF2; |
| 2365 | break; |
| 2366 | case 2: /* 2.25 V */ |
| 2367 | cval = AC97_AD1986_CVREF0; |
| 2368 | lval = AC97_AD1986_LVREF0; |
| 2369 | mval = AC97_AD1986_MVREF0; |
| 2370 | break; |
| 2371 | case 3: /* 0 V */ |
| 2372 | cval = AC97_AD1986_CVREF1; |
| 2373 | lval = AC97_AD1986_LVREF1; |
| 2374 | mval = AC97_AD1986_MVREF1; |
| 2375 | break; |
| 2376 | default: |
| 2377 | return -EINVAL; |
| 2378 | } |
| 2379 | |
| 2380 | cret = snd_ac97_update_bits(ac97, AC97_AD_MISC2, |
| 2381 | AC97_AD1986_CVREF_MASK, cval); |
| 2382 | if (cret < 0) |
| 2383 | return cret; |
| 2384 | lret = snd_ac97_update_bits(ac97, AC97_AD_MISC3, |
| 2385 | AC97_AD1986_LVREF_MASK, lval); |
| 2386 | if (lret < 0) |
| 2387 | return lret; |
| 2388 | mret = snd_ac97_update_bits(ac97, AC97_AD_MISC2, |
| 2389 | AC97_AD1986_MVREF_MASK, mval); |
| 2390 | if (mret < 0) |
| 2391 | return mret; |
| 2392 | |
| 2393 | return (cret > 0 || lret > 0 || mret > 0) ? 1 : 0; |
| 2394 | } |
| 2395 | |
| 2396 | static const struct snd_kcontrol_new snd_ac97_ad1986_controls[] = { |
| 2397 | AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0), |
| 2398 | { |
| 2399 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2400 | .name = "Exchange Front/Surround", |
| 2401 | .info = snd_ac97_ad1986_bool_info, |
| 2402 | .get = snd_ac97_ad1986_lososel_get, |
| 2403 | .put = snd_ac97_ad1986_lososel_put |
| 2404 | }, |
| 2405 | { |
| 2406 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2407 | .name = "Exchange Mic/Line In", |
| 2408 | .info = snd_ac97_ad1986_bool_info, |
| 2409 | .get = snd_ac97_ad1986_miclisel_get, |
| 2410 | .put = snd_ac97_ad1986_miclisel_put |
| 2411 | }, |
| 2412 | { |
| 2413 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2414 | .name = "Spread Front to Surround and Center/LFE", |
| 2415 | .info = snd_ac97_ad1986_bool_info, |
| 2416 | .get = snd_ac97_ad1986_spread_get, |
| 2417 | .put = snd_ac97_ad1986_spread_put |
| 2418 | }, |
| 2419 | { |
| 2420 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2421 | .name = "Downmix", |
| 2422 | .info = snd_ac97_ad1888_downmix_info, |
| 2423 | .get = snd_ac97_ad1888_downmix_get, |
| 2424 | .put = snd_ac97_ad1888_downmix_put |
| 2425 | }, |
| 2426 | { |
| 2427 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2428 | .name = "V_REFOUT", |
| 2429 | .info = snd_ac97_ad1985_vrefout_info, |
| 2430 | .get = snd_ac97_ad1986_vrefout_get, |
| 2431 | .put = snd_ac97_ad1986_vrefout_put |
| 2432 | }, |
| 2433 | AC97_SURROUND_JACK_MODE_CTL, |
| 2434 | AC97_CHANNEL_MODE_CTL, |
| 2435 | |
| 2436 | AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0), |
| 2437 | AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0) |
| 2438 | }; |
| 2439 | |
| 2440 | static void ad1986_update_jacks(struct snd_ac97 *ac97) |
| 2441 | { |
| 2442 | unsigned short misc_val = 0; |
| 2443 | unsigned short ser_val; |
| 2444 | |
| 2445 | /* disable SURROUND and CENTER/LFE if not surround mode */ |
Randy Cushman | c26a8de | 2007-03-09 11:32:22 +0100 | [diff] [blame] | 2446 | if (!is_surround_on(ac97)) |
Randy Cushman | 67e9f4b | 2006-12-22 12:44:25 +0100 | [diff] [blame] | 2447 | misc_val |= AC97_AD1986_SODIS; |
Randy Cushman | c26a8de | 2007-03-09 11:32:22 +0100 | [diff] [blame] | 2448 | if (!is_clfe_on(ac97)) |
Randy Cushman | 67e9f4b | 2006-12-22 12:44:25 +0100 | [diff] [blame] | 2449 | misc_val |= AC97_AD1986_CLDIS; |
| 2450 | |
| 2451 | /* select line input (default=LINE_IN, SURROUND or MIC_1/2) */ |
| 2452 | if (is_shared_linein(ac97)) |
| 2453 | misc_val |= AC97_AD1986_LISEL_SURR; |
| 2454 | else if (ac97->spec.ad18xx.swap_mic_linein != 0) |
| 2455 | misc_val |= AC97_AD1986_LISEL_MIC; |
| 2456 | snd_ac97_update_bits(ac97, AC97_AD_MISC, |
| 2457 | AC97_AD1986_SODIS | AC97_AD1986_CLDIS | |
| 2458 | AC97_AD1986_LISEL_MASK, |
| 2459 | misc_val); |
| 2460 | |
| 2461 | /* select microphone input (MIC_1/2, Center/LFE or LINE_IN) */ |
| 2462 | if (is_shared_micin(ac97)) |
| 2463 | ser_val = AC97_AD1986_OMS_C; |
| 2464 | else if (ac97->spec.ad18xx.swap_mic_linein != 0) |
| 2465 | ser_val = AC97_AD1986_OMS_L; |
| 2466 | else |
| 2467 | ser_val = AC97_AD1986_OMS_M; |
| 2468 | snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, |
| 2469 | AC97_AD1986_OMS_MASK, |
| 2470 | ser_val); |
| 2471 | } |
| 2472 | |
| 2473 | static int patch_ad1986_specific(struct snd_ac97 *ac97) |
| 2474 | { |
| 2475 | int err; |
| 2476 | |
| 2477 | if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0) |
| 2478 | return err; |
| 2479 | |
| 2480 | return patch_build_controls(ac97, snd_ac97_ad1986_controls, |
| 2481 | ARRAY_SIZE(snd_ac97_ad1985_controls)); |
| 2482 | } |
| 2483 | |
Hanno Boeck | 3e8b3b9 | 2011-01-14 19:14:47 +0100 | [diff] [blame] | 2484 | static const struct snd_ac97_build_ops patch_ad1986_build_ops = { |
Randy Cushman | 67e9f4b | 2006-12-22 12:44:25 +0100 | [diff] [blame] | 2485 | .build_post_spdif = patch_ad198x_post_spdif, |
| 2486 | .build_specific = patch_ad1986_specific, |
| 2487 | #ifdef CONFIG_PM |
| 2488 | .resume = ad18xx_resume, |
| 2489 | #endif |
| 2490 | .update_jacks = ad1986_update_jacks, |
| 2491 | }; |
| 2492 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 2493 | static int patch_ad1986(struct snd_ac97 * ac97) |
Randy Cushman | 67e9f4b | 2006-12-22 12:44:25 +0100 | [diff] [blame] | 2494 | { |
| 2495 | patch_ad1881(ac97); |
| 2496 | ac97->build_ops = &patch_ad1986_build_ops; |
| 2497 | ac97->flags |= AC97_STEREO_MUTES; |
| 2498 | |
| 2499 | /* update current jack configuration */ |
| 2500 | ad1986_update_jacks(ac97); |
| 2501 | |
| 2502 | return 0; |
| 2503 | } |
| 2504 | |
Takashi Iwai | 8f4f4ef | 2008-08-05 15:45:45 +0200 | [diff] [blame] | 2505 | /* |
| 2506 | * realtek ALC203: use mono-out for pin 37 |
| 2507 | */ |
| 2508 | static int patch_alc203(struct snd_ac97 *ac97) |
| 2509 | { |
| 2510 | snd_ac97_update_bits(ac97, 0x7a, 0x400, 0x400); |
| 2511 | return 0; |
| 2512 | } |
Randy Cushman | 67e9f4b | 2006-12-22 12:44:25 +0100 | [diff] [blame] | 2513 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2514 | /* |
| 2515 | * realtek ALC65x/850 codecs |
| 2516 | */ |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2517 | static void alc650_update_jacks(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2518 | { |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2519 | int shared; |
| 2520 | |
Randy Cushman | 831466f | 2006-12-19 18:42:16 +0100 | [diff] [blame] | 2521 | /* shared Line-In / Surround Out */ |
| 2522 | shared = is_shared_surrout(ac97); |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2523 | snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 9, |
| 2524 | shared ? (1 << 9) : 0); |
Randy Cushman | 831466f | 2006-12-19 18:42:16 +0100 | [diff] [blame] | 2525 | /* update shared Mic In / Center/LFE Out */ |
| 2526 | shared = is_shared_clfeout(ac97); |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2527 | /* disable/enable vref */ |
| 2528 | snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12, |
| 2529 | shared ? (1 << 12) : 0); |
| 2530 | /* turn on/off center-on-mic */ |
| 2531 | snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 10, |
| 2532 | shared ? (1 << 10) : 0); |
| 2533 | /* GPIO0 high for mic */ |
| 2534 | snd_ac97_update_bits(ac97, AC97_ALC650_GPIO_STATUS, 0x100, |
| 2535 | shared ? 0 : 0x100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2536 | } |
| 2537 | |
Takashi Iwai | 833a493 | 2012-08-03 17:59:36 +0200 | [diff] [blame] | 2538 | static int alc650_swap_surround_put(struct snd_kcontrol *kcontrol, |
| 2539 | struct snd_ctl_elem_value *ucontrol) |
| 2540 | { |
| 2541 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
| 2542 | struct snd_pcm_chmap *map = ac97->chmaps[SNDRV_PCM_STREAM_PLAYBACK]; |
| 2543 | |
| 2544 | if (map) { |
| 2545 | if (ucontrol->value.integer.value[0]) |
| 2546 | map->chmap = snd_pcm_std_chmaps; |
| 2547 | else |
| 2548 | map->chmap = snd_pcm_alt_chmaps; |
| 2549 | } |
| 2550 | return snd_ac97_put_volsw(kcontrol, ucontrol); |
| 2551 | } |
| 2552 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2553 | static const struct snd_kcontrol_new snd_ac97_controls_alc650[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2554 | AC97_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0), |
| 2555 | AC97_SINGLE("Surround Down Mix", AC97_ALC650_MULTICH, 1, 1, 0), |
| 2556 | AC97_SINGLE("Center/LFE Down Mix", AC97_ALC650_MULTICH, 2, 1, 0), |
| 2557 | AC97_SINGLE("Exchange Center/LFE", AC97_ALC650_MULTICH, 3, 1, 0), |
| 2558 | /* 4: Analog Input To Surround */ |
| 2559 | /* 5: Analog Input To Center/LFE */ |
| 2560 | /* 6: Independent Master Volume Right */ |
| 2561 | /* 7: Independent Master Volume Left */ |
| 2562 | /* 8: reserved */ |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2563 | /* 9: Line-In/Surround share */ |
| 2564 | /* 10: Mic/CLFE share */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2565 | /* 11-13: in IEC958 controls */ |
Takashi Iwai | 833a493 | 2012-08-03 17:59:36 +0200 | [diff] [blame] | 2566 | { |
| 2567 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2568 | .name = "Swap Surround Slot", |
| 2569 | .info = snd_ac97_info_volsw, |
| 2570 | .get = snd_ac97_get_volsw, |
| 2571 | .put = alc650_swap_surround_put, |
| 2572 | .private_value = AC97_SINGLE_VALUE(AC97_ALC650_MULTICH, 14, 1, 0), |
| 2573 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2574 | #if 0 /* always set in patch_alc650 */ |
| 2575 | AC97_SINGLE("IEC958 Input Clock Enable", AC97_ALC650_CLOCK, 0, 1, 0), |
| 2576 | AC97_SINGLE("IEC958 Input Pin Enable", AC97_ALC650_CLOCK, 1, 1, 0), |
| 2577 | AC97_SINGLE("Surround DAC Switch", AC97_ALC650_SURR_DAC_VOL, 15, 1, 1), |
| 2578 | AC97_DOUBLE("Surround DAC Volume", AC97_ALC650_SURR_DAC_VOL, 8, 0, 31, 1), |
| 2579 | AC97_SINGLE("Center/LFE DAC Switch", AC97_ALC650_LFE_DAC_VOL, 15, 1, 1), |
| 2580 | AC97_DOUBLE("Center/LFE DAC Volume", AC97_ALC650_LFE_DAC_VOL, 8, 0, 31, 1), |
| 2581 | #endif |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2582 | AC97_SURROUND_JACK_MODE_CTL, |
| 2583 | AC97_CHANNEL_MODE_CTL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2584 | }; |
| 2585 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2586 | static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc650[] = { |
Clemens Ladisch | 10e8d78 | 2005-08-03 13:40:08 +0200 | [diff] [blame] | 2587 | AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2588 | AC97_SINGLE("Analog to IEC958 Output", AC97_ALC650_MULTICH, 12, 1, 0), |
| 2589 | /* disable this controls since it doesn't work as expected */ |
| 2590 | /* AC97_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 13, 1, 0), */ |
| 2591 | }; |
| 2592 | |
Takashi Iwai | 0cb29ea | 2007-01-29 15:33:49 +0100 | [diff] [blame] | 2593 | static const DECLARE_TLV_DB_SCALE(db_scale_5bit_3db_max, -4350, 150, 0); |
Takashi Iwai | 2f3482f | 2006-08-21 18:44:31 +0200 | [diff] [blame] | 2594 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2595 | static int patch_alc650_specific(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2596 | { |
| 2597 | int err; |
| 2598 | |
| 2599 | if ((err = patch_build_controls(ac97, snd_ac97_controls_alc650, ARRAY_SIZE(snd_ac97_controls_alc650))) < 0) |
| 2600 | return err; |
| 2601 | if (ac97->ext_id & AC97_EI_SPDIF) { |
| 2602 | if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc650, ARRAY_SIZE(snd_ac97_spdif_controls_alc650))) < 0) |
| 2603 | return err; |
| 2604 | } |
Takashi Iwai | 2f3482f | 2006-08-21 18:44:31 +0200 | [diff] [blame] | 2605 | if (ac97->id != AC97_ID_ALC650F) |
| 2606 | reset_tlv(ac97, "Master Playback Volume", |
| 2607 | db_scale_5bit_3db_max); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2608 | return 0; |
| 2609 | } |
| 2610 | |
Hanno Boeck | 3e8b3b9 | 2011-01-14 19:14:47 +0100 | [diff] [blame] | 2611 | static const struct snd_ac97_build_ops patch_alc650_ops = { |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2612 | .build_specific = patch_alc650_specific, |
| 2613 | .update_jacks = alc650_update_jacks |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2614 | }; |
| 2615 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 2616 | static int patch_alc650(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2617 | { |
| 2618 | unsigned short val; |
| 2619 | |
| 2620 | ac97->build_ops = &patch_alc650_ops; |
| 2621 | |
| 2622 | /* determine the revision */ |
| 2623 | val = snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f; |
| 2624 | if (val < 3) |
| 2625 | ac97->id = 0x414c4720; /* Old version */ |
| 2626 | else if (val < 0x10) |
| 2627 | ac97->id = 0x414c4721; /* D version */ |
| 2628 | else if (val < 0x20) |
| 2629 | ac97->id = 0x414c4722; /* E version */ |
| 2630 | else if (val < 0x30) |
| 2631 | ac97->id = 0x414c4723; /* F version */ |
| 2632 | |
| 2633 | /* revision E or F */ |
| 2634 | /* FIXME: what about revision D ? */ |
| 2635 | ac97->spec.dev_flags = (ac97->id == 0x414c4722 || |
| 2636 | ac97->id == 0x414c4723); |
| 2637 | |
| 2638 | /* enable AC97_ALC650_GPIO_SETUP, AC97_ALC650_CLOCK for R/W */ |
| 2639 | snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS, |
| 2640 | snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x8000); |
| 2641 | |
| 2642 | /* Enable SPDIF-IN only on Rev.E and above */ |
| 2643 | val = snd_ac97_read(ac97, AC97_ALC650_CLOCK); |
| 2644 | /* SPDIF IN with pin 47 */ |
Takashi Iwai | eed6564 | 2006-05-02 18:22:06 +0200 | [diff] [blame] | 2645 | if (ac97->spec.dev_flags && |
| 2646 | /* ASUS A6KM requires EAPD */ |
| 2647 | ! (ac97->subsystem_vendor == 0x1043 && |
| 2648 | ac97->subsystem_device == 0x1103)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2649 | val |= 0x03; /* enable */ |
| 2650 | else |
| 2651 | val &= ~0x03; /* disable */ |
| 2652 | snd_ac97_write_cache(ac97, AC97_ALC650_CLOCK, val); |
| 2653 | |
| 2654 | /* set default: slot 3,4,7,8,6,9 |
| 2655 | spdif-in monitor off, analog-spdif off, spdif-in off |
| 2656 | center on mic off, surround on line-in off |
| 2657 | downmix off, duplicate front off |
| 2658 | */ |
| 2659 | snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 0); |
| 2660 | |
| 2661 | /* set GPIO0 for mic bias */ |
| 2662 | /* GPIO0 pin output, no interrupt, high */ |
| 2663 | snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_SETUP, |
| 2664 | snd_ac97_read(ac97, AC97_ALC650_GPIO_SETUP) | 0x01); |
| 2665 | snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS, |
| 2666 | (snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x100) & ~0x10); |
| 2667 | |
| 2668 | /* full DAC volume */ |
| 2669 | snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808); |
| 2670 | snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808); |
| 2671 | return 0; |
| 2672 | } |
| 2673 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2674 | static void alc655_update_jacks(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2675 | { |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2676 | int shared; |
| 2677 | |
Randy Cushman | 831466f | 2006-12-19 18:42:16 +0100 | [diff] [blame] | 2678 | /* shared Line-In / Surround Out */ |
| 2679 | shared = is_shared_surrout(ac97); |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2680 | ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 9, |
| 2681 | shared ? (1 << 9) : 0, 0); |
Randy Cushman | 831466f | 2006-12-19 18:42:16 +0100 | [diff] [blame] | 2682 | /* update shared Mic In / Center/LFE Out */ |
| 2683 | shared = is_shared_clfeout(ac97); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2684 | /* misc control; vrefout disable */ |
| 2685 | snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12, |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2686 | shared ? (1 << 12) : 0); |
| 2687 | ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 10, |
| 2688 | shared ? (1 << 10) : 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2689 | } |
| 2690 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2691 | static const struct snd_kcontrol_new snd_ac97_controls_alc655[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2692 | AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0), |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2693 | AC97_SURROUND_JACK_MODE_CTL, |
| 2694 | AC97_CHANNEL_MODE_CTL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2695 | }; |
| 2696 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2697 | static int alc655_iec958_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2698 | { |
Takashi Iwai | 3b7a00d | 2014-10-20 18:15:36 +0200 | [diff] [blame^] | 2699 | static const char * const texts_655[3] = { |
| 2700 | "PCM", "Analog In", "IEC958 In" |
| 2701 | }; |
| 2702 | static const char * const texts_658[4] = { |
| 2703 | "PCM", "Analog1 In", "Analog2 In", "IEC958 In" |
| 2704 | }; |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2705 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2706 | |
Takashi Iwai | 3b7a00d | 2014-10-20 18:15:36 +0200 | [diff] [blame^] | 2707 | if (ac97->spec.dev_flags) |
| 2708 | return snd_ctl_enum_info(uinfo, 1, 4, texts_658); |
| 2709 | else |
| 2710 | return snd_ctl_enum_info(uinfo, 1, 3, texts_655); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2711 | } |
| 2712 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2713 | static int alc655_iec958_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2714 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2715 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2716 | unsigned short val; |
| 2717 | |
| 2718 | val = ac97->regs[AC97_ALC650_MULTICH]; |
| 2719 | val = (val >> 12) & 3; |
| 2720 | if (ac97->spec.dev_flags && val == 3) |
| 2721 | val = 0; |
| 2722 | ucontrol->value.enumerated.item[0] = val; |
| 2723 | return 0; |
| 2724 | } |
| 2725 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2726 | static int alc655_iec958_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2727 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2728 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2729 | |
| 2730 | return ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 3 << 12, |
| 2731 | (unsigned short)ucontrol->value.enumerated.item[0] << 12, |
| 2732 | 0); |
| 2733 | } |
| 2734 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2735 | static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc655[] = { |
Clemens Ladisch | 10e8d78 | 2005-08-03 13:40:08 +0200 | [diff] [blame] | 2736 | AC97_PAGE_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2737 | /* disable this controls since it doesn't work as expected */ |
| 2738 | /* AC97_PAGE_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 14, 1, 0, 0), */ |
| 2739 | { |
| 2740 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Takashi Iwai | 031c95d | 2005-12-05 20:51:43 +0100 | [diff] [blame] | 2741 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2742 | .info = alc655_iec958_route_info, |
| 2743 | .get = alc655_iec958_route_get, |
| 2744 | .put = alc655_iec958_route_put, |
| 2745 | }, |
| 2746 | }; |
| 2747 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2748 | static int patch_alc655_specific(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2749 | { |
| 2750 | int err; |
| 2751 | |
| 2752 | if ((err = patch_build_controls(ac97, snd_ac97_controls_alc655, ARRAY_SIZE(snd_ac97_controls_alc655))) < 0) |
| 2753 | return err; |
| 2754 | if (ac97->ext_id & AC97_EI_SPDIF) { |
| 2755 | if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0) |
| 2756 | return err; |
| 2757 | } |
| 2758 | return 0; |
| 2759 | } |
| 2760 | |
Hanno Boeck | 3e8b3b9 | 2011-01-14 19:14:47 +0100 | [diff] [blame] | 2761 | static const struct snd_ac97_build_ops patch_alc655_ops = { |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2762 | .build_specific = patch_alc655_specific, |
| 2763 | .update_jacks = alc655_update_jacks |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2764 | }; |
| 2765 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 2766 | static int patch_alc655(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2767 | { |
| 2768 | unsigned int val; |
| 2769 | |
Takashi Iwai | a5022b0 | 2005-09-02 14:03:05 +0200 | [diff] [blame] | 2770 | if (ac97->id == AC97_ID_ALC658) { |
| 2771 | ac97->spec.dev_flags = 1; /* ALC658 */ |
| 2772 | if ((snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f) == 2) { |
| 2773 | ac97->id = AC97_ID_ALC658D; |
| 2774 | ac97->spec.dev_flags = 2; |
| 2775 | } |
| 2776 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2777 | |
| 2778 | ac97->build_ops = &patch_alc655_ops; |
| 2779 | |
| 2780 | /* assume only page 0 for writing cache */ |
| 2781 | snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR); |
| 2782 | |
| 2783 | /* adjust default values */ |
| 2784 | val = snd_ac97_read(ac97, 0x7a); /* misc control */ |
Takashi Iwai | a5022b0 | 2005-09-02 14:03:05 +0200 | [diff] [blame] | 2785 | if (ac97->spec.dev_flags) /* ALC658 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2786 | val &= ~(1 << 1); /* Pin 47 is spdif input pin */ |
Takashi Iwai | ee71508e | 2005-08-31 17:31:07 +0200 | [diff] [blame] | 2787 | else { /* ALC655 */ |
| 2788 | if (ac97->subsystem_vendor == 0x1462 && |
Magnus Sandin | d244bf8 | 2006-08-16 15:25:23 +0200 | [diff] [blame] | 2789 | (ac97->subsystem_device == 0x0131 || /* MSI S270 laptop */ |
Jaroslav Kysela | e7d24f0 | 2006-10-05 09:30:36 +0200 | [diff] [blame] | 2790 | ac97->subsystem_device == 0x0161 || /* LG K1 Express */ |
Jerome Demange | cbcc2c4 | 2006-10-16 21:08:57 +0200 | [diff] [blame] | 2791 | ac97->subsystem_device == 0x0351 || /* MSI L725 laptop */ |
Takashi Iwai | 592a82e | 2007-03-12 11:33:32 +0100 | [diff] [blame] | 2792 | ac97->subsystem_device == 0x0471 || /* MSI L720 laptop */ |
Jerome Demange | cbcc2c4 | 2006-10-16 21:08:57 +0200 | [diff] [blame] | 2793 | ac97->subsystem_device == 0x0061)) /* MSI S250 laptop */ |
Takashi Iwai | ee71508e | 2005-08-31 17:31:07 +0200 | [diff] [blame] | 2794 | val &= ~(1 << 1); /* Pin 47 is EAPD (for internal speaker) */ |
| 2795 | else |
| 2796 | val |= (1 << 1); /* Pin 47 is spdif input pin */ |
Takashi Iwai | c872e8c | 2008-08-12 13:39:01 +0200 | [diff] [blame] | 2797 | /* this seems missing on some hardwares */ |
| 2798 | ac97->ext_id |= AC97_EI_SPDIF; |
Takashi Iwai | ee71508e | 2005-08-31 17:31:07 +0200 | [diff] [blame] | 2799 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2800 | val &= ~(1 << 12); /* vref enable */ |
| 2801 | snd_ac97_write_cache(ac97, 0x7a, val); |
| 2802 | /* set default: spdif-in enabled, |
| 2803 | spdif-in monitor off, spdif-in PCM off |
| 2804 | center on mic off, surround on line-in off |
| 2805 | duplicate front off |
| 2806 | */ |
| 2807 | snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15); |
| 2808 | |
| 2809 | /* full DAC volume */ |
| 2810 | snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808); |
| 2811 | snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808); |
Takashi Iwai | a5022b0 | 2005-09-02 14:03:05 +0200 | [diff] [blame] | 2812 | |
| 2813 | /* update undocumented bit... */ |
| 2814 | if (ac97->id == AC97_ID_ALC658D) |
| 2815 | snd_ac97_update_bits(ac97, 0x74, 0x0800, 0x0800); |
| 2816 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2817 | return 0; |
| 2818 | } |
| 2819 | |
| 2820 | |
| 2821 | #define AC97_ALC850_JACK_SELECT 0x76 |
| 2822 | #define AC97_ALC850_MISC1 0x7a |
Takashi Iwai | 4235a31 | 2008-02-18 12:23:13 +0100 | [diff] [blame] | 2823 | #define AC97_ALC850_MULTICH 0x6a |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2824 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2825 | static void alc850_update_jacks(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2826 | { |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2827 | int shared; |
Takashi Iwai | 4235a31 | 2008-02-18 12:23:13 +0100 | [diff] [blame] | 2828 | int aux_is_back_surround; |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2829 | |
Randy Cushman | 831466f | 2006-12-19 18:42:16 +0100 | [diff] [blame] | 2830 | /* shared Line-In / Surround Out */ |
| 2831 | shared = is_shared_surrout(ac97); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2832 | /* SURR 1kOhm (bit4), Amp (bit5) */ |
| 2833 | snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<4)|(1<<5), |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2834 | shared ? (1<<5) : (1<<4)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2835 | /* LINE-IN = 0, SURROUND = 2 */ |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2836 | snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 12, |
| 2837 | shared ? (2<<12) : (0<<12)); |
Randy Cushman | 831466f | 2006-12-19 18:42:16 +0100 | [diff] [blame] | 2838 | /* update shared Mic In / Center/LFE Out */ |
| 2839 | shared = is_shared_clfeout(ac97); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2840 | /* Vref disable (bit12), 1kOhm (bit13) */ |
| 2841 | snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<12)|(1<<13), |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2842 | shared ? (1<<12) : (1<<13)); |
Takashi Iwai | da79e44 | 2006-01-12 11:45:51 +0100 | [diff] [blame] | 2843 | /* MIC-IN = 1, CENTER-LFE = 5 */ |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2844 | snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 4, |
Takashi Iwai | da79e44 | 2006-01-12 11:45:51 +0100 | [diff] [blame] | 2845 | shared ? (5<<4) : (1<<4)); |
Takashi Iwai | 4235a31 | 2008-02-18 12:23:13 +0100 | [diff] [blame] | 2846 | |
| 2847 | aux_is_back_surround = alc850_is_aux_back_surround(ac97); |
| 2848 | /* Aux is Back Surround */ |
| 2849 | snd_ac97_update_bits(ac97, AC97_ALC850_MULTICH, 1 << 10, |
| 2850 | aux_is_back_surround ? (1<<10) : (0<<10)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2851 | } |
| 2852 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2853 | static const struct snd_kcontrol_new snd_ac97_controls_alc850[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2854 | AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0), |
Sergey Vlasov | 67e1b51 | 2005-04-25 11:34:33 +0200 | [diff] [blame] | 2855 | AC97_SINGLE("Mic Front Input Switch", AC97_ALC850_JACK_SELECT, 15, 1, 1), |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2856 | AC97_SURROUND_JACK_MODE_CTL, |
Takashi Iwai | 4235a31 | 2008-02-18 12:23:13 +0100 | [diff] [blame] | 2857 | AC97_CHANNEL_MODE_8CH_CTL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2858 | }; |
| 2859 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2860 | static int patch_alc850_specific(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2861 | { |
| 2862 | int err; |
| 2863 | |
| 2864 | if ((err = patch_build_controls(ac97, snd_ac97_controls_alc850, ARRAY_SIZE(snd_ac97_controls_alc850))) < 0) |
| 2865 | return err; |
| 2866 | if (ac97->ext_id & AC97_EI_SPDIF) { |
| 2867 | if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0) |
| 2868 | return err; |
| 2869 | } |
| 2870 | return 0; |
| 2871 | } |
| 2872 | |
Hanno Boeck | 3e8b3b9 | 2011-01-14 19:14:47 +0100 | [diff] [blame] | 2873 | static const struct snd_ac97_build_ops patch_alc850_ops = { |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2874 | .build_specific = patch_alc850_specific, |
| 2875 | .update_jacks = alc850_update_jacks |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2876 | }; |
| 2877 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 2878 | static int patch_alc850(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2879 | { |
| 2880 | ac97->build_ops = &patch_alc850_ops; |
| 2881 | |
| 2882 | ac97->spec.dev_flags = 0; /* for IEC958 playback route - ALC655 compatible */ |
Takashi Iwai | 4235a31 | 2008-02-18 12:23:13 +0100 | [diff] [blame] | 2883 | ac97->flags |= AC97_HAS_8CH; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2884 | |
| 2885 | /* assume only page 0 for writing cache */ |
| 2886 | snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR); |
| 2887 | |
| 2888 | /* adjust default values */ |
| 2889 | /* set default: spdif-in enabled, |
| 2890 | spdif-in monitor off, spdif-in PCM off |
| 2891 | center on mic off, surround on line-in off |
| 2892 | duplicate front off |
Takashi Iwai | 4235a31 | 2008-02-18 12:23:13 +0100 | [diff] [blame] | 2893 | NB default bit 10=0 = Aux is Capture, not Back Surround |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2894 | */ |
| 2895 | snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15); |
| 2896 | /* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off |
| 2897 | * Front Amp: on, Vref: enable, Center 1kOhm: on, Mix: on |
| 2898 | */ |
| 2899 | snd_ac97_write_cache(ac97, 0x7a, (1<<1)|(1<<4)|(0<<5)|(1<<6)| |
| 2900 | (1<<7)|(0<<12)|(1<<13)|(0<<14)); |
| 2901 | /* detection UIO2,3: all path floating, UIO3: MIC, Vref2: disable, |
| 2902 | * UIO1: FRONT, Vref3: disable, UIO3: LINE, Front-Mic: mute |
| 2903 | */ |
| 2904 | snd_ac97_write_cache(ac97, 0x76, (0<<0)|(0<<2)|(1<<4)|(1<<7)|(2<<8)| |
| 2905 | (1<<11)|(0<<12)|(1<<15)); |
| 2906 | |
| 2907 | /* full DAC volume */ |
| 2908 | snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808); |
| 2909 | snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808); |
| 2910 | return 0; |
| 2911 | } |
| 2912 | |
Andreas Mohr | 6ba9256 | 2011-02-19 00:49:48 +0100 | [diff] [blame] | 2913 | static int patch_aztech_azf3328_specific(struct snd_ac97 *ac97) |
| 2914 | { |
| 2915 | struct snd_kcontrol *kctl_3d_center = |
| 2916 | snd_ac97_find_mixer_ctl(ac97, "3D Control - Center"); |
| 2917 | struct snd_kcontrol *kctl_3d_depth = |
| 2918 | snd_ac97_find_mixer_ctl(ac97, "3D Control - Depth"); |
| 2919 | |
| 2920 | /* |
| 2921 | * 3D register is different from AC97 standard layout |
| 2922 | * (also do some renaming, to resemble Windows driver naming) |
| 2923 | */ |
| 2924 | if (kctl_3d_center) { |
| 2925 | kctl_3d_center->private_value = |
| 2926 | AC97_SINGLE_VALUE(AC97_3D_CONTROL, 1, 0x07, 0); |
| 2927 | snd_ac97_rename_vol_ctl(ac97, |
| 2928 | "3D Control - Center", "3D Control - Width" |
| 2929 | ); |
| 2930 | } |
| 2931 | if (kctl_3d_depth) |
| 2932 | kctl_3d_depth->private_value = |
| 2933 | AC97_SINGLE_VALUE(AC97_3D_CONTROL, 8, 0x03, 0); |
| 2934 | |
| 2935 | /* Aztech Windows driver calls the |
| 2936 | equivalent control "Modem Playback", thus rename it: */ |
| 2937 | snd_ac97_rename_vol_ctl(ac97, |
| 2938 | "Master Mono Playback", "Modem Playback" |
| 2939 | ); |
| 2940 | snd_ac97_rename_vol_ctl(ac97, |
| 2941 | "Headphone Playback", "FM Synth Playback" |
| 2942 | ); |
| 2943 | |
| 2944 | return 0; |
| 2945 | } |
| 2946 | |
| 2947 | static const struct snd_ac97_build_ops patch_aztech_azf3328_ops = { |
| 2948 | .build_specific = patch_aztech_azf3328_specific |
| 2949 | }; |
| 2950 | |
| 2951 | static int patch_aztech_azf3328(struct snd_ac97 *ac97) |
| 2952 | { |
| 2953 | ac97->build_ops = &patch_aztech_azf3328_ops; |
| 2954 | return 0; |
| 2955 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2956 | |
| 2957 | /* |
| 2958 | * C-Media CM97xx codecs |
| 2959 | */ |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2960 | static void cm9738_update_jacks(struct snd_ac97 *ac97) |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2961 | { |
Randy Cushman | 831466f | 2006-12-19 18:42:16 +0100 | [diff] [blame] | 2962 | /* shared Line-In / Surround Out */ |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2963 | snd_ac97_update_bits(ac97, AC97_CM9738_VENDOR_CTRL, 1 << 10, |
Randy Cushman | 831466f | 2006-12-19 18:42:16 +0100 | [diff] [blame] | 2964 | is_shared_surrout(ac97) ? (1 << 10) : 0); |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2965 | } |
| 2966 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2967 | static const struct snd_kcontrol_new snd_ac97_cm9738_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2968 | AC97_SINGLE("Duplicate Front", AC97_CM9738_VENDOR_CTRL, 13, 1, 0), |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2969 | AC97_SURROUND_JACK_MODE_CTL, |
| 2970 | AC97_CHANNEL_MODE_4CH_CTL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2971 | }; |
| 2972 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2973 | static int patch_cm9738_specific(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2974 | { |
| 2975 | return patch_build_controls(ac97, snd_ac97_cm9738_controls, ARRAY_SIZE(snd_ac97_cm9738_controls)); |
| 2976 | } |
| 2977 | |
Hanno Boeck | 3e8b3b9 | 2011-01-14 19:14:47 +0100 | [diff] [blame] | 2978 | static const struct snd_ac97_build_ops patch_cm9738_ops = { |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2979 | .build_specific = patch_cm9738_specific, |
| 2980 | .update_jacks = cm9738_update_jacks |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2981 | }; |
| 2982 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 2983 | static int patch_cm9738(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2984 | { |
| 2985 | ac97->build_ops = &patch_cm9738_ops; |
| 2986 | /* FIXME: can anyone confirm below? */ |
| 2987 | /* CM9738 has no PCM volume although the register reacts */ |
| 2988 | ac97->flags |= AC97_HAS_NO_PCM_VOL; |
| 2989 | snd_ac97_write_cache(ac97, AC97_PCM, 0x8000); |
| 2990 | |
| 2991 | return 0; |
| 2992 | } |
| 2993 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2994 | static int snd_ac97_cmedia_spdif_playback_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2995 | { |
Takashi Iwai | 3b7a00d | 2014-10-20 18:15:36 +0200 | [diff] [blame^] | 2996 | static const char * const texts[] = { "Analog", "Digital" }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2997 | |
Takashi Iwai | 3b7a00d | 2014-10-20 18:15:36 +0200 | [diff] [blame^] | 2998 | return snd_ctl_enum_info(uinfo, 1, 2, texts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2999 | } |
| 3000 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 3001 | static int snd_ac97_cmedia_spdif_playback_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3002 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 3003 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3004 | unsigned short val; |
| 3005 | |
| 3006 | val = ac97->regs[AC97_CM9739_SPDIF_CTRL]; |
| 3007 | ucontrol->value.enumerated.item[0] = (val >> 1) & 0x01; |
| 3008 | return 0; |
| 3009 | } |
| 3010 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 3011 | static int snd_ac97_cmedia_spdif_playback_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3012 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 3013 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3014 | |
| 3015 | return snd_ac97_update_bits(ac97, AC97_CM9739_SPDIF_CTRL, |
| 3016 | 0x01 << 1, |
| 3017 | (ucontrol->value.enumerated.item[0] & 0x01) << 1); |
| 3018 | } |
| 3019 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 3020 | static const struct snd_kcontrol_new snd_ac97_cm9739_controls_spdif[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3021 | /* BIT 0: SPDI_EN - always true */ |
| 3022 | { /* BIT 1: SPDIFS */ |
| 3023 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3024 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source", |
| 3025 | .info = snd_ac97_cmedia_spdif_playback_source_info, |
| 3026 | .get = snd_ac97_cmedia_spdif_playback_source_get, |
| 3027 | .put = snd_ac97_cmedia_spdif_playback_source_put, |
| 3028 | }, |
| 3029 | /* BIT 2: IG_SPIV */ |
| 3030 | AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9739_SPDIF_CTRL, 2, 1, 0), |
| 3031 | /* BIT 3: SPI2F */ |
| 3032 | AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9739_SPDIF_CTRL, 3, 1, 0), |
| 3033 | /* BIT 4: SPI2SDI */ |
| 3034 | AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9739_SPDIF_CTRL, 4, 1, 0), |
| 3035 | /* BIT 8: SPD32 - 32bit SPDIF - not supported yet */ |
| 3036 | }; |
| 3037 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 3038 | static void cm9739_update_jacks(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3039 | { |
Randy Cushman | 831466f | 2006-12-19 18:42:16 +0100 | [diff] [blame] | 3040 | /* shared Line-In / Surround Out */ |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 3041 | snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 1 << 10, |
Randy Cushman | 831466f | 2006-12-19 18:42:16 +0100 | [diff] [blame] | 3042 | is_shared_surrout(ac97) ? (1 << 10) : 0); |
| 3043 | /* shared Mic In / Center/LFE Out **/ |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 3044 | snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 0x3000, |
Randy Cushman | 831466f | 2006-12-19 18:42:16 +0100 | [diff] [blame] | 3045 | is_shared_clfeout(ac97) ? 0x1000 : 0x2000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3046 | } |
| 3047 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 3048 | static const struct snd_kcontrol_new snd_ac97_cm9739_controls[] = { |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 3049 | AC97_SURROUND_JACK_MODE_CTL, |
| 3050 | AC97_CHANNEL_MODE_CTL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3051 | }; |
| 3052 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 3053 | static int patch_cm9739_specific(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3054 | { |
| 3055 | return patch_build_controls(ac97, snd_ac97_cm9739_controls, ARRAY_SIZE(snd_ac97_cm9739_controls)); |
| 3056 | } |
| 3057 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 3058 | static int patch_cm9739_post_spdif(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3059 | { |
| 3060 | return patch_build_controls(ac97, snd_ac97_cm9739_controls_spdif, ARRAY_SIZE(snd_ac97_cm9739_controls_spdif)); |
| 3061 | } |
| 3062 | |
Hanno Boeck | 3e8b3b9 | 2011-01-14 19:14:47 +0100 | [diff] [blame] | 3063 | static const struct snd_ac97_build_ops patch_cm9739_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3064 | .build_specific = patch_cm9739_specific, |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 3065 | .build_post_spdif = patch_cm9739_post_spdif, |
| 3066 | .update_jacks = cm9739_update_jacks |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3067 | }; |
| 3068 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 3069 | static int patch_cm9739(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3070 | { |
| 3071 | unsigned short val; |
| 3072 | |
| 3073 | ac97->build_ops = &patch_cm9739_ops; |
| 3074 | |
| 3075 | /* CM9739/A has no Master and PCM volume although the register reacts */ |
| 3076 | ac97->flags |= AC97_HAS_NO_MASTER_VOL | AC97_HAS_NO_PCM_VOL; |
| 3077 | snd_ac97_write_cache(ac97, AC97_MASTER, 0x8000); |
| 3078 | snd_ac97_write_cache(ac97, AC97_PCM, 0x8000); |
| 3079 | |
| 3080 | /* check spdif */ |
| 3081 | val = snd_ac97_read(ac97, AC97_EXTENDED_STATUS); |
| 3082 | if (val & AC97_EA_SPCV) { |
| 3083 | /* enable spdif in */ |
| 3084 | snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL, |
| 3085 | snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) | 0x01); |
| 3086 | ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */ |
| 3087 | } else { |
| 3088 | ac97->ext_id &= ~AC97_EI_SPDIF; /* disable extended-id */ |
| 3089 | ac97->rates[AC97_RATES_SPDIF] = 0; |
| 3090 | } |
| 3091 | |
| 3092 | /* set-up multi channel */ |
| 3093 | /* bit 14: 0 = SPDIF, 1 = EAPD */ |
| 3094 | /* bit 13: enable internal vref output for mic */ |
| 3095 | /* bit 12: disable center/lfe (swithable) */ |
| 3096 | /* bit 10: disable surround/line (switchable) */ |
| 3097 | /* bit 9: mix 2 surround off */ |
| 3098 | /* bit 4: undocumented; 0 mutes the CM9739A, which defaults to 1 */ |
| 3099 | /* bit 3: undocumented; surround? */ |
| 3100 | /* bit 0: dB */ |
| 3101 | val = snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) & (1 << 4); |
| 3102 | val |= (1 << 3); |
| 3103 | val |= (1 << 13); |
| 3104 | if (! (ac97->ext_id & AC97_EI_SPDIF)) |
| 3105 | val |= (1 << 14); |
| 3106 | snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, val); |
| 3107 | |
| 3108 | /* FIXME: set up GPIO */ |
| 3109 | snd_ac97_write_cache(ac97, 0x70, 0x0100); |
| 3110 | snd_ac97_write_cache(ac97, 0x72, 0x0020); |
| 3111 | /* Special exception for ASUS W1000/CMI9739. It does not have an SPDIF in. */ |
| 3112 | if (ac97->pci && |
| 3113 | ac97->subsystem_vendor == 0x1043 && |
| 3114 | ac97->subsystem_device == 0x1843) { |
| 3115 | snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL, |
| 3116 | snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) & ~0x01); |
| 3117 | snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, |
| 3118 | snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) | (1 << 14)); |
| 3119 | } |
| 3120 | |
| 3121 | return 0; |
| 3122 | } |
| 3123 | |
| 3124 | #define AC97_CM9761_MULTI_CHAN 0x64 |
Takashi Iwai | 5f0dccf | 2005-04-07 15:53:20 +0200 | [diff] [blame] | 3125 | #define AC97_CM9761_FUNC 0x66 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3126 | #define AC97_CM9761_SPDIF_CTRL 0x6c |
| 3127 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 3128 | static void cm9761_update_jacks(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3129 | { |
Takashi Iwai | 4525c9f | 2005-09-13 11:47:07 +0200 | [diff] [blame] | 3130 | /* FIXME: check the bits for each model |
| 3131 | * model 83 is confirmed to work |
| 3132 | */ |
| 3133 | static unsigned short surr_on[3][2] = { |
| 3134 | { 0x0008, 0x0000 }, /* 9761-78 & 82 */ |
| 3135 | { 0x0000, 0x0008 }, /* 9761-82 rev.B */ |
| 3136 | { 0x0000, 0x0008 }, /* 9761-83 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3137 | }; |
Takashi Iwai | 4525c9f | 2005-09-13 11:47:07 +0200 | [diff] [blame] | 3138 | static unsigned short clfe_on[3][2] = { |
| 3139 | { 0x0000, 0x1000 }, /* 9761-78 & 82 */ |
| 3140 | { 0x1000, 0x0000 }, /* 9761-82 rev.B */ |
| 3141 | { 0x0000, 0x1000 }, /* 9761-83 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3142 | }; |
Takashi Iwai | 4525c9f | 2005-09-13 11:47:07 +0200 | [diff] [blame] | 3143 | static unsigned short surr_shared[3][2] = { |
| 3144 | { 0x0000, 0x0400 }, /* 9761-78 & 82 */ |
| 3145 | { 0x0000, 0x0400 }, /* 9761-82 rev.B */ |
| 3146 | { 0x0000, 0x0400 }, /* 9761-83 */ |
| 3147 | }; |
| 3148 | static unsigned short clfe_shared[3][2] = { |
| 3149 | { 0x2000, 0x0880 }, /* 9761-78 & 82 */ |
| 3150 | { 0x0000, 0x2880 }, /* 9761-82 rev.B */ |
| 3151 | { 0x2000, 0x0800 }, /* 9761-83 */ |
| 3152 | }; |
| 3153 | unsigned short val = 0; |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 3154 | |
Takashi Iwai | 4525c9f | 2005-09-13 11:47:07 +0200 | [diff] [blame] | 3155 | val |= surr_on[ac97->spec.dev_flags][is_surround_on(ac97)]; |
| 3156 | val |= clfe_on[ac97->spec.dev_flags][is_clfe_on(ac97)]; |
Randy Cushman | 831466f | 2006-12-19 18:42:16 +0100 | [diff] [blame] | 3157 | val |= surr_shared[ac97->spec.dev_flags][is_shared_surrout(ac97)]; |
| 3158 | val |= clfe_shared[ac97->spec.dev_flags][is_shared_clfeout(ac97)]; |
Takashi Iwai | 4525c9f | 2005-09-13 11:47:07 +0200 | [diff] [blame] | 3159 | |
| 3160 | snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x3c88, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3161 | } |
| 3162 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 3163 | static const struct snd_kcontrol_new snd_ac97_cm9761_controls[] = { |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 3164 | AC97_SURROUND_JACK_MODE_CTL, |
| 3165 | AC97_CHANNEL_MODE_CTL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3166 | }; |
| 3167 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 3168 | static int cm9761_spdif_out_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Takashi Iwai | 5f0dccf | 2005-04-07 15:53:20 +0200 | [diff] [blame] | 3169 | { |
Takashi Iwai | 3b7a00d | 2014-10-20 18:15:36 +0200 | [diff] [blame^] | 3170 | static const char * const texts[] = { "AC-Link", "ADC", "SPDIF-In" }; |
Takashi Iwai | 5f0dccf | 2005-04-07 15:53:20 +0200 | [diff] [blame] | 3171 | |
Takashi Iwai | 3b7a00d | 2014-10-20 18:15:36 +0200 | [diff] [blame^] | 3172 | return snd_ctl_enum_info(uinfo, 1, 3, texts); |
Takashi Iwai | 5f0dccf | 2005-04-07 15:53:20 +0200 | [diff] [blame] | 3173 | } |
| 3174 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 3175 | static int cm9761_spdif_out_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 5f0dccf | 2005-04-07 15:53:20 +0200 | [diff] [blame] | 3176 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 3177 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 5f0dccf | 2005-04-07 15:53:20 +0200 | [diff] [blame] | 3178 | |
| 3179 | if (ac97->regs[AC97_CM9761_FUNC] & 0x1) |
| 3180 | ucontrol->value.enumerated.item[0] = 2; /* SPDIF-loopback */ |
| 3181 | else if (ac97->regs[AC97_CM9761_SPDIF_CTRL] & 0x2) |
| 3182 | ucontrol->value.enumerated.item[0] = 1; /* ADC loopback */ |
| 3183 | else |
| 3184 | ucontrol->value.enumerated.item[0] = 0; /* AC-link */ |
| 3185 | return 0; |
| 3186 | } |
| 3187 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 3188 | static int cm9761_spdif_out_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 5f0dccf | 2005-04-07 15:53:20 +0200 | [diff] [blame] | 3189 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 3190 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 5f0dccf | 2005-04-07 15:53:20 +0200 | [diff] [blame] | 3191 | |
| 3192 | if (ucontrol->value.enumerated.item[0] == 2) |
| 3193 | return snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0x1); |
| 3194 | snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0); |
| 3195 | return snd_ac97_update_bits(ac97, AC97_CM9761_SPDIF_CTRL, 0x2, |
| 3196 | ucontrol->value.enumerated.item[0] == 1 ? 0x2 : 0); |
| 3197 | } |
| 3198 | |
| 3199 | static const char *cm9761_dac_clock[] = { "AC-Link", "SPDIF-In", "Both" }; |
| 3200 | static const struct ac97_enum cm9761_dac_clock_enum = |
| 3201 | AC97_ENUM_SINGLE(AC97_CM9761_SPDIF_CTRL, 9, 3, cm9761_dac_clock); |
| 3202 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 3203 | static const struct snd_kcontrol_new snd_ac97_cm9761_controls_spdif[] = { |
Takashi Iwai | 5f0dccf | 2005-04-07 15:53:20 +0200 | [diff] [blame] | 3204 | { /* BIT 1: SPDIFS */ |
| 3205 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3206 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source", |
| 3207 | .info = cm9761_spdif_out_source_info, |
| 3208 | .get = cm9761_spdif_out_source_get, |
| 3209 | .put = cm9761_spdif_out_source_put, |
| 3210 | }, |
| 3211 | /* BIT 2: IG_SPIV */ |
| 3212 | AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9761_SPDIF_CTRL, 2, 1, 0), |
| 3213 | /* BIT 3: SPI2F */ |
| 3214 | AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9761_SPDIF_CTRL, 3, 1, 0), |
| 3215 | /* BIT 4: SPI2SDI */ |
| 3216 | AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9761_SPDIF_CTRL, 4, 1, 0), |
| 3217 | /* BIT 9-10: DAC_CTL */ |
| 3218 | AC97_ENUM("DAC Clock Source", cm9761_dac_clock_enum), |
| 3219 | }; |
| 3220 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 3221 | static int patch_cm9761_post_spdif(struct snd_ac97 * ac97) |
Takashi Iwai | 5f0dccf | 2005-04-07 15:53:20 +0200 | [diff] [blame] | 3222 | { |
| 3223 | return patch_build_controls(ac97, snd_ac97_cm9761_controls_spdif, ARRAY_SIZE(snd_ac97_cm9761_controls_spdif)); |
| 3224 | } |
| 3225 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 3226 | static int patch_cm9761_specific(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3227 | { |
| 3228 | return patch_build_controls(ac97, snd_ac97_cm9761_controls, ARRAY_SIZE(snd_ac97_cm9761_controls)); |
| 3229 | } |
| 3230 | |
Hanno Boeck | 3e8b3b9 | 2011-01-14 19:14:47 +0100 | [diff] [blame] | 3231 | static const struct snd_ac97_build_ops patch_cm9761_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3232 | .build_specific = patch_cm9761_specific, |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 3233 | .build_post_spdif = patch_cm9761_post_spdif, |
| 3234 | .update_jacks = cm9761_update_jacks |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3235 | }; |
| 3236 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 3237 | static int patch_cm9761(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3238 | { |
| 3239 | unsigned short val; |
| 3240 | |
| 3241 | /* CM9761 has no PCM volume although the register reacts */ |
| 3242 | /* Master volume seems to have _some_ influence on the analog |
| 3243 | * input sounds |
| 3244 | */ |
| 3245 | ac97->flags |= /*AC97_HAS_NO_MASTER_VOL |*/ AC97_HAS_NO_PCM_VOL; |
| 3246 | snd_ac97_write_cache(ac97, AC97_MASTER, 0x8808); |
| 3247 | snd_ac97_write_cache(ac97, AC97_PCM, 0x8808); |
| 3248 | |
Takashi Iwai | 4525c9f | 2005-09-13 11:47:07 +0200 | [diff] [blame] | 3249 | ac97->spec.dev_flags = 0; /* 1 = model 82 revision B, 2 = model 83 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3250 | if (ac97->id == AC97_ID_CM9761_82) { |
| 3251 | unsigned short tmp; |
| 3252 | /* check page 1, reg 0x60 */ |
| 3253 | val = snd_ac97_read(ac97, AC97_INT_PAGING); |
| 3254 | snd_ac97_write_cache(ac97, AC97_INT_PAGING, (val & ~0x0f) | 0x01); |
| 3255 | tmp = snd_ac97_read(ac97, 0x60); |
| 3256 | ac97->spec.dev_flags = tmp & 1; /* revision B? */ |
| 3257 | snd_ac97_write_cache(ac97, AC97_INT_PAGING, val); |
Takashi Iwai | 4525c9f | 2005-09-13 11:47:07 +0200 | [diff] [blame] | 3258 | } else if (ac97->id == AC97_ID_CM9761_83) |
| 3259 | ac97->spec.dev_flags = 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3260 | |
| 3261 | ac97->build_ops = &patch_cm9761_ops; |
| 3262 | |
| 3263 | /* enable spdif */ |
| 3264 | /* force the SPDIF bit in ext_id - codec doesn't set this bit! */ |
| 3265 | ac97->ext_id |= AC97_EI_SPDIF; |
| 3266 | /* to be sure: we overwrite the ext status bits */ |
| 3267 | snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, 0x05c0); |
| 3268 | /* Don't set 0x0200 here. This results in the silent analog output */ |
Takashi Iwai | 5f0dccf | 2005-04-07 15:53:20 +0200 | [diff] [blame] | 3269 | snd_ac97_write_cache(ac97, AC97_CM9761_SPDIF_CTRL, 0x0001); /* enable spdif-in */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3270 | ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */ |
| 3271 | |
| 3272 | /* set-up multi channel */ |
| 3273 | /* bit 15: pc master beep off |
Takashi Iwai | 5f0dccf | 2005-04-07 15:53:20 +0200 | [diff] [blame] | 3274 | * bit 14: pin47 = EAPD/SPDIF |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3275 | * bit 13: vref ctl [= cm9739] |
Takashi Iwai | 5f0dccf | 2005-04-07 15:53:20 +0200 | [diff] [blame] | 3276 | * bit 12: CLFE control (reverted on rev B) |
| 3277 | * bit 11: Mic/center share (reverted on rev B) |
| 3278 | * bit 10: suddound/line share |
| 3279 | * bit 9: Analog-in mix -> surround |
| 3280 | * bit 8: Analog-in mix -> CLFE |
| 3281 | * bit 7: Mic/LFE share (mic/center/lfe) |
| 3282 | * bit 5: vref select (9761A) |
| 3283 | * bit 4: front control |
| 3284 | * bit 3: surround control (revereted with rev B) |
| 3285 | * bit 2: front mic |
| 3286 | * bit 1: stereo mic |
| 3287 | * bit 0: mic boost level (0=20dB, 1=30dB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3288 | */ |
| 3289 | |
| 3290 | #if 0 |
| 3291 | if (ac97->spec.dev_flags) |
| 3292 | val = 0x0214; |
| 3293 | else |
| 3294 | val = 0x321c; |
| 3295 | #endif |
| 3296 | val = snd_ac97_read(ac97, AC97_CM9761_MULTI_CHAN); |
| 3297 | val |= (1 << 4); /* front on */ |
| 3298 | snd_ac97_write_cache(ac97, AC97_CM9761_MULTI_CHAN, val); |
| 3299 | |
| 3300 | /* FIXME: set up GPIO */ |
| 3301 | snd_ac97_write_cache(ac97, 0x70, 0x0100); |
| 3302 | snd_ac97_write_cache(ac97, 0x72, 0x0020); |
| 3303 | |
| 3304 | return 0; |
| 3305 | } |
| 3306 | |
Takashi Iwai | 5f0dccf | 2005-04-07 15:53:20 +0200 | [diff] [blame] | 3307 | #define AC97_CM9780_SIDE 0x60 |
| 3308 | #define AC97_CM9780_JACK 0x62 |
| 3309 | #define AC97_CM9780_MIXER 0x64 |
| 3310 | #define AC97_CM9780_MULTI_CHAN 0x66 |
| 3311 | #define AC97_CM9780_SPDIF 0x6c |
| 3312 | |
| 3313 | static const char *cm9780_ch_select[] = { "Front", "Side", "Center/LFE", "Rear" }; |
| 3314 | static const struct ac97_enum cm9780_ch_select_enum = |
| 3315 | AC97_ENUM_SINGLE(AC97_CM9780_MULTI_CHAN, 6, 4, cm9780_ch_select); |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 3316 | static const struct snd_kcontrol_new cm9780_controls[] = { |
Takashi Iwai | 5f0dccf | 2005-04-07 15:53:20 +0200 | [diff] [blame] | 3317 | AC97_DOUBLE("Side Playback Switch", AC97_CM9780_SIDE, 15, 7, 1, 1), |
| 3318 | AC97_DOUBLE("Side Playback Volume", AC97_CM9780_SIDE, 8, 0, 31, 0), |
| 3319 | AC97_ENUM("Side Playback Route", cm9780_ch_select_enum), |
| 3320 | }; |
| 3321 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 3322 | static int patch_cm9780_specific(struct snd_ac97 *ac97) |
Takashi Iwai | 5f0dccf | 2005-04-07 15:53:20 +0200 | [diff] [blame] | 3323 | { |
| 3324 | return patch_build_controls(ac97, cm9780_controls, ARRAY_SIZE(cm9780_controls)); |
| 3325 | } |
| 3326 | |
Hanno Boeck | 3e8b3b9 | 2011-01-14 19:14:47 +0100 | [diff] [blame] | 3327 | static const struct snd_ac97_build_ops patch_cm9780_ops = { |
Takashi Iwai | 5f0dccf | 2005-04-07 15:53:20 +0200 | [diff] [blame] | 3328 | .build_specific = patch_cm9780_specific, |
| 3329 | .build_post_spdif = patch_cm9761_post_spdif /* identical with CM9761 */ |
| 3330 | }; |
| 3331 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 3332 | static int patch_cm9780(struct snd_ac97 *ac97) |
Takashi Iwai | 5f0dccf | 2005-04-07 15:53:20 +0200 | [diff] [blame] | 3333 | { |
| 3334 | unsigned short val; |
| 3335 | |
| 3336 | ac97->build_ops = &patch_cm9780_ops; |
| 3337 | |
| 3338 | /* enable spdif */ |
| 3339 | if (ac97->ext_id & AC97_EI_SPDIF) { |
| 3340 | ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */ |
| 3341 | val = snd_ac97_read(ac97, AC97_CM9780_SPDIF); |
| 3342 | val |= 0x1; /* SPDI_EN */ |
| 3343 | snd_ac97_write_cache(ac97, AC97_CM9780_SPDIF, val); |
| 3344 | } |
| 3345 | |
| 3346 | return 0; |
| 3347 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3348 | |
| 3349 | /* |
| 3350 | * VIA VT1616 codec |
| 3351 | */ |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 3352 | static const struct snd_kcontrol_new snd_ac97_controls_vt1616[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3353 | AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0), |
| 3354 | AC97_SINGLE("Alternate Level to Surround Out", 0x5a, 15, 1, 0), |
| 3355 | AC97_SINGLE("Downmix LFE and Center to Front", 0x5a, 12, 1, 0), |
| 3356 | AC97_SINGLE("Downmix Surround to Front", 0x5a, 11, 1, 0), |
| 3357 | }; |
| 3358 | |
Daniel Jacobowitz | 87af38d | 2008-05-07 12:05:10 +0200 | [diff] [blame] | 3359 | static const char *slave_vols_vt1616[] = { |
| 3360 | "Front Playback Volume", |
| 3361 | "Surround Playback Volume", |
| 3362 | "Center Playback Volume", |
| 3363 | "LFE Playback Volume", |
| 3364 | NULL |
| 3365 | }; |
| 3366 | |
| 3367 | static const char *slave_sws_vt1616[] = { |
| 3368 | "Front Playback Switch", |
| 3369 | "Surround Playback Switch", |
| 3370 | "Center Playback Switch", |
| 3371 | "LFE Playback Switch", |
| 3372 | NULL |
| 3373 | }; |
| 3374 | |
| 3375 | /* find a mixer control element with the given name */ |
| 3376 | static struct snd_kcontrol *snd_ac97_find_mixer_ctl(struct snd_ac97 *ac97, |
| 3377 | const char *name) |
| 3378 | { |
| 3379 | struct snd_ctl_elem_id id; |
| 3380 | memset(&id, 0, sizeof(id)); |
| 3381 | id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 3382 | strcpy(id.name, name); |
| 3383 | return snd_ctl_find_id(ac97->bus->card, &id); |
| 3384 | } |
| 3385 | |
| 3386 | /* create a virtual master control and add slaves */ |
Adrian Bunk | 13c2108 | 2008-07-22 20:21:32 +0300 | [diff] [blame] | 3387 | static int snd_ac97_add_vmaster(struct snd_ac97 *ac97, char *name, |
| 3388 | const unsigned int *tlv, const char **slaves) |
Daniel Jacobowitz | 87af38d | 2008-05-07 12:05:10 +0200 | [diff] [blame] | 3389 | { |
| 3390 | struct snd_kcontrol *kctl; |
| 3391 | const char **s; |
| 3392 | int err; |
| 3393 | |
| 3394 | kctl = snd_ctl_make_virtual_master(name, tlv); |
| 3395 | if (!kctl) |
| 3396 | return -ENOMEM; |
| 3397 | err = snd_ctl_add(ac97->bus->card, kctl); |
| 3398 | if (err < 0) |
| 3399 | return err; |
| 3400 | |
| 3401 | for (s = slaves; *s; s++) { |
| 3402 | struct snd_kcontrol *sctl; |
| 3403 | |
| 3404 | sctl = snd_ac97_find_mixer_ctl(ac97, *s); |
| 3405 | if (!sctl) { |
Takashi Iwai | 38c16e3 | 2014-02-25 15:37:50 +0100 | [diff] [blame] | 3406 | dev_dbg(ac97->bus->card->dev, |
| 3407 | "Cannot find slave %s, skipped\n", *s); |
Daniel Jacobowitz | 87af38d | 2008-05-07 12:05:10 +0200 | [diff] [blame] | 3408 | continue; |
| 3409 | } |
| 3410 | err = snd_ctl_add_slave(kctl, sctl); |
| 3411 | if (err < 0) |
| 3412 | return err; |
| 3413 | } |
| 3414 | return 0; |
| 3415 | } |
| 3416 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 3417 | static int patch_vt1616_specific(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3418 | { |
Daniel Jacobowitz | 87af38d | 2008-05-07 12:05:10 +0200 | [diff] [blame] | 3419 | struct snd_kcontrol *kctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3420 | int err; |
| 3421 | |
| 3422 | if (snd_ac97_try_bit(ac97, 0x5a, 9)) |
| 3423 | if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[0], 1)) < 0) |
| 3424 | return err; |
| 3425 | if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[1], ARRAY_SIZE(snd_ac97_controls_vt1616) - 1)) < 0) |
| 3426 | return err; |
Daniel Jacobowitz | 87af38d | 2008-05-07 12:05:10 +0200 | [diff] [blame] | 3427 | |
| 3428 | /* There is already a misnamed master switch. Rename it. */ |
| 3429 | kctl = snd_ac97_find_mixer_ctl(ac97, "Master Playback Volume"); |
| 3430 | if (!kctl) |
| 3431 | return -EINVAL; |
| 3432 | |
| 3433 | snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Front Playback"); |
| 3434 | |
| 3435 | err = snd_ac97_add_vmaster(ac97, "Master Playback Volume", |
| 3436 | kctl->tlv.p, slave_vols_vt1616); |
| 3437 | if (err < 0) |
| 3438 | return err; |
| 3439 | |
| 3440 | err = snd_ac97_add_vmaster(ac97, "Master Playback Switch", |
| 3441 | NULL, slave_sws_vt1616); |
| 3442 | if (err < 0) |
| 3443 | return err; |
| 3444 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3445 | return 0; |
| 3446 | } |
| 3447 | |
Hanno Boeck | 3e8b3b9 | 2011-01-14 19:14:47 +0100 | [diff] [blame] | 3448 | static const struct snd_ac97_build_ops patch_vt1616_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3449 | .build_specific = patch_vt1616_specific |
| 3450 | }; |
| 3451 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 3452 | static int patch_vt1616(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3453 | { |
| 3454 | ac97->build_ops = &patch_vt1616_ops; |
| 3455 | return 0; |
| 3456 | } |
| 3457 | |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 3458 | /* |
Philip Prindeville | 4b49948 | 2005-08-12 16:46:17 +0200 | [diff] [blame] | 3459 | * VT1617A codec |
| 3460 | */ |
John Utz | e9024cc | 2007-03-12 12:30:06 +0100 | [diff] [blame] | 3461 | |
| 3462 | /* |
| 3463 | * unfortunately, the vt1617a stashes the twiddlers required for |
John L. Utz III | 9e285e1 | 2008-08-28 16:04:40 +0200 | [diff] [blame] | 3464 | * noodling the i/o jacks on 2 different regs. that means that we can't |
John Utz | e9024cc | 2007-03-12 12:30:06 +0100 | [diff] [blame] | 3465 | * use the easy way provided by AC97_ENUM_DOUBLE() we have to write |
| 3466 | * are own funcs. |
| 3467 | * |
| 3468 | * NB: this is absolutely and utterly different from the vt1618. dunno |
| 3469 | * about the 1616. |
| 3470 | */ |
| 3471 | |
| 3472 | /* copied from ac97_surround_jack_mode_info() */ |
| 3473 | static int snd_ac97_vt1617a_smart51_info(struct snd_kcontrol *kcontrol, |
| 3474 | struct snd_ctl_elem_info *uinfo) |
Philip Prindeville | 4b49948 | 2005-08-12 16:46:17 +0200 | [diff] [blame] | 3475 | { |
John Utz | e9024cc | 2007-03-12 12:30:06 +0100 | [diff] [blame] | 3476 | /* ordering in this list reflects vt1617a docs for Reg 20 and |
| 3477 | * 7a and Table 6 that lays out the matrix NB WRT Table6: SM51 |
| 3478 | * is SM51EN *AND* it's Bit14, not Bit15 so the table is very |
| 3479 | * counter-intuitive */ |
| 3480 | |
Takashi Iwai | 3b7a00d | 2014-10-20 18:15:36 +0200 | [diff] [blame^] | 3481 | static const char * const texts[] = {"LineIn Mic1", "LineIn Mic1 Mic3", |
John Utz | e9024cc | 2007-03-12 12:30:06 +0100 | [diff] [blame] | 3482 | "Surr LFE/C Mic3", "LineIn LFE/C Mic3", |
| 3483 | "LineIn Mic2", "LineIn Mic2 Mic1", |
| 3484 | "Surr LFE Mic1", "Surr LFE Mic1 Mic2"}; |
Takashi Iwai | 3b7a00d | 2014-10-20 18:15:36 +0200 | [diff] [blame^] | 3485 | |
| 3486 | return snd_ctl_enum_info(uinfo, 1, 8, texts); |
John Utz | e9024cc | 2007-03-12 12:30:06 +0100 | [diff] [blame] | 3487 | } |
| 3488 | |
| 3489 | static int snd_ac97_vt1617a_smart51_get(struct snd_kcontrol *kcontrol, |
| 3490 | struct snd_ctl_elem_value *ucontrol) |
| 3491 | { |
| 3492 | ushort usSM51, usMS; |
| 3493 | |
| 3494 | struct snd_ac97 *pac97; |
| 3495 | |
| 3496 | pac97 = snd_kcontrol_chip(kcontrol); /* grab codec handle */ |
| 3497 | |
John L. Utz III | 9e285e1 | 2008-08-28 16:04:40 +0200 | [diff] [blame] | 3498 | /* grab our desired bits, then mash them together in a manner |
John Utz | e9024cc | 2007-03-12 12:30:06 +0100 | [diff] [blame] | 3499 | * consistent with Table 6 on page 17 in the 1617a docs */ |
| 3500 | |
| 3501 | usSM51 = snd_ac97_read(pac97, 0x7a) >> 14; |
| 3502 | usMS = snd_ac97_read(pac97, 0x20) >> 8; |
| 3503 | |
| 3504 | ucontrol->value.enumerated.item[0] = (usSM51 << 1) + usMS; |
| 3505 | |
| 3506 | return 0; |
| 3507 | } |
| 3508 | |
| 3509 | static int snd_ac97_vt1617a_smart51_put(struct snd_kcontrol *kcontrol, |
| 3510 | struct snd_ctl_elem_value *ucontrol) |
| 3511 | { |
| 3512 | ushort usSM51, usMS, usReg; |
| 3513 | |
| 3514 | struct snd_ac97 *pac97; |
| 3515 | |
| 3516 | pac97 = snd_kcontrol_chip(kcontrol); /* grab codec handle */ |
| 3517 | |
| 3518 | usSM51 = ucontrol->value.enumerated.item[0] >> 1; |
| 3519 | usMS = ucontrol->value.enumerated.item[0] & 1; |
| 3520 | |
| 3521 | /* push our values into the register - consider that things will be left |
| 3522 | * in a funky state if the write fails */ |
| 3523 | |
| 3524 | usReg = snd_ac97_read(pac97, 0x7a); |
| 3525 | snd_ac97_write_cache(pac97, 0x7a, (usReg & 0x3FFF) + (usSM51 << 14)); |
| 3526 | usReg = snd_ac97_read(pac97, 0x20); |
| 3527 | snd_ac97_write_cache(pac97, 0x20, (usReg & 0xFEFF) + (usMS << 8)); |
| 3528 | |
| 3529 | return 0; |
| 3530 | } |
| 3531 | |
| 3532 | static const struct snd_kcontrol_new snd_ac97_controls_vt1617a[] = { |
| 3533 | |
| 3534 | AC97_SINGLE("Center/LFE Exchange", 0x5a, 8, 1, 0), |
| 3535 | /* |
| 3536 | * These are used to enable/disable surround sound on motherboards |
| 3537 | * that have 3 bidirectional analog jacks |
| 3538 | */ |
| 3539 | { |
| 3540 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3541 | .name = "Smart 5.1 Select", |
| 3542 | .info = snd_ac97_vt1617a_smart51_info, |
| 3543 | .get = snd_ac97_vt1617a_smart51_get, |
| 3544 | .put = snd_ac97_vt1617a_smart51_put, |
| 3545 | }, |
| 3546 | }; |
| 3547 | |
Harvey Harrison | b03671a | 2008-08-29 13:32:00 -0700 | [diff] [blame] | 3548 | static int patch_vt1617a(struct snd_ac97 * ac97) |
John Utz | e9024cc | 2007-03-12 12:30:06 +0100 | [diff] [blame] | 3549 | { |
| 3550 | int err = 0; |
Takashi Iwai | 2e75d05 | 2008-05-03 18:46:56 +0200 | [diff] [blame] | 3551 | int val; |
John Utz | e9024cc | 2007-03-12 12:30:06 +0100 | [diff] [blame] | 3552 | |
| 3553 | /* we choose to not fail out at this point, but we tell the |
| 3554 | caller when we return */ |
| 3555 | |
| 3556 | err = patch_build_controls(ac97, &snd_ac97_controls_vt1617a[0], |
| 3557 | ARRAY_SIZE(snd_ac97_controls_vt1617a)); |
| 3558 | |
| 3559 | /* bring analog power consumption to normal by turning off the |
| 3560 | * headphone amplifier, like WinXP driver for EPIA SP |
Andrey Liakhovets | 9f458e7 | 2006-08-28 16:52:41 +0200 | [diff] [blame] | 3561 | */ |
Takashi Iwai | 2e75d05 | 2008-05-03 18:46:56 +0200 | [diff] [blame] | 3562 | /* We need to check the bit before writing it. |
| 3563 | * On some (many?) hardwares, setting bit actually clears it! |
| 3564 | */ |
| 3565 | val = snd_ac97_read(ac97, 0x5c); |
| 3566 | if (!(val & 0x20)) |
| 3567 | snd_ac97_write_cache(ac97, 0x5c, 0x20); |
| 3568 | |
Philip Prindeville | 4b49948 | 2005-08-12 16:46:17 +0200 | [diff] [blame] | 3569 | ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */ |
| 3570 | ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000; |
Daniel Jacobowitz | 9f42817 | 2007-01-12 19:11:47 +0100 | [diff] [blame] | 3571 | ac97->build_ops = &patch_vt1616_ops; |
John Utz | e9024cc | 2007-03-12 12:30:06 +0100 | [diff] [blame] | 3572 | |
| 3573 | return err; |
Philip Prindeville | 4b49948 | 2005-08-12 16:46:17 +0200 | [diff] [blame] | 3574 | } |
| 3575 | |
John L. Utz III | 9e285e1 | 2008-08-28 16:04:40 +0200 | [diff] [blame] | 3576 | /* VIA VT1618 8 CHANNEL AC97 CODEC |
| 3577 | * |
| 3578 | * VIA implements 'Smart 5.1' completely differently on the 1618 than |
| 3579 | * it does on the 1617a. awesome! They seem to have sourced this |
| 3580 | * particular revision of the technology from somebody else, it's |
| 3581 | * called Universal Audio Jack and it shows up on some other folk's chips |
| 3582 | * as well. |
| 3583 | * |
| 3584 | * ordering in this list reflects vt1618 docs for Reg 60h and |
| 3585 | * the block diagram, DACs are as follows: |
| 3586 | * |
| 3587 | * OUT_O -> Front, |
| 3588 | * OUT_1 -> Surround, |
| 3589 | * OUT_2 -> C/LFE |
| 3590 | * |
| 3591 | * Unlike the 1617a, each OUT has a consistent set of mappings |
| 3592 | * for all bitpatterns other than 00: |
| 3593 | * |
| 3594 | * 01 Unmixed Output |
| 3595 | * 10 Line In |
| 3596 | * 11 Mic In |
| 3597 | * |
| 3598 | * Special Case of 00: |
| 3599 | * |
| 3600 | * OUT_0 Mixed Output |
| 3601 | * OUT_1 Reserved |
| 3602 | * OUT_2 Reserved |
| 3603 | * |
| 3604 | * I have no idea what the hell Reserved does, but on an MSI |
| 3605 | * CN700T, i have to set it to get 5.1 output - YMMV, bad |
| 3606 | * shit may happen. |
| 3607 | * |
| 3608 | * If other chips use Universal Audio Jack, then this code might be applicable |
| 3609 | * to them. |
| 3610 | */ |
| 3611 | |
| 3612 | struct vt1618_uaj_item { |
| 3613 | unsigned short mask; |
| 3614 | unsigned short shift; |
| 3615 | const char *items[4]; |
| 3616 | }; |
| 3617 | |
| 3618 | /* This list reflects the vt1618 docs for Vendor Defined Register 0x60. */ |
| 3619 | |
| 3620 | static struct vt1618_uaj_item vt1618_uaj[3] = { |
| 3621 | { |
| 3622 | /* speaker jack */ |
| 3623 | .mask = 0x03, |
| 3624 | .shift = 0, |
| 3625 | .items = { |
| 3626 | "Speaker Out", "DAC Unmixed Out", "Line In", "Mic In" |
| 3627 | } |
| 3628 | }, |
| 3629 | { |
| 3630 | /* line jack */ |
| 3631 | .mask = 0x0c, |
| 3632 | .shift = 2, |
| 3633 | .items = { |
| 3634 | "Surround Out", "DAC Unmixed Out", "Line In", "Mic In" |
| 3635 | } |
| 3636 | }, |
| 3637 | { |
| 3638 | /* mic jack */ |
| 3639 | .mask = 0x30, |
| 3640 | .shift = 4, |
| 3641 | .items = { |
| 3642 | "Center LFE Out", "DAC Unmixed Out", "Line In", "Mic In" |
| 3643 | }, |
| 3644 | }, |
| 3645 | }; |
| 3646 | |
| 3647 | static int snd_ac97_vt1618_UAJ_info(struct snd_kcontrol *kcontrol, |
| 3648 | struct snd_ctl_elem_info *uinfo) |
| 3649 | { |
Takashi Iwai | 3b7a00d | 2014-10-20 18:15:36 +0200 | [diff] [blame^] | 3650 | return snd_ctl_enum_info(uinfo, 1, 4, |
| 3651 | vt1618_uaj[kcontrol->private_value].items); |
John L. Utz III | 9e285e1 | 2008-08-28 16:04:40 +0200 | [diff] [blame] | 3652 | } |
| 3653 | |
| 3654 | /* All of the vt1618 Universal Audio Jack twiddlers are on |
| 3655 | * Vendor Defined Register 0x60, page 0. The bits, and thus |
| 3656 | * the mask, are the only thing that changes |
| 3657 | */ |
| 3658 | static int snd_ac97_vt1618_UAJ_get(struct snd_kcontrol *kcontrol, |
| 3659 | struct snd_ctl_elem_value *ucontrol) |
| 3660 | { |
| 3661 | unsigned short datpag, uaj; |
| 3662 | struct snd_ac97 *pac97 = snd_kcontrol_chip(kcontrol); |
| 3663 | |
| 3664 | mutex_lock(&pac97->page_mutex); |
| 3665 | |
| 3666 | datpag = snd_ac97_read(pac97, AC97_INT_PAGING) & AC97_PAGE_MASK; |
| 3667 | snd_ac97_update_bits(pac97, AC97_INT_PAGING, AC97_PAGE_MASK, 0); |
| 3668 | |
| 3669 | uaj = snd_ac97_read(pac97, 0x60) & |
| 3670 | vt1618_uaj[kcontrol->private_value].mask; |
| 3671 | |
| 3672 | snd_ac97_update_bits(pac97, AC97_INT_PAGING, AC97_PAGE_MASK, datpag); |
| 3673 | mutex_unlock(&pac97->page_mutex); |
| 3674 | |
| 3675 | ucontrol->value.enumerated.item[0] = uaj >> |
| 3676 | vt1618_uaj[kcontrol->private_value].shift; |
| 3677 | |
| 3678 | return 0; |
| 3679 | } |
| 3680 | |
| 3681 | static int snd_ac97_vt1618_UAJ_put(struct snd_kcontrol *kcontrol, |
| 3682 | struct snd_ctl_elem_value *ucontrol) |
| 3683 | { |
| 3684 | return ac97_update_bits_page(snd_kcontrol_chip(kcontrol), 0x60, |
| 3685 | vt1618_uaj[kcontrol->private_value].mask, |
| 3686 | ucontrol->value.enumerated.item[0]<< |
| 3687 | vt1618_uaj[kcontrol->private_value].shift, |
| 3688 | 0); |
| 3689 | } |
| 3690 | |
| 3691 | /* config aux in jack - not found on 3 jack motherboards or soundcards */ |
| 3692 | |
| 3693 | static int snd_ac97_vt1618_aux_info(struct snd_kcontrol *kcontrol, |
| 3694 | struct snd_ctl_elem_info *uinfo) |
| 3695 | { |
Takashi Iwai | 3b7a00d | 2014-10-20 18:15:36 +0200 | [diff] [blame^] | 3696 | static const char * const txt_aux[] = {"Aux In", "Back Surr Out"}; |
John L. Utz III | 9e285e1 | 2008-08-28 16:04:40 +0200 | [diff] [blame] | 3697 | |
Takashi Iwai | 3b7a00d | 2014-10-20 18:15:36 +0200 | [diff] [blame^] | 3698 | return snd_ctl_enum_info(uinfo, 1, 2, txt_aux); |
John L. Utz III | 9e285e1 | 2008-08-28 16:04:40 +0200 | [diff] [blame] | 3699 | } |
| 3700 | |
| 3701 | static int snd_ac97_vt1618_aux_get(struct snd_kcontrol *kcontrol, |
| 3702 | struct snd_ctl_elem_value *ucontrol) |
| 3703 | { |
| 3704 | ucontrol->value.enumerated.item[0] = |
| 3705 | (snd_ac97_read(snd_kcontrol_chip(kcontrol), 0x5c) & 0x0008)>>3; |
| 3706 | return 0; |
| 3707 | } |
| 3708 | |
| 3709 | static int snd_ac97_vt1618_aux_put(struct snd_kcontrol *kcontrol, |
| 3710 | struct snd_ctl_elem_value *ucontrol) |
| 3711 | { |
| 3712 | /* toggle surround rear dac power */ |
| 3713 | |
| 3714 | snd_ac97_update_bits(snd_kcontrol_chip(kcontrol), 0x5c, 0x0008, |
| 3715 | ucontrol->value.enumerated.item[0] << 3); |
| 3716 | |
| 3717 | /* toggle aux in surround rear out jack */ |
| 3718 | |
| 3719 | return snd_ac97_update_bits(snd_kcontrol_chip(kcontrol), 0x76, 0x0008, |
| 3720 | ucontrol->value.enumerated.item[0] << 3); |
| 3721 | } |
| 3722 | |
| 3723 | static const struct snd_kcontrol_new snd_ac97_controls_vt1618[] = { |
| 3724 | AC97_SINGLE("Exchange Center/LFE", 0x5a, 8, 1, 0), |
| 3725 | AC97_SINGLE("DC Offset", 0x5a, 10, 1, 0), |
| 3726 | AC97_SINGLE("Soft Mute", 0x5c, 0, 1, 1), |
| 3727 | AC97_SINGLE("Headphone Amp", 0x5c, 5, 1, 1), |
| 3728 | AC97_DOUBLE("Back Surr Volume", 0x5e, 8, 0, 31, 1), |
| 3729 | AC97_SINGLE("Back Surr Switch", 0x5e, 15, 1, 1), |
| 3730 | { |
| 3731 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3732 | .name = "Speaker Jack Mode", |
| 3733 | .info = snd_ac97_vt1618_UAJ_info, |
| 3734 | .get = snd_ac97_vt1618_UAJ_get, |
| 3735 | .put = snd_ac97_vt1618_UAJ_put, |
| 3736 | .private_value = 0 |
| 3737 | }, |
| 3738 | { |
| 3739 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3740 | .name = "Line Jack Mode", |
| 3741 | .info = snd_ac97_vt1618_UAJ_info, |
| 3742 | .get = snd_ac97_vt1618_UAJ_get, |
| 3743 | .put = snd_ac97_vt1618_UAJ_put, |
| 3744 | .private_value = 1 |
| 3745 | }, |
| 3746 | { |
| 3747 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3748 | .name = "Mic Jack Mode", |
| 3749 | .info = snd_ac97_vt1618_UAJ_info, |
| 3750 | .get = snd_ac97_vt1618_UAJ_get, |
| 3751 | .put = snd_ac97_vt1618_UAJ_put, |
| 3752 | .private_value = 2 |
| 3753 | }, |
| 3754 | { |
| 3755 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3756 | .name = "Aux Jack Mode", |
| 3757 | .info = snd_ac97_vt1618_aux_info, |
| 3758 | .get = snd_ac97_vt1618_aux_get, |
| 3759 | .put = snd_ac97_vt1618_aux_put, |
| 3760 | } |
| 3761 | }; |
| 3762 | |
Harvey Harrison | b03671a | 2008-08-29 13:32:00 -0700 | [diff] [blame] | 3763 | static int patch_vt1618(struct snd_ac97 *ac97) |
John L. Utz III | 9e285e1 | 2008-08-28 16:04:40 +0200 | [diff] [blame] | 3764 | { |
| 3765 | return patch_build_controls(ac97, snd_ac97_controls_vt1618, |
| 3766 | ARRAY_SIZE(snd_ac97_controls_vt1618)); |
| 3767 | } |
| 3768 | |
Philip Prindeville | 4b49948 | 2005-08-12 16:46:17 +0200 | [diff] [blame] | 3769 | /* |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 3770 | */ |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 3771 | static void it2646_update_jacks(struct snd_ac97 *ac97) |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 3772 | { |
Randy Cushman | 831466f | 2006-12-19 18:42:16 +0100 | [diff] [blame] | 3773 | /* shared Line-In / Surround Out */ |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 3774 | snd_ac97_update_bits(ac97, 0x76, 1 << 9, |
Randy Cushman | 831466f | 2006-12-19 18:42:16 +0100 | [diff] [blame] | 3775 | is_shared_surrout(ac97) ? (1<<9) : 0); |
| 3776 | /* shared Mic / Center/LFE Out */ |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 3777 | snd_ac97_update_bits(ac97, 0x76, 1 << 10, |
Randy Cushman | 831466f | 2006-12-19 18:42:16 +0100 | [diff] [blame] | 3778 | is_shared_clfeout(ac97) ? (1<<10) : 0); |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 3779 | } |
| 3780 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 3781 | static const struct snd_kcontrol_new snd_ac97_controls_it2646[] = { |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 3782 | AC97_SURROUND_JACK_MODE_CTL, |
| 3783 | AC97_CHANNEL_MODE_CTL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3784 | }; |
| 3785 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 3786 | static const struct snd_kcontrol_new snd_ac97_spdif_controls_it2646[] = { |
Clemens Ladisch | 10e8d78 | 2005-08-03 13:40:08 +0200 | [diff] [blame] | 3787 | AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 0x76, 11, 1, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3788 | AC97_SINGLE("Analog to IEC958 Output", 0x76, 12, 1, 0), |
| 3789 | AC97_SINGLE("IEC958 Input Monitor", 0x76, 13, 1, 0), |
| 3790 | }; |
| 3791 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 3792 | static int patch_it2646_specific(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3793 | { |
| 3794 | int err; |
| 3795 | if ((err = patch_build_controls(ac97, snd_ac97_controls_it2646, ARRAY_SIZE(snd_ac97_controls_it2646))) < 0) |
| 3796 | return err; |
| 3797 | if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_it2646, ARRAY_SIZE(snd_ac97_spdif_controls_it2646))) < 0) |
| 3798 | return err; |
| 3799 | return 0; |
| 3800 | } |
| 3801 | |
Hanno Boeck | 3e8b3b9 | 2011-01-14 19:14:47 +0100 | [diff] [blame] | 3802 | static const struct snd_ac97_build_ops patch_it2646_ops = { |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 3803 | .build_specific = patch_it2646_specific, |
| 3804 | .update_jacks = it2646_update_jacks |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3805 | }; |
| 3806 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 3807 | static int patch_it2646(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3808 | { |
| 3809 | ac97->build_ops = &patch_it2646_ops; |
| 3810 | /* full DAC volume */ |
| 3811 | snd_ac97_write_cache(ac97, 0x5E, 0x0808); |
| 3812 | snd_ac97_write_cache(ac97, 0x7A, 0x0808); |
| 3813 | return 0; |
| 3814 | } |
| 3815 | |
Sasha Khapyorsky | 87d61c2 | 2005-05-29 15:08:23 +0200 | [diff] [blame] | 3816 | /* |
| 3817 | * Si3036 codec |
| 3818 | */ |
| 3819 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3820 | #define AC97_SI3036_CHIP_ID 0x5a |
Sasha Khapyorsky | 87d61c2 | 2005-05-29 15:08:23 +0200 | [diff] [blame] | 3821 | #define AC97_SI3036_LINE_CFG 0x5c |
| 3822 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 3823 | static const struct snd_kcontrol_new snd_ac97_controls_si3036[] = { |
Sasha Khapyorsky | 87d61c2 | 2005-05-29 15:08:23 +0200 | [diff] [blame] | 3824 | AC97_DOUBLE("Modem Speaker Volume", 0x5c, 14, 12, 3, 1) |
| 3825 | }; |
| 3826 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 3827 | static int patch_si3036_specific(struct snd_ac97 * ac97) |
Sasha Khapyorsky | 87d61c2 | 2005-05-29 15:08:23 +0200 | [diff] [blame] | 3828 | { |
Sasha Khapyorsky | 27bcaa6 | 2005-09-13 11:23:13 +0200 | [diff] [blame] | 3829 | int idx, err; |
| 3830 | for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_si3036); idx++) |
| 3831 | if ((err = snd_ctl_add(ac97->bus->card, snd_ctl_new1(&snd_ac97_controls_si3036[idx], ac97))) < 0) |
| 3832 | return err; |
| 3833 | return 0; |
Sasha Khapyorsky | 87d61c2 | 2005-05-29 15:08:23 +0200 | [diff] [blame] | 3834 | } |
| 3835 | |
Hanno Boeck | 3e8b3b9 | 2011-01-14 19:14:47 +0100 | [diff] [blame] | 3836 | static const struct snd_ac97_build_ops patch_si3036_ops = { |
Sasha Khapyorsky | 87d61c2 | 2005-05-29 15:08:23 +0200 | [diff] [blame] | 3837 | .build_specific = patch_si3036_specific, |
| 3838 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3839 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 3840 | static int mpatch_si3036(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3841 | { |
Sasha Khapyorsky | 87d61c2 | 2005-05-29 15:08:23 +0200 | [diff] [blame] | 3842 | ac97->build_ops = &patch_si3036_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3843 | snd_ac97_write_cache(ac97, 0x5c, 0xf210 ); |
| 3844 | snd_ac97_write_cache(ac97, 0x68, 0); |
| 3845 | return 0; |
| 3846 | } |
Charl Coetzee | ba22429 | 2006-02-09 11:48:21 +0100 | [diff] [blame] | 3847 | |
| 3848 | /* |
| 3849 | * LM 4550 Codec |
| 3850 | * |
| 3851 | * We use a static resolution table since LM4550 codec cannot be |
| 3852 | * properly autoprobed to determine the resolution via |
| 3853 | * check_volume_resolution(). |
| 3854 | */ |
| 3855 | |
| 3856 | static struct snd_ac97_res_table lm4550_restbl[] = { |
| 3857 | { AC97_MASTER, 0x1f1f }, |
| 3858 | { AC97_HEADPHONE, 0x1f1f }, |
| 3859 | { AC97_MASTER_MONO, 0x001f }, |
| 3860 | { AC97_PC_BEEP, 0x001f }, /* LSB is ignored */ |
| 3861 | { AC97_PHONE, 0x001f }, |
Charl Coetzee | ba22429 | 2006-02-09 11:48:21 +0100 | [diff] [blame] | 3862 | { AC97_MIC, 0x001f }, |
| 3863 | { AC97_LINE, 0x1f1f }, |
| 3864 | { AC97_CD, 0x1f1f }, |
| 3865 | { AC97_VIDEO, 0x1f1f }, |
| 3866 | { AC97_AUX, 0x1f1f }, |
| 3867 | { AC97_PCM, 0x1f1f }, |
| 3868 | { AC97_REC_GAIN, 0x0f0f }, |
| 3869 | { } /* terminator */ |
| 3870 | }; |
| 3871 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 3872 | static int patch_lm4550(struct snd_ac97 *ac97) |
Charl Coetzee | ba22429 | 2006-02-09 11:48:21 +0100 | [diff] [blame] | 3873 | { |
| 3874 | ac97->res_table = lm4550_restbl; |
| 3875 | return 0; |
| 3876 | } |
Mike Rapoport | 82466ad | 2006-06-29 17:15:33 +0200 | [diff] [blame] | 3877 | |
| 3878 | /* |
| 3879 | * UCB1400 codec (http://www.semiconductors.philips.com/acrobat_download/datasheets/UCB1400-02.pdf) |
| 3880 | */ |
| 3881 | static const struct snd_kcontrol_new snd_ac97_controls_ucb1400[] = { |
| 3882 | /* enable/disable headphone driver which allows direct connection to |
| 3883 | stereo headphone without the use of external DC blocking |
| 3884 | capacitors */ |
| 3885 | AC97_SINGLE("Headphone Driver", 0x6a, 6, 1, 0), |
| 3886 | /* Filter used to compensate the DC offset is added in the ADC to remove idle |
| 3887 | tones from the audio band. */ |
| 3888 | AC97_SINGLE("DC Filter", 0x6a, 4, 1, 0), |
| 3889 | /* Control smart-low-power mode feature. Allows automatic power down |
| 3890 | of unused blocks in the ADC analog front end and the PLL. */ |
| 3891 | AC97_SINGLE("Smart Low Power Mode", 0x6c, 4, 3, 0), |
| 3892 | }; |
| 3893 | |
| 3894 | static int patch_ucb1400_specific(struct snd_ac97 * ac97) |
| 3895 | { |
| 3896 | int idx, err; |
| 3897 | for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_ucb1400); idx++) |
| 3898 | if ((err = snd_ctl_add(ac97->bus->card, snd_ctl_new1(&snd_ac97_controls_ucb1400[idx], ac97))) < 0) |
| 3899 | return err; |
| 3900 | return 0; |
| 3901 | } |
| 3902 | |
Hanno Boeck | 3e8b3b9 | 2011-01-14 19:14:47 +0100 | [diff] [blame] | 3903 | static const struct snd_ac97_build_ops patch_ucb1400_ops = { |
Mike Rapoport | 82466ad | 2006-06-29 17:15:33 +0200 | [diff] [blame] | 3904 | .build_specific = patch_ucb1400_specific, |
| 3905 | }; |
| 3906 | |
Takashi Iwai | ac51902 | 2007-02-22 12:58:27 +0100 | [diff] [blame] | 3907 | static int patch_ucb1400(struct snd_ac97 * ac97) |
Mike Rapoport | 82466ad | 2006-06-29 17:15:33 +0200 | [diff] [blame] | 3908 | { |
| 3909 | ac97->build_ops = &patch_ucb1400_ops; |
| 3910 | /* enable headphone driver and smart low power mode by default */ |
Mike Rapoport | 25552e8 | 2008-07-02 13:19:23 +0300 | [diff] [blame] | 3911 | snd_ac97_write_cache(ac97, 0x6a, 0x0050); |
| 3912 | snd_ac97_write_cache(ac97, 0x6c, 0x0030); |
Mike Rapoport | 82466ad | 2006-06-29 17:15:33 +0200 | [diff] [blame] | 3913 | return 0; |
| 3914 | } |