Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) by Jaroslav Kysela <perex@suse.cz> |
| 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 | |
| 26 | #include <sound/driver.h> |
| 27 | #include <linux/delay.h> |
| 28 | #include <linux/init.h> |
| 29 | #include <linux/slab.h> |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 30 | #include <linux/mutex.h> |
| 31 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <sound/core.h> |
| 33 | #include <sound/pcm.h> |
| 34 | #include <sound/control.h> |
| 35 | #include <sound/ac97_codec.h> |
| 36 | #include "ac97_patch.h" |
| 37 | #include "ac97_id.h" |
| 38 | #include "ac97_local.h" |
| 39 | |
| 40 | /* |
| 41 | * Chip specific initialization |
| 42 | */ |
| 43 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 44 | 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] | 45 | { |
| 46 | int idx, err; |
| 47 | |
| 48 | for (idx = 0; idx < count; idx++) |
| 49 | if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&controls[idx], ac97))) < 0) |
| 50 | return err; |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | /* set to the page, update bits and restore the page */ |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 55 | 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] | 56 | { |
| 57 | unsigned short page_save; |
| 58 | int ret; |
| 59 | |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 60 | mutex_lock(&ac97->page_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | page_save = snd_ac97_read(ac97, AC97_INT_PAGING) & AC97_PAGE_MASK; |
| 62 | snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page); |
| 63 | ret = snd_ac97_update_bits(ac97, reg, mask, value); |
| 64 | 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] | 65 | mutex_unlock(&ac97->page_mutex); /* unlock paging */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | return ret; |
| 67 | } |
| 68 | |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 69 | /* |
| 70 | * shared line-in/mic controls |
| 71 | */ |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 72 | static int ac97_enum_text_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo, |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 73 | const char **texts, unsigned int nums) |
| 74 | { |
| 75 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 76 | uinfo->count = 1; |
| 77 | uinfo->value.enumerated.items = nums; |
| 78 | if (uinfo->value.enumerated.item > nums - 1) |
| 79 | uinfo->value.enumerated.item = nums - 1; |
| 80 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); |
| 81 | return 0; |
| 82 | } |
| 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 | { |
| 86 | static const char *texts[] = { "Shared", "Independent" }; |
| 87 | return ac97_enum_text_info(kcontrol, uinfo, texts, 2); |
| 88 | } |
| 89 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 90 | 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] | 91 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 92 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 93 | |
| 94 | ucontrol->value.enumerated.item[0] = ac97->indep_surround; |
| 95 | return 0; |
| 96 | } |
| 97 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 98 | 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] | 99 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 100 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 101 | unsigned char indep = !!ucontrol->value.enumerated.item[0]; |
| 102 | |
| 103 | if (indep != ac97->indep_surround) { |
| 104 | ac97->indep_surround = indep; |
| 105 | if (ac97->build_ops->update_jacks) |
| 106 | ac97->build_ops->update_jacks(ac97); |
| 107 | return 1; |
| 108 | } |
| 109 | return 0; |
| 110 | } |
| 111 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 112 | 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] | 113 | { |
| 114 | static const char *texts[] = { "2ch", "4ch", "6ch" }; |
| 115 | if (kcontrol->private_value) |
| 116 | return ac97_enum_text_info(kcontrol, uinfo, texts, 2); /* 4ch only */ |
| 117 | return ac97_enum_text_info(kcontrol, uinfo, texts, 3); |
| 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 | |
| 133 | if (mode != ac97->channel_mode) { |
| 134 | ac97->channel_mode = mode; |
| 135 | if (ac97->build_ops->update_jacks) |
| 136 | ac97->build_ops->update_jacks(ac97); |
| 137 | return 1; |
| 138 | } |
| 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | #define AC97_SURROUND_JACK_MODE_CTL \ |
| 143 | { \ |
| 144 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 145 | .name = "Surround Jack Mode", \ |
| 146 | .info = ac97_surround_jack_mode_info, \ |
| 147 | .get = ac97_surround_jack_mode_get, \ |
| 148 | .put = ac97_surround_jack_mode_put, \ |
| 149 | } |
| 150 | #define AC97_CHANNEL_MODE_CTL \ |
| 151 | { \ |
| 152 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 153 | .name = "Channel Mode", \ |
| 154 | .info = ac97_channel_mode_info, \ |
| 155 | .get = ac97_channel_mode_get, \ |
| 156 | .put = ac97_channel_mode_put, \ |
| 157 | } |
| 158 | #define AC97_CHANNEL_MODE_4CH_CTL \ |
| 159 | { \ |
| 160 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 161 | .name = "Channel Mode", \ |
| 162 | .info = ac97_channel_mode_info, \ |
| 163 | .get = ac97_channel_mode_get, \ |
| 164 | .put = ac97_channel_mode_put, \ |
| 165 | .private_value = 1, \ |
| 166 | } |
| 167 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 168 | static inline int is_surround_on(struct snd_ac97 *ac97) |
Takashi Iwai | 4525c9f | 2005-09-13 11:47:07 +0200 | [diff] [blame] | 169 | { |
| 170 | return ac97->channel_mode >= 1; |
| 171 | } |
| 172 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 173 | static inline int is_clfe_on(struct snd_ac97 *ac97) |
Takashi Iwai | 4525c9f | 2005-09-13 11:47:07 +0200 | [diff] [blame] | 174 | { |
Takashi Iwai | eb9b414 | 2005-09-13 18:39:21 +0200 | [diff] [blame] | 175 | return ac97->channel_mode >= 2; |
Takashi Iwai | 4525c9f | 2005-09-13 11:47:07 +0200 | [diff] [blame] | 176 | } |
| 177 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 178 | static inline int is_shared_linein(struct snd_ac97 *ac97) |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 179 | { |
Takashi Iwai | 4525c9f | 2005-09-13 11:47:07 +0200 | [diff] [blame] | 180 | return ! ac97->indep_surround && is_surround_on(ac97); |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 181 | } |
| 182 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 183 | static inline int is_shared_micin(struct snd_ac97 *ac97) |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 184 | { |
Takashi Iwai | 4525c9f | 2005-09-13 11:47:07 +0200 | [diff] [blame] | 185 | return ! ac97->indep_surround && is_clfe_on(ac97); |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | /* The following snd_ac97_ymf753_... items added by David Shust (dshust@shustring.com) */ |
| 190 | |
| 191 | /* It is possible to indicate to the Yamaha YMF753 the type of speakers being used. */ |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 192 | static int snd_ac97_ymf753_info_speaker(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | { |
| 194 | static char *texts[3] = { |
| 195 | "Standard", "Small", "Smaller" |
| 196 | }; |
| 197 | |
| 198 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 199 | uinfo->count = 1; |
| 200 | uinfo->value.enumerated.items = 3; |
| 201 | if (uinfo->value.enumerated.item > 2) |
| 202 | uinfo->value.enumerated.item = 2; |
| 203 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); |
| 204 | return 0; |
| 205 | } |
| 206 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 207 | static int snd_ac97_ymf753_get_speaker(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 209 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | unsigned short val; |
| 211 | |
| 212 | val = ac97->regs[AC97_YMF753_3D_MODE_SEL]; |
| 213 | val = (val >> 10) & 3; |
| 214 | if (val > 0) /* 0 = invalid */ |
| 215 | val--; |
| 216 | ucontrol->value.enumerated.item[0] = val; |
| 217 | return 0; |
| 218 | } |
| 219 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 220 | static int snd_ac97_ymf753_put_speaker(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 222 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | unsigned short val; |
| 224 | |
| 225 | if (ucontrol->value.enumerated.item[0] > 2) |
| 226 | return -EINVAL; |
| 227 | val = (ucontrol->value.enumerated.item[0] + 1) << 10; |
| 228 | return snd_ac97_update(ac97, AC97_YMF753_3D_MODE_SEL, val); |
| 229 | } |
| 230 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 231 | static const struct snd_kcontrol_new snd_ac97_ymf753_controls_speaker = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | { |
| 233 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 234 | .name = "3D Control - Speaker", |
| 235 | .info = snd_ac97_ymf753_info_speaker, |
| 236 | .get = snd_ac97_ymf753_get_speaker, |
| 237 | .put = snd_ac97_ymf753_put_speaker, |
| 238 | }; |
| 239 | |
| 240 | /* It is possible to indicate to the Yamaha YMF753 the source to direct to the S/PDIF output. */ |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 241 | static int snd_ac97_ymf753_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] | 242 | { |
| 243 | static char *texts[2] = { "AC-Link", "A/D Converter" }; |
| 244 | |
| 245 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 246 | uinfo->count = 1; |
| 247 | uinfo->value.enumerated.items = 2; |
| 248 | if (uinfo->value.enumerated.item > 1) |
| 249 | uinfo->value.enumerated.item = 1; |
| 250 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); |
| 251 | return 0; |
| 252 | } |
| 253 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 254 | static int snd_ac97_ymf753_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] | 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 | val = ac97->regs[AC97_YMF753_DIT_CTRL2]; |
| 260 | ucontrol->value.enumerated.item[0] = (val >> 1) & 1; |
| 261 | return 0; |
| 262 | } |
| 263 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 264 | static int snd_ac97_ymf753_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] | 265 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 266 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | unsigned short val; |
| 268 | |
| 269 | if (ucontrol->value.enumerated.item[0] > 1) |
| 270 | return -EINVAL; |
| 271 | val = ucontrol->value.enumerated.item[0] << 1; |
| 272 | return snd_ac97_update_bits(ac97, AC97_YMF753_DIT_CTRL2, 0x0002, val); |
| 273 | } |
| 274 | |
| 275 | /* The AC'97 spec states that the S/PDIF signal is to be output at pin 48. |
| 276 | The YMF753 will output the S/PDIF signal to pin 43, 47 (EAPD), or 48. |
| 277 | By default, no output pin is selected, and the S/PDIF signal is not output. |
| 278 | 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] | 279 | 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] | 280 | { |
| 281 | static char *texts[3] = { "Disabled", "Pin 43", "Pin 48" }; |
| 282 | |
| 283 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 284 | uinfo->count = 1; |
| 285 | uinfo->value.enumerated.items = 3; |
| 286 | if (uinfo->value.enumerated.item > 2) |
| 287 | uinfo->value.enumerated.item = 2; |
| 288 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); |
| 289 | return 0; |
| 290 | } |
| 291 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 292 | 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] | 293 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 294 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | unsigned short val; |
| 296 | |
| 297 | val = ac97->regs[AC97_YMF753_DIT_CTRL2]; |
| 298 | ucontrol->value.enumerated.item[0] = (val & 0x0008) ? 2 : (val & 0x0020) ? 1 : 0; |
| 299 | return 0; |
| 300 | } |
| 301 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 302 | 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] | 303 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 304 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | unsigned short val; |
| 306 | |
| 307 | if (ucontrol->value.enumerated.item[0] > 2) |
| 308 | return -EINVAL; |
| 309 | val = (ucontrol->value.enumerated.item[0] == 2) ? 0x0008 : |
| 310 | (ucontrol->value.enumerated.item[0] == 1) ? 0x0020 : 0; |
| 311 | return snd_ac97_update_bits(ac97, AC97_YMF753_DIT_CTRL2, 0x0028, val); |
| 312 | /* The following can be used to direct S/PDIF output to pin 47 (EAPD). |
| 313 | snd_ac97_write_cache(ac97, 0x62, snd_ac97_read(ac97, 0x62) | 0x0008); */ |
| 314 | } |
| 315 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 316 | static const struct snd_kcontrol_new snd_ac97_ymf753_controls_spdif[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | { |
| 318 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 319 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source", |
| 320 | .info = snd_ac97_ymf753_spdif_source_info, |
| 321 | .get = snd_ac97_ymf753_spdif_source_get, |
| 322 | .put = snd_ac97_ymf753_spdif_source_put, |
| 323 | }, |
| 324 | { |
| 325 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 326 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Output Pin", |
| 327 | .info = snd_ac97_ymf753_spdif_output_pin_info, |
| 328 | .get = snd_ac97_ymf753_spdif_output_pin_get, |
| 329 | .put = snd_ac97_ymf753_spdif_output_pin_put, |
| 330 | }, |
| 331 | AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",NONE,NONE) "Mute", AC97_YMF753_DIT_CTRL2, 2, 1, 1) |
| 332 | }; |
| 333 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 334 | static int patch_yamaha_ymf753_3d(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 336 | struct snd_kcontrol *kctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | int err; |
| 338 | |
| 339 | if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0) |
| 340 | return err; |
| 341 | strcpy(kctl->id.name, "3D Control - Wide"); |
| 342 | kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 9, 7, 0); |
| 343 | snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000); |
| 344 | if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&snd_ac97_ymf753_controls_speaker, ac97))) < 0) |
| 345 | return err; |
| 346 | snd_ac97_write_cache(ac97, AC97_YMF753_3D_MODE_SEL, 0x0c00); |
| 347 | return 0; |
| 348 | } |
| 349 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 350 | static int patch_yamaha_ymf753_post_spdif(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | { |
| 352 | int err; |
| 353 | |
| 354 | if ((err = patch_build_controls(ac97, snd_ac97_ymf753_controls_spdif, ARRAY_SIZE(snd_ac97_ymf753_controls_spdif))) < 0) |
| 355 | return err; |
| 356 | return 0; |
| 357 | } |
| 358 | |
| 359 | static struct snd_ac97_build_ops patch_yamaha_ymf753_ops = { |
| 360 | .build_3d = patch_yamaha_ymf753_3d, |
| 361 | .build_post_spdif = patch_yamaha_ymf753_post_spdif |
| 362 | }; |
| 363 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 364 | int patch_yamaha_ymf753(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | { |
| 366 | /* Patch for Yamaha YMF753, Copyright (c) by David Shust, dshust@shustring.com. |
| 367 | This chip has nonstandard and extended behaviour with regard to its S/PDIF output. |
| 368 | The AC'97 spec states that the S/PDIF signal is to be output at pin 48. |
| 369 | The YMF753 will ouput the S/PDIF signal to pin 43, 47 (EAPD), or 48. |
| 370 | By default, no output pin is selected, and the S/PDIF signal is not output. |
| 371 | There is also a bit to mute S/PDIF output in a vendor-specific register. |
| 372 | */ |
| 373 | ac97->build_ops = &patch_yamaha_ymf753_ops; |
| 374 | ac97->caps |= AC97_BC_BASS_TREBLE; |
| 375 | ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */ |
| 376 | return 0; |
| 377 | } |
| 378 | |
| 379 | /* |
| 380 | * May 2, 2003 Liam Girdwood <liam.girdwood@wolfsonmicro.com> |
| 381 | * removed broken wolfson00 patch. |
| 382 | * added support for WM9705,WM9708,WM9709,WM9710,WM9711,WM9712 and WM9717. |
| 383 | */ |
| 384 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 385 | static const struct snd_kcontrol_new wm97xx_snd_ac97_controls[] = { |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 386 | AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1), |
| 387 | AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1), |
| 388 | }; |
| 389 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 390 | static int patch_wolfson_wm9703_specific(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | { |
| 392 | /* This is known to work for the ViewSonic ViewPad 1000 |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 393 | * Randolph Bentson <bentson@holmsjoen.com> |
| 394 | * WM9703/9707/9708/9717 |
| 395 | */ |
| 396 | int err, i; |
| 397 | |
| 398 | for (i = 0; i < ARRAY_SIZE(wm97xx_snd_ac97_controls); i++) { |
| 399 | if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm97xx_snd_ac97_controls[i], ac97))) < 0) |
| 400 | return err; |
| 401 | } |
| 402 | snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | return 0; |
| 404 | } |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 405 | |
| 406 | static struct snd_ac97_build_ops patch_wolfson_wm9703_ops = { |
| 407 | .build_specific = patch_wolfson_wm9703_specific, |
| 408 | }; |
| 409 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 410 | int patch_wolfson03(struct snd_ac97 * ac97) |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 411 | { |
| 412 | ac97->build_ops = &patch_wolfson_wm9703_ops; |
| 413 | return 0; |
| 414 | } |
| 415 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 416 | static const struct snd_kcontrol_new wm9704_snd_ac97_controls[] = { |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 417 | AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1), |
| 418 | AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1), |
| 419 | AC97_DOUBLE("Rear Playback Volume", AC97_WM9704_RMIXER_VOL, 8, 0, 31, 1), |
| 420 | AC97_SINGLE("Rear Playback Switch", AC97_WM9704_RMIXER_VOL, 15, 1, 1), |
| 421 | AC97_DOUBLE("Rear DAC Volume", AC97_WM9704_RPCM_VOL, 8, 0, 31, 1), |
| 422 | AC97_DOUBLE("Surround Volume", AC97_SURROUND_MASTER, 8, 0, 31, 1), |
| 423 | }; |
| 424 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 425 | static int patch_wolfson_wm9704_specific(struct snd_ac97 * ac97) |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 426 | { |
| 427 | int err, i; |
| 428 | for (i = 0; i < ARRAY_SIZE(wm9704_snd_ac97_controls); i++) { |
| 429 | if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9704_snd_ac97_controls[i], ac97))) < 0) |
| 430 | return err; |
| 431 | } |
| 432 | /* patch for DVD noise */ |
| 433 | snd_ac97_write_cache(ac97, AC97_WM9704_TEST, 0x0200); |
| 434 | return 0; |
| 435 | } |
| 436 | |
| 437 | static struct snd_ac97_build_ops patch_wolfson_wm9704_ops = { |
| 438 | .build_specific = patch_wolfson_wm9704_specific, |
| 439 | }; |
| 440 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 441 | int patch_wolfson04(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | { |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 443 | /* WM9704M/9704Q */ |
| 444 | ac97->build_ops = &patch_wolfson_wm9704_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | return 0; |
| 446 | } |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 447 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 448 | static int patch_wolfson_wm9705_specific(struct snd_ac97 * ac97) |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 449 | { |
| 450 | int err, i; |
| 451 | for (i = 0; i < ARRAY_SIZE(wm97xx_snd_ac97_controls); i++) { |
| 452 | if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm97xx_snd_ac97_controls[i], ac97))) < 0) |
| 453 | return err; |
| 454 | } |
| 455 | snd_ac97_write_cache(ac97, 0x72, 0x0808); |
| 456 | return 0; |
| 457 | } |
| 458 | |
| 459 | static struct snd_ac97_build_ops patch_wolfson_wm9705_ops = { |
| 460 | .build_specific = patch_wolfson_wm9705_specific, |
| 461 | }; |
| 462 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 463 | int patch_wolfson05(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | { |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 465 | /* WM9705, WM9710 */ |
| 466 | ac97->build_ops = &patch_wolfson_wm9705_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | return 0; |
| 468 | } |
| 469 | |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 470 | static const char* wm9711_alc_select[] = {"None", "Left", "Right", "Stereo"}; |
| 471 | static const char* wm9711_alc_mix[] = {"Stereo", "Right", "Left", "None"}; |
| 472 | static const char* wm9711_out3_src[] = {"Left", "VREF", "Left + Right", "Mono"}; |
| 473 | static const char* wm9711_out3_lrsrc[] = {"Master Mix", "Headphone Mix"}; |
| 474 | static const char* wm9711_rec_adc[] = {"Stereo", "Left", "Right", "Mute"}; |
| 475 | static const char* wm9711_base[] = {"Linear Control", "Adaptive Boost"}; |
| 476 | static const char* wm9711_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"}; |
| 477 | static const char* wm9711_mic[] = {"Mic 1", "Differential", "Mic 2", "Stereo"}; |
| 478 | static const char* wm9711_rec_sel[] = |
| 479 | {"Mic 1", "NC", "NC", "Master Mix", "Line", "Headphone Mix", "Phone Mix", "Phone"}; |
| 480 | static const char* wm9711_ng_type[] = {"Constant Gain", "Mute"}; |
| 481 | |
| 482 | static const struct ac97_enum wm9711_enum[] = { |
| 483 | AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9711_alc_select), |
| 484 | AC97_ENUM_SINGLE(AC97_VIDEO, 10, 4, wm9711_alc_mix), |
| 485 | AC97_ENUM_SINGLE(AC97_AUX, 9, 4, wm9711_out3_src), |
| 486 | AC97_ENUM_SINGLE(AC97_AUX, 8, 2, wm9711_out3_lrsrc), |
| 487 | AC97_ENUM_SINGLE(AC97_REC_SEL, 12, 4, wm9711_rec_adc), |
| 488 | AC97_ENUM_SINGLE(AC97_MASTER_TONE, 15, 2, wm9711_base), |
| 489 | AC97_ENUM_DOUBLE(AC97_REC_GAIN, 14, 6, 2, wm9711_rec_gain), |
| 490 | AC97_ENUM_SINGLE(AC97_MIC, 5, 4, wm9711_mic), |
| 491 | AC97_ENUM_DOUBLE(AC97_REC_SEL, 8, 0, 8, wm9711_rec_sel), |
| 492 | AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9711_ng_type), |
| 493 | }; |
| 494 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 495 | static const struct snd_kcontrol_new wm9711_snd_ac97_controls[] = { |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 496 | AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0), |
| 497 | AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0), |
| 498 | AC97_SINGLE("ALC Decay Time", AC97_CODEC_CLASS_REV, 4, 15, 0), |
| 499 | AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0), |
| 500 | AC97_ENUM("ALC Function", wm9711_enum[0]), |
| 501 | AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 1), |
| 502 | AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 1), |
| 503 | AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0), |
| 504 | AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0), |
| 505 | AC97_ENUM("ALC NG Type", wm9711_enum[9]), |
| 506 | AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 1), |
| 507 | |
| 508 | AC97_SINGLE("Side Tone Switch", AC97_VIDEO, 15, 1, 1), |
| 509 | AC97_SINGLE("Side Tone Volume", AC97_VIDEO, 12, 7, 1), |
| 510 | AC97_ENUM("ALC Headphone Mux", wm9711_enum[1]), |
| 511 | AC97_SINGLE("ALC Headphone Volume", AC97_VIDEO, 7, 7, 1), |
| 512 | |
| 513 | AC97_SINGLE("Out3 Switch", AC97_AUX, 15, 1, 1), |
| 514 | AC97_SINGLE("Out3 ZC Switch", AC97_AUX, 7, 1, 1), |
| 515 | AC97_ENUM("Out3 Mux", wm9711_enum[2]), |
| 516 | AC97_ENUM("Out3 LR Mux", wm9711_enum[3]), |
| 517 | AC97_SINGLE("Out3 Volume", AC97_AUX, 0, 31, 1), |
| 518 | |
| 519 | AC97_SINGLE("Beep to Headphone Switch", AC97_PC_BEEP, 15, 1, 1), |
| 520 | AC97_SINGLE("Beep to Headphone Volume", AC97_PC_BEEP, 12, 7, 1), |
| 521 | AC97_SINGLE("Beep to Side Tone Switch", AC97_PC_BEEP, 11, 1, 1), |
| 522 | AC97_SINGLE("Beep to Side Tone Volume", AC97_PC_BEEP, 8, 7, 1), |
| 523 | AC97_SINGLE("Beep to Phone Switch", AC97_PC_BEEP, 7, 1, 1), |
| 524 | AC97_SINGLE("Beep to Phone Volume", AC97_PC_BEEP, 4, 7, 1), |
| 525 | |
| 526 | AC97_SINGLE("Aux to Headphone Switch", AC97_CD, 15, 1, 1), |
| 527 | AC97_SINGLE("Aux to Headphone Volume", AC97_CD, 12, 7, 1), |
| 528 | AC97_SINGLE("Aux to Side Tone Switch", AC97_CD, 11, 1, 1), |
| 529 | AC97_SINGLE("Aux to Side Tone Volume", AC97_CD, 8, 7, 1), |
| 530 | AC97_SINGLE("Aux to Phone Switch", AC97_CD, 7, 1, 1), |
| 531 | AC97_SINGLE("Aux to Phone Volume", AC97_CD, 4, 7, 1), |
| 532 | |
| 533 | AC97_SINGLE("Phone to Headphone Switch", AC97_PHONE, 15, 1, 1), |
| 534 | AC97_SINGLE("Phone to Master Switch", AC97_PHONE, 14, 1, 1), |
| 535 | |
| 536 | AC97_SINGLE("Line to Headphone Switch", AC97_LINE, 15, 1, 1), |
| 537 | AC97_SINGLE("Line to Master Switch", AC97_LINE, 14, 1, 1), |
| 538 | AC97_SINGLE("Line to Phone Switch", AC97_LINE, 13, 1, 1), |
| 539 | |
| 540 | AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PCM, 15, 1, 1), |
| 541 | AC97_SINGLE("PCM Playback to Master Switch", AC97_PCM, 14, 1, 1), |
| 542 | AC97_SINGLE("PCM Playback to Phone Switch", AC97_PCM, 13, 1, 1), |
| 543 | |
| 544 | AC97_SINGLE("Capture 20dB Boost Switch", AC97_REC_SEL, 14, 1, 0), |
| 545 | AC97_ENUM("Capture to Phone Mux", wm9711_enum[4]), |
| 546 | AC97_SINGLE("Capture to Phone 20dB Boost Switch", AC97_REC_SEL, 11, 1, 1), |
| 547 | AC97_ENUM("Capture Select", wm9711_enum[8]), |
| 548 | |
| 549 | AC97_SINGLE("3D Upper Cut-off Switch", AC97_3D_CONTROL, 5, 1, 1), |
| 550 | AC97_SINGLE("3D Lower Cut-off Switch", AC97_3D_CONTROL, 4, 1, 1), |
| 551 | |
| 552 | AC97_ENUM("Bass Control", wm9711_enum[5]), |
| 553 | AC97_SINGLE("Bass Cut-off Switch", AC97_MASTER_TONE, 12, 1, 1), |
| 554 | AC97_SINGLE("Tone Cut-off Switch", AC97_MASTER_TONE, 4, 1, 1), |
| 555 | AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_MASTER_TONE, 6, 1, 0), |
| 556 | |
| 557 | AC97_SINGLE("ADC Switch", AC97_REC_GAIN, 15, 1, 1), |
| 558 | AC97_ENUM("Capture Volume Steps", wm9711_enum[6]), |
| 559 | AC97_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 15, 1), |
| 560 | AC97_SINGLE("Capture ZC Switch", AC97_REC_GAIN, 7, 1, 0), |
| 561 | |
| 562 | AC97_SINGLE("Mic 1 to Phone Switch", AC97_MIC, 14, 1, 1), |
| 563 | AC97_SINGLE("Mic 2 to Phone Switch", AC97_MIC, 13, 1, 1), |
| 564 | AC97_ENUM("Mic Select Source", wm9711_enum[7]), |
| 565 | AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 32, 1), |
| 566 | AC97_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 7, 1, 0), |
| 567 | |
| 568 | AC97_SINGLE("Master ZC Switch", AC97_MASTER, 7, 1, 0), |
| 569 | AC97_SINGLE("Headphone ZC Switch", AC97_HEADPHONE, 7, 1, 0), |
| 570 | AC97_SINGLE("Mono ZC Switch", AC97_MASTER_MONO, 7, 1, 0), |
| 571 | }; |
| 572 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 573 | static int patch_wolfson_wm9711_specific(struct snd_ac97 * ac97) |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 574 | { |
| 575 | int err, i; |
| 576 | |
| 577 | for (i = 0; i < ARRAY_SIZE(wm9711_snd_ac97_controls); i++) { |
| 578 | if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9711_snd_ac97_controls[i], ac97))) < 0) |
| 579 | return err; |
| 580 | } |
| 581 | snd_ac97_write_cache(ac97, AC97_CODEC_CLASS_REV, 0x0808); |
| 582 | snd_ac97_write_cache(ac97, AC97_PCI_SVID, 0x0808); |
| 583 | snd_ac97_write_cache(ac97, AC97_VIDEO, 0x0808); |
| 584 | snd_ac97_write_cache(ac97, AC97_AUX, 0x0808); |
| 585 | snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808); |
| 586 | snd_ac97_write_cache(ac97, AC97_CD, 0x0000); |
| 587 | return 0; |
| 588 | } |
| 589 | |
| 590 | static struct snd_ac97_build_ops patch_wolfson_wm9711_ops = { |
| 591 | .build_specific = patch_wolfson_wm9711_specific, |
| 592 | }; |
| 593 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 594 | int patch_wolfson11(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | { |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 596 | /* WM9711, WM9712 */ |
| 597 | ac97->build_ops = &patch_wolfson_wm9711_ops; |
| 598 | |
| 599 | ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_MIC | |
| 600 | AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD; |
| 601 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | return 0; |
| 603 | } |
| 604 | |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 605 | static const char* wm9713_mic_mixer[] = {"Stereo", "Mic 1", "Mic 2", "Mute"}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | static const char* wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"}; |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 607 | static const char* wm9713_rec_src[] = |
| 608 | {"Mic 1", "Mic 2", "Line", "Mono In", "Headphone Mix", "Master Mix", |
| 609 | "Mono Mix", "Zh"}; |
| 610 | static const char* wm9713_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"}; |
| 611 | static const char* wm9713_alc_select[] = {"None", "Left", "Right", "Stereo"}; |
| 612 | static const char* wm9713_mono_pga[] = {"Vmid", "Zh", "Mono Mix", "Inv 1"}; |
| 613 | static const char* wm9713_spk_pga[] = |
| 614 | {"Vmid", "Zh", "Headphone Mix", "Master Mix", "Inv", "NC", "NC", "NC"}; |
| 615 | static const char* wm9713_hp_pga[] = {"Vmid", "Zh", "Headphone Mix", "NC"}; |
| 616 | static const char* wm9713_out3_pga[] = {"Vmid", "Zh", "Inv 1", "NC"}; |
| 617 | static const char* wm9713_out4_pga[] = {"Vmid", "Zh", "Inv 2", "NC"}; |
| 618 | static const char* wm9713_dac_inv[] = |
| 619 | {"Off", "Mono Mix", "Master Mix", "Headphone Mix L", "Headphone Mix R", |
| 620 | "Headphone Mix Mono", "NC", "Vmid"}; |
| 621 | static const char* wm9713_base[] = {"Linear Control", "Adaptive Boost"}; |
| 622 | static const char* wm9713_ng_type[] = {"Constant Gain", "Mute"}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | |
| 624 | static const struct ac97_enum wm9713_enum[] = { |
| 625 | AC97_ENUM_SINGLE(AC97_LINE, 3, 4, wm9713_mic_mixer), |
| 626 | AC97_ENUM_SINGLE(AC97_VIDEO, 14, 4, wm9713_rec_mux), |
| 627 | AC97_ENUM_SINGLE(AC97_VIDEO, 9, 4, wm9713_rec_mux), |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 628 | AC97_ENUM_DOUBLE(AC97_VIDEO, 3, 0, 8, wm9713_rec_src), |
| 629 | AC97_ENUM_DOUBLE(AC97_CD, 14, 6, 2, wm9713_rec_gain), |
| 630 | AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9713_alc_select), |
| 631 | AC97_ENUM_SINGLE(AC97_REC_GAIN, 14, 4, wm9713_mono_pga), |
| 632 | AC97_ENUM_DOUBLE(AC97_REC_GAIN, 11, 8, 8, wm9713_spk_pga), |
| 633 | AC97_ENUM_DOUBLE(AC97_REC_GAIN, 6, 4, 4, wm9713_hp_pga), |
| 634 | AC97_ENUM_SINGLE(AC97_REC_GAIN, 2, 4, wm9713_out3_pga), |
| 635 | AC97_ENUM_SINGLE(AC97_REC_GAIN, 0, 4, wm9713_out4_pga), |
| 636 | AC97_ENUM_DOUBLE(AC97_REC_GAIN_MIC, 13, 10, 8, wm9713_dac_inv), |
| 637 | AC97_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, wm9713_base), |
| 638 | AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9713_ng_type), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | }; |
| 640 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 641 | static const struct snd_kcontrol_new wm13_snd_ac97_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | AC97_DOUBLE("Line In Volume", AC97_PC_BEEP, 8, 0, 31, 1), |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 643 | AC97_SINGLE("Line In to Headphone Switch", AC97_PC_BEEP, 15, 1, 1), |
| 644 | AC97_SINGLE("Line In to Master Switch", AC97_PC_BEEP, 14, 1, 1), |
| 645 | AC97_SINGLE("Line In to Mono Switch", AC97_PC_BEEP, 13, 1, 1), |
| 646 | |
| 647 | AC97_DOUBLE("PCM Playback Volume", AC97_PHONE, 8, 0, 31, 1), |
| 648 | AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PHONE, 15, 1, 1), |
| 649 | AC97_SINGLE("PCM Playback to Master Switch", AC97_PHONE, 14, 1, 1), |
| 650 | AC97_SINGLE("PCM Playback to Mono Switch", AC97_PHONE, 13, 1, 1), |
| 651 | |
| 652 | AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1), |
| 653 | AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1), |
| 654 | AC97_SINGLE("Mic 1 to Mono Switch", AC97_LINE, 7, 1, 1), |
| 655 | AC97_SINGLE("Mic 2 to Mono Switch", AC97_LINE, 6, 1, 1), |
| 656 | AC97_SINGLE("Mic Boost (+20dB) Switch", AC97_LINE, 5, 1, 0), |
| 657 | AC97_ENUM("Mic to Headphone Mux", wm9713_enum[0]), |
| 658 | AC97_SINGLE("Mic Headphone Mixer Volume", AC97_LINE, 0, 7, 1), |
| 659 | |
| 660 | AC97_SINGLE("Capture Switch", AC97_CD, 15, 1, 1), |
| 661 | AC97_ENUM("Capture Volume Steps", wm9713_enum[4]), |
| 662 | AC97_DOUBLE("Capture Volume", AC97_CD, 8, 0, 15, 0), |
| 663 | AC97_SINGLE("Capture ZC Switch", AC97_CD, 7, 1, 0), |
| 664 | |
| 665 | AC97_ENUM("Capture to Headphone Mux", wm9713_enum[1]), |
| 666 | AC97_SINGLE("Capture to Headphone Volume", AC97_VIDEO, 11, 7, 1), |
| 667 | AC97_ENUM("Capture to Mono Mux", wm9713_enum[2]), |
| 668 | AC97_SINGLE("Capture to Mono Boost (+20dB) Switch", AC97_VIDEO, 8, 1, 0), |
| 669 | AC97_SINGLE("Capture ADC Boost (+20dB) Switch", AC97_VIDEO, 6, 1, 0), |
| 670 | AC97_ENUM("Capture Select", wm9713_enum[3]), |
| 671 | |
| 672 | AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0), |
| 673 | AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0), |
| 674 | AC97_SINGLE("ALC Decay Time ", AC97_CODEC_CLASS_REV, 4, 15, 0), |
| 675 | AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0), |
| 676 | AC97_ENUM("ALC Function", wm9713_enum[5]), |
| 677 | AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 0), |
| 678 | AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 0), |
| 679 | AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0), |
| 680 | AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0), |
| 681 | AC97_ENUM("ALC NG Type", wm9713_enum[13]), |
| 682 | AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 0), |
| 683 | |
| 684 | AC97_DOUBLE("Master ZC Switch", AC97_MASTER, 14, 6, 1, 0), |
| 685 | AC97_DOUBLE("Headphone ZC Switch", AC97_HEADPHONE, 14, 6, 1, 0), |
| 686 | AC97_DOUBLE("Out3/4 ZC Switch", AC97_MASTER_MONO, 14, 6, 1, 0), |
| 687 | AC97_SINGLE("Master Right Switch", AC97_MASTER, 7, 1, 1), |
| 688 | AC97_SINGLE("Headphone Right Switch", AC97_HEADPHONE, 7, 1, 1), |
| 689 | AC97_SINGLE("Out3/4 Right Switch", AC97_MASTER_MONO, 7, 1, 1), |
| 690 | |
| 691 | AC97_SINGLE("Mono In to Headphone Switch", AC97_MASTER_TONE, 15, 1, 1), |
| 692 | AC97_SINGLE("Mono In to Master Switch", AC97_MASTER_TONE, 14, 1, 1), |
| 693 | AC97_SINGLE("Mono In Volume", AC97_MASTER_TONE, 8, 31, 1), |
| 694 | AC97_SINGLE("Mono Switch", AC97_MASTER_TONE, 7, 1, 1), |
| 695 | AC97_SINGLE("Mono ZC Switch", AC97_MASTER_TONE, 6, 1, 0), |
| 696 | AC97_SINGLE("Mono Volume", AC97_MASTER_TONE, 0, 31, 1), |
| 697 | |
| 698 | AC97_SINGLE("PC Beep to Headphone Switch", AC97_AUX, 15, 1, 1), |
| 699 | AC97_SINGLE("PC Beep to Headphone Volume", AC97_AUX, 12, 7, 1), |
| 700 | AC97_SINGLE("PC Beep to Master Switch", AC97_AUX, 11, 1, 1), |
| 701 | AC97_SINGLE("PC Beep to Master Volume", AC97_AUX, 8, 7, 1), |
| 702 | AC97_SINGLE("PC Beep to Mono Switch", AC97_AUX, 7, 1, 1), |
| 703 | AC97_SINGLE("PC Beep to Mono Volume", AC97_AUX, 4, 7, 1), |
| 704 | |
| 705 | AC97_SINGLE("Voice to Headphone Switch", AC97_PCM, 15, 1, 1), |
| 706 | AC97_SINGLE("Voice to Headphone Volume", AC97_PCM, 12, 7, 1), |
| 707 | AC97_SINGLE("Voice to Master Switch", AC97_PCM, 11, 1, 1), |
| 708 | AC97_SINGLE("Voice to Master Volume", AC97_PCM, 8, 7, 1), |
| 709 | AC97_SINGLE("Voice to Mono Switch", AC97_PCM, 7, 1, 1), |
| 710 | AC97_SINGLE("Voice to Mono Volume", AC97_PCM, 4, 7, 1), |
| 711 | |
| 712 | AC97_SINGLE("Aux to Headphone Switch", AC97_REC_SEL, 15, 1, 1), |
| 713 | AC97_SINGLE("Aux to Headphone Volume", AC97_REC_SEL, 12, 7, 1), |
| 714 | AC97_SINGLE("Aux to Master Switch", AC97_REC_SEL, 11, 1, 1), |
| 715 | AC97_SINGLE("Aux to Master Volume", AC97_REC_SEL, 8, 7, 1), |
| 716 | AC97_SINGLE("Aux to Mono Switch", AC97_REC_SEL, 7, 1, 1), |
| 717 | AC97_SINGLE("Aux to Mono Volume", AC97_REC_SEL, 4, 7, 1), |
| 718 | |
| 719 | AC97_ENUM("Mono Input Mux", wm9713_enum[6]), |
| 720 | AC97_ENUM("Master Input Mux", wm9713_enum[7]), |
| 721 | AC97_ENUM("Headphone Input Mux", wm9713_enum[8]), |
| 722 | AC97_ENUM("Out 3 Input Mux", wm9713_enum[9]), |
| 723 | AC97_ENUM("Out 4 Input Mux", wm9713_enum[10]), |
| 724 | |
| 725 | AC97_ENUM("Bass Control", wm9713_enum[12]), |
| 726 | AC97_SINGLE("Bass Cut-off Switch", AC97_GENERAL_PURPOSE, 12, 1, 1), |
| 727 | AC97_SINGLE("Tone Cut-off Switch", AC97_GENERAL_PURPOSE, 4, 1, 1), |
| 728 | AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_GENERAL_PURPOSE, 6, 1, 0), |
| 729 | AC97_SINGLE("Bass Volume", AC97_GENERAL_PURPOSE, 8, 15, 1), |
| 730 | AC97_SINGLE("Tone Volume", AC97_GENERAL_PURPOSE, 0, 15, 1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | }; |
| 732 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 733 | static const struct snd_kcontrol_new wm13_snd_ac97_controls_3d[] = { |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 734 | AC97_ENUM("Inv Input Mux", wm9713_enum[11]), |
| 735 | AC97_SINGLE("3D Upper Cut-off Switch", AC97_REC_GAIN_MIC, 5, 1, 0), |
| 736 | AC97_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC, 4, 1, 0), |
| 737 | AC97_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | }; |
| 739 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 740 | static int patch_wolfson_wm9713_3d (struct snd_ac97 * ac97) |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 741 | { |
| 742 | int err, i; |
| 743 | |
| 744 | for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_3d); i++) { |
| 745 | if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_3d[i], ac97))) < 0) |
| 746 | return err; |
| 747 | } |
| 748 | return 0; |
| 749 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 751 | static int patch_wolfson_wm9713_specific(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | { |
| 753 | int err, i; |
| 754 | |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 755 | for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls); i++) { |
| 756 | 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] | 757 | return err; |
| 758 | } |
| 759 | snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | snd_ac97_write_cache(ac97, AC97_PHONE, 0x0808); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | snd_ac97_write_cache(ac97, AC97_MIC, 0x0808); |
| 762 | snd_ac97_write_cache(ac97, AC97_LINE, 0x00da); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | snd_ac97_write_cache(ac97, AC97_CD, 0x0808); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | snd_ac97_write_cache(ac97, AC97_VIDEO, 0xd612); |
| 765 | snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x1ba0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | return 0; |
| 767 | } |
| 768 | |
| 769 | #ifdef CONFIG_PM |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 770 | static void patch_wolfson_wm9713_suspend (struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | { |
| 772 | snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xfeff); |
| 773 | snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0xffff); |
| 774 | } |
| 775 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 776 | static void patch_wolfson_wm9713_resume (struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | { |
| 778 | snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00); |
| 779 | snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810); |
| 780 | snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0); |
| 781 | } |
| 782 | #endif |
| 783 | |
| 784 | static struct snd_ac97_build_ops patch_wolfson_wm9713_ops = { |
| 785 | .build_specific = patch_wolfson_wm9713_specific, |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 786 | .build_3d = patch_wolfson_wm9713_3d, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | #ifdef CONFIG_PM |
| 788 | .suspend = patch_wolfson_wm9713_suspend, |
| 789 | .resume = patch_wolfson_wm9713_resume |
| 790 | #endif |
| 791 | }; |
| 792 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 793 | int patch_wolfson13(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | { |
Liam Girdwood | 3998b70 | 2005-07-29 11:41:55 +0200 | [diff] [blame] | 795 | /* WM9713, WM9714 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | ac97->build_ops = &patch_wolfson_wm9713_ops; |
| 797 | |
| 798 | 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] | 799 | AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD | AC97_HAS_NO_TONE | |
| 800 | AC97_HAS_NO_STD_PCM; |
Liam Girdwood | 064d211 | 2005-08-05 10:25:08 +0200 | [diff] [blame] | 801 | ac97->scaps &= ~AC97_SCAP_MODEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | |
| 803 | snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00); |
| 804 | snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810); |
| 805 | snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0); |
| 806 | |
| 807 | return 0; |
| 808 | } |
| 809 | |
| 810 | /* |
| 811 | * Tritech codec |
| 812 | */ |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 813 | int patch_tritech_tr28028(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | { |
| 815 | snd_ac97_write_cache(ac97, 0x26, 0x0300); |
| 816 | snd_ac97_write_cache(ac97, 0x26, 0x0000); |
| 817 | snd_ac97_write_cache(ac97, AC97_SURROUND_MASTER, 0x0000); |
| 818 | snd_ac97_write_cache(ac97, AC97_SPDIF, 0x0000); |
| 819 | return 0; |
| 820 | } |
| 821 | |
| 822 | /* |
| 823 | * Sigmatel STAC97xx codecs |
| 824 | */ |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 825 | static int patch_sigmatel_stac9700_3d(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 827 | struct snd_kcontrol *kctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | int err; |
| 829 | |
| 830 | if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0) |
| 831 | return err; |
| 832 | strcpy(kctl->id.name, "3D Control Sigmatel - Depth"); |
| 833 | kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0); |
| 834 | snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000); |
| 835 | return 0; |
| 836 | } |
| 837 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 838 | static int patch_sigmatel_stac9708_3d(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 840 | struct snd_kcontrol *kctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | int err; |
| 842 | |
| 843 | if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0) |
| 844 | return err; |
| 845 | strcpy(kctl->id.name, "3D Control Sigmatel - Depth"); |
| 846 | kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 0, 3, 0); |
| 847 | if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0) |
| 848 | return err; |
| 849 | strcpy(kctl->id.name, "3D Control Sigmatel - Rear Depth"); |
| 850 | kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0); |
| 851 | snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000); |
| 852 | return 0; |
| 853 | } |
| 854 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 855 | static const struct snd_kcontrol_new snd_ac97_sigmatel_4speaker = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | AC97_SINGLE("Sigmatel 4-Speaker Stereo Playback Switch", AC97_SIGMATEL_DAC2INVERT, 2, 1, 0); |
| 857 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 858 | static const struct snd_kcontrol_new snd_ac97_sigmatel_phaseinvert = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | AC97_SINGLE("Sigmatel Surround Phase Inversion Playback Switch", AC97_SIGMATEL_DAC2INVERT, 3, 1, 0); |
| 860 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 861 | static const struct snd_kcontrol_new snd_ac97_sigmatel_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | AC97_SINGLE("Sigmatel DAC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 1, 1, 0), |
| 863 | AC97_SINGLE("Sigmatel ADC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 0, 1, 0) |
| 864 | }; |
| 865 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 866 | static int patch_sigmatel_stac97xx_specific(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | { |
| 868 | int err; |
| 869 | |
| 870 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_ANALOG, snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) & ~0x0003); |
| 871 | if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 1)) |
| 872 | if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[0], 1)) < 0) |
| 873 | return err; |
| 874 | if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 0)) |
| 875 | if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[1], 1)) < 0) |
| 876 | return err; |
| 877 | if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 2)) |
| 878 | if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_4speaker, 1)) < 0) |
| 879 | return err; |
| 880 | if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 3)) |
| 881 | if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_phaseinvert, 1)) < 0) |
| 882 | return err; |
| 883 | return 0; |
| 884 | } |
| 885 | |
| 886 | static struct snd_ac97_build_ops patch_sigmatel_stac9700_ops = { |
| 887 | .build_3d = patch_sigmatel_stac9700_3d, |
| 888 | .build_specific = patch_sigmatel_stac97xx_specific |
| 889 | }; |
| 890 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 891 | int patch_sigmatel_stac9700(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | { |
| 893 | ac97->build_ops = &patch_sigmatel_stac9700_ops; |
| 894 | return 0; |
| 895 | } |
| 896 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 897 | 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] | 898 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 899 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | int err; |
| 901 | |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 902 | mutex_lock(&ac97->page_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0xabba); |
| 904 | err = snd_ac97_update_bits(ac97, AC97_SIGMATEL_BIAS2, 0x0010, |
| 905 | (ucontrol->value.integer.value[0] & 1) << 4); |
| 906 | snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0); |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 907 | mutex_unlock(&ac97->page_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | return err; |
| 909 | } |
| 910 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 911 | static const struct snd_kcontrol_new snd_ac97_stac9708_bias_control = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 913 | .name = "Sigmatel Output Bias Switch", |
| 914 | .info = snd_ac97_info_volsw, |
| 915 | .get = snd_ac97_get_volsw, |
| 916 | .put = snd_ac97_stac9708_put_bias, |
| 917 | .private_value = AC97_SINGLE_VALUE(AC97_SIGMATEL_BIAS2, 4, 1, 0), |
| 918 | }; |
| 919 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 920 | static int patch_sigmatel_stac9708_specific(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | { |
| 922 | int err; |
| 923 | |
| 924 | snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Sigmatel Surround Playback"); |
| 925 | if ((err = patch_build_controls(ac97, &snd_ac97_stac9708_bias_control, 1)) < 0) |
| 926 | return err; |
| 927 | return patch_sigmatel_stac97xx_specific(ac97); |
| 928 | } |
| 929 | |
| 930 | static struct snd_ac97_build_ops patch_sigmatel_stac9708_ops = { |
| 931 | .build_3d = patch_sigmatel_stac9708_3d, |
| 932 | .build_specific = patch_sigmatel_stac9708_specific |
| 933 | }; |
| 934 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 935 | int patch_sigmatel_stac9708(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | { |
| 937 | unsigned int codec72, codec6c; |
| 938 | |
| 939 | ac97->build_ops = &patch_sigmatel_stac9708_ops; |
| 940 | ac97->caps |= 0x10; /* HP (sigmatel surround) support */ |
| 941 | |
| 942 | codec72 = snd_ac97_read(ac97, AC97_SIGMATEL_BIAS2) & 0x8000; |
| 943 | codec6c = snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG); |
| 944 | |
| 945 | if ((codec72==0) && (codec6c==0)) { |
| 946 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); |
| 947 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1000); |
| 948 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba); |
| 949 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0007); |
| 950 | } else if ((codec72==0x8000) && (codec6c==0)) { |
| 951 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); |
| 952 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1001); |
| 953 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_DAC2INVERT, 0x0008); |
| 954 | } else if ((codec72==0x8000) && (codec6c==0x0080)) { |
| 955 | /* nothing */ |
| 956 | } |
| 957 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000); |
| 958 | return 0; |
| 959 | } |
| 960 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 961 | int patch_sigmatel_stac9721(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | { |
| 963 | ac97->build_ops = &patch_sigmatel_stac9700_ops; |
| 964 | if (snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) == 0) { |
| 965 | // patch for SigmaTel |
| 966 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); |
| 967 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x4000); |
| 968 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba); |
| 969 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002); |
| 970 | } |
| 971 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000); |
| 972 | return 0; |
| 973 | } |
| 974 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 975 | int patch_sigmatel_stac9744(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | { |
| 977 | // patch for SigmaTel |
| 978 | ac97->build_ops = &patch_sigmatel_stac9700_ops; |
| 979 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); |
| 980 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */ |
| 981 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba); |
| 982 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002); |
| 983 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000); |
| 984 | return 0; |
| 985 | } |
| 986 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 987 | int patch_sigmatel_stac9756(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | { |
| 989 | // patch for SigmaTel |
| 990 | ac97->build_ops = &patch_sigmatel_stac9700_ops; |
| 991 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); |
| 992 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */ |
| 993 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba); |
| 994 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002); |
| 995 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000); |
| 996 | return 0; |
| 997 | } |
| 998 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 999 | 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] | 1000 | { |
| 1001 | static char *texts[5] = { "Input/Disabled", "Front Output", |
| 1002 | "Rear Output", "Center/LFE Output", "Mixer Output" }; |
| 1003 | |
| 1004 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 1005 | uinfo->count = 1; |
| 1006 | uinfo->value.enumerated.items = 5; |
| 1007 | if (uinfo->value.enumerated.item > 4) |
| 1008 | uinfo->value.enumerated.item = 4; |
| 1009 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); |
| 1010 | return 0; |
| 1011 | } |
| 1012 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1013 | 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] | 1014 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1015 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | int shift = kcontrol->private_value; |
| 1017 | unsigned short val; |
| 1018 | |
| 1019 | val = ac97->regs[AC97_SIGMATEL_OUTSEL] >> shift; |
| 1020 | if (!(val & 4)) |
| 1021 | ucontrol->value.enumerated.item[0] = 0; |
| 1022 | else |
| 1023 | ucontrol->value.enumerated.item[0] = 1 + (val & 3); |
| 1024 | return 0; |
| 1025 | } |
| 1026 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1027 | 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] | 1028 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1029 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | int shift = kcontrol->private_value; |
| 1031 | unsigned short val; |
| 1032 | |
| 1033 | if (ucontrol->value.enumerated.item[0] > 4) |
| 1034 | return -EINVAL; |
| 1035 | if (ucontrol->value.enumerated.item[0] == 0) |
| 1036 | val = 0; |
| 1037 | else |
| 1038 | val = 4 | (ucontrol->value.enumerated.item[0] - 1); |
| 1039 | return ac97_update_bits_page(ac97, AC97_SIGMATEL_OUTSEL, |
| 1040 | 7 << shift, val << shift, 0); |
| 1041 | } |
| 1042 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1043 | 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] | 1044 | { |
| 1045 | static char *texts[7] = { "Mic2 Jack", "Mic1 Jack", "Line In Jack", |
| 1046 | "Front Jack", "Rear Jack", "Center/LFE Jack", "Mute" }; |
| 1047 | |
| 1048 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 1049 | uinfo->count = 1; |
| 1050 | uinfo->value.enumerated.items = 7; |
| 1051 | if (uinfo->value.enumerated.item > 6) |
| 1052 | uinfo->value.enumerated.item = 6; |
| 1053 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); |
| 1054 | return 0; |
| 1055 | } |
| 1056 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1057 | 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] | 1058 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1059 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | int shift = kcontrol->private_value; |
| 1061 | unsigned short val; |
| 1062 | |
| 1063 | val = ac97->regs[AC97_SIGMATEL_INSEL]; |
| 1064 | ucontrol->value.enumerated.item[0] = (val >> shift) & 7; |
| 1065 | return 0; |
| 1066 | } |
| 1067 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1068 | 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] | 1069 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1070 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | int shift = kcontrol->private_value; |
| 1072 | |
| 1073 | return ac97_update_bits_page(ac97, AC97_SIGMATEL_INSEL, 7 << shift, |
| 1074 | ucontrol->value.enumerated.item[0] << shift, 0); |
| 1075 | } |
| 1076 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1077 | 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] | 1078 | { |
| 1079 | static char *texts[3] = { "None", "Front Jack", "Rear Jack" }; |
| 1080 | |
| 1081 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 1082 | uinfo->count = 1; |
| 1083 | uinfo->value.enumerated.items = 3; |
| 1084 | if (uinfo->value.enumerated.item > 2) |
| 1085 | uinfo->value.enumerated.item = 2; |
| 1086 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); |
| 1087 | return 0; |
| 1088 | } |
| 1089 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1090 | 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] | 1091 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1092 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | |
| 1094 | ucontrol->value.enumerated.item[0] = ac97->regs[AC97_SIGMATEL_IOMISC] & 3; |
| 1095 | return 0; |
| 1096 | } |
| 1097 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1098 | 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] | 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 | |
| 1102 | return ac97_update_bits_page(ac97, AC97_SIGMATEL_IOMISC, 3, |
| 1103 | ucontrol->value.enumerated.item[0], 0); |
| 1104 | } |
| 1105 | |
| 1106 | #define STAC9758_OUTPUT_JACK(xname, shift) \ |
| 1107 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ |
| 1108 | .info = snd_ac97_stac9758_output_jack_info, \ |
| 1109 | .get = snd_ac97_stac9758_output_jack_get, \ |
| 1110 | .put = snd_ac97_stac9758_output_jack_put, \ |
| 1111 | .private_value = shift } |
| 1112 | #define STAC9758_INPUT_JACK(xname, shift) \ |
| 1113 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ |
| 1114 | .info = snd_ac97_stac9758_input_jack_info, \ |
| 1115 | .get = snd_ac97_stac9758_input_jack_get, \ |
| 1116 | .put = snd_ac97_stac9758_input_jack_put, \ |
| 1117 | .private_value = shift } |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1118 | static const struct snd_kcontrol_new snd_ac97_sigmatel_stac9758_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | STAC9758_OUTPUT_JACK("Mic1 Jack", 1), |
| 1120 | STAC9758_OUTPUT_JACK("LineIn Jack", 4), |
| 1121 | STAC9758_OUTPUT_JACK("Front Jack", 7), |
| 1122 | STAC9758_OUTPUT_JACK("Rear Jack", 10), |
| 1123 | STAC9758_OUTPUT_JACK("Center/LFE Jack", 13), |
| 1124 | STAC9758_INPUT_JACK("Mic Input Source", 0), |
| 1125 | STAC9758_INPUT_JACK("Line Input Source", 8), |
| 1126 | { |
| 1127 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1128 | .name = "Headphone Amp", |
| 1129 | .info = snd_ac97_stac9758_phonesel_info, |
| 1130 | .get = snd_ac97_stac9758_phonesel_get, |
| 1131 | .put = snd_ac97_stac9758_phonesel_put |
| 1132 | }, |
| 1133 | AC97_SINGLE("Exchange Center/LFE", AC97_SIGMATEL_IOMISC, 4, 1, 0), |
| 1134 | AC97_SINGLE("Headphone +3dB Boost", AC97_SIGMATEL_IOMISC, 8, 1, 0) |
| 1135 | }; |
| 1136 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1137 | static int patch_sigmatel_stac9758_specific(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | { |
| 1139 | int err; |
| 1140 | |
| 1141 | err = patch_sigmatel_stac97xx_specific(ac97); |
| 1142 | if (err < 0) |
| 1143 | return err; |
| 1144 | err = patch_build_controls(ac97, snd_ac97_sigmatel_stac9758_controls, |
| 1145 | ARRAY_SIZE(snd_ac97_sigmatel_stac9758_controls)); |
| 1146 | if (err < 0) |
| 1147 | return err; |
| 1148 | /* DAC-A direct */ |
| 1149 | snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Front Playback"); |
| 1150 | /* DAC-A to Mix = PCM */ |
| 1151 | /* DAC-B direct = Surround */ |
| 1152 | /* DAC-B to Mix */ |
| 1153 | snd_ac97_rename_vol_ctl(ac97, "Video Playback", "Surround Mix Playback"); |
| 1154 | /* DAC-C direct = Center/LFE */ |
| 1155 | |
| 1156 | return 0; |
| 1157 | } |
| 1158 | |
| 1159 | static struct snd_ac97_build_ops patch_sigmatel_stac9758_ops = { |
| 1160 | .build_3d = patch_sigmatel_stac9700_3d, |
| 1161 | .build_specific = patch_sigmatel_stac9758_specific |
| 1162 | }; |
| 1163 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1164 | int patch_sigmatel_stac9758(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | { |
| 1166 | static unsigned short regs[4] = { |
| 1167 | AC97_SIGMATEL_OUTSEL, |
| 1168 | AC97_SIGMATEL_IOMISC, |
| 1169 | AC97_SIGMATEL_INSEL, |
| 1170 | AC97_SIGMATEL_VARIOUS |
| 1171 | }; |
| 1172 | static unsigned short def_regs[4] = { |
| 1173 | /* OUTSEL */ 0xd794, /* CL:CL, SR:SR, LO:MX, LI:DS, MI:DS */ |
| 1174 | /* IOMISC */ 0x2001, |
| 1175 | /* INSEL */ 0x0201, /* LI:LI, MI:M1 */ |
| 1176 | /* VARIOUS */ 0x0040 |
| 1177 | }; |
| 1178 | static unsigned short m675_regs[4] = { |
| 1179 | /* OUTSEL */ 0xfc70, /* CL:MX, SR:MX, LO:DS, LI:MX, MI:DS */ |
| 1180 | /* IOMISC */ 0x2102, /* HP amp on */ |
| 1181 | /* INSEL */ 0x0203, /* LI:LI, MI:FR */ |
| 1182 | /* VARIOUS */ 0x0041 /* stereo mic */ |
| 1183 | }; |
| 1184 | unsigned short *pregs = def_regs; |
| 1185 | int i; |
| 1186 | |
| 1187 | /* Gateway M675 notebook */ |
| 1188 | if (ac97->pci && |
| 1189 | ac97->subsystem_vendor == 0x107b && |
| 1190 | ac97->subsystem_device == 0x0601) |
| 1191 | pregs = m675_regs; |
| 1192 | |
| 1193 | // patch for SigmaTel |
| 1194 | ac97->build_ops = &patch_sigmatel_stac9758_ops; |
| 1195 | /* FIXME: assume only page 0 for writing cache */ |
| 1196 | snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR); |
| 1197 | for (i = 0; i < 4; i++) |
| 1198 | snd_ac97_write_cache(ac97, regs[i], pregs[i]); |
| 1199 | |
| 1200 | ac97->flags |= AC97_STEREO_MUTES; |
| 1201 | return 0; |
| 1202 | } |
| 1203 | |
| 1204 | /* |
| 1205 | * Cirrus Logic CS42xx codecs |
| 1206 | */ |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1207 | static const struct snd_kcontrol_new snd_ac97_cirrus_controls_spdif[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CSR_SPDIF, 15, 1, 0), |
| 1209 | AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "AC97-SPSA", AC97_CSR_ACMODE, 0, 3, 0) |
| 1210 | }; |
| 1211 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1212 | static int patch_cirrus_build_spdif(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | { |
| 1214 | int err; |
| 1215 | |
| 1216 | /* con mask, pro mask, default */ |
| 1217 | if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0) |
| 1218 | return err; |
| 1219 | /* switch, spsa */ |
| 1220 | if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[0], 1)) < 0) |
| 1221 | return err; |
| 1222 | switch (ac97->id & AC97_ID_CS_MASK) { |
| 1223 | case AC97_ID_CS4205: |
| 1224 | if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[1], 1)) < 0) |
| 1225 | return err; |
| 1226 | break; |
| 1227 | } |
| 1228 | /* set default PCM S/PDIF params */ |
| 1229 | /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */ |
| 1230 | snd_ac97_write_cache(ac97, AC97_CSR_SPDIF, 0x0a20); |
| 1231 | return 0; |
| 1232 | } |
| 1233 | |
| 1234 | static struct snd_ac97_build_ops patch_cirrus_ops = { |
| 1235 | .build_spdif = patch_cirrus_build_spdif |
| 1236 | }; |
| 1237 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1238 | int patch_cirrus_spdif(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | { |
| 1240 | /* Basically, the cs4201/cs4205/cs4297a has non-standard sp/dif registers. |
| 1241 | WHY CAN'T ANYONE FOLLOW THE BLOODY SPEC? *sigh* |
| 1242 | - sp/dif EA ID is not set, but sp/dif is always present. |
| 1243 | - enable/disable is spdif register bit 15. |
| 1244 | - sp/dif control register is 0x68. differs from AC97: |
| 1245 | - valid is bit 14 (vs 15) |
| 1246 | - no DRS |
| 1247 | - only 44.1/48k [00 = 48, 01=44,1] (AC97 is 00=44.1, 10=48) |
| 1248 | - sp/dif ssource select is in 0x5e bits 0,1. |
| 1249 | */ |
| 1250 | |
| 1251 | ac97->build_ops = &patch_cirrus_ops; |
| 1252 | ac97->flags |= AC97_CS_SPDIF; |
| 1253 | ac97->rates[AC97_RATES_SPDIF] &= ~SNDRV_PCM_RATE_32000; |
| 1254 | ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */ |
| 1255 | snd_ac97_write_cache(ac97, AC97_CSR_ACMODE, 0x0080); |
| 1256 | return 0; |
| 1257 | } |
| 1258 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1259 | int patch_cirrus_cs4299(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | { |
| 1261 | /* force the detection of PC Beep */ |
| 1262 | ac97->flags |= AC97_HAS_PC_BEEP; |
| 1263 | |
| 1264 | return patch_cirrus_spdif(ac97); |
| 1265 | } |
| 1266 | |
| 1267 | /* |
| 1268 | * Conexant codecs |
| 1269 | */ |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1270 | static const struct snd_kcontrol_new snd_ac97_conexant_controls_spdif[1] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CXR_AUDIO_MISC, 3, 1, 0), |
| 1272 | }; |
| 1273 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1274 | static int patch_conexant_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 */ |
| 1282 | if ((err = patch_build_controls(ac97, &snd_ac97_conexant_controls_spdif[0], 1)) < 0) |
| 1283 | return err; |
| 1284 | /* set default PCM S/PDIF params */ |
| 1285 | /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */ |
| 1286 | snd_ac97_write_cache(ac97, AC97_CXR_AUDIO_MISC, |
| 1287 | snd_ac97_read(ac97, AC97_CXR_AUDIO_MISC) & ~(AC97_CXR_SPDIFEN|AC97_CXR_COPYRGT|AC97_CXR_SPDIF_MASK)); |
| 1288 | return 0; |
| 1289 | } |
| 1290 | |
| 1291 | static struct snd_ac97_build_ops patch_conexant_ops = { |
| 1292 | .build_spdif = patch_conexant_build_spdif |
| 1293 | }; |
| 1294 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1295 | int patch_conexant(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | { |
| 1297 | ac97->build_ops = &patch_conexant_ops; |
| 1298 | ac97->flags |= AC97_CX_SPDIF; |
| 1299 | ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */ |
| 1300 | ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */ |
| 1301 | return 0; |
| 1302 | } |
| 1303 | |
| 1304 | /* |
| 1305 | * Analog Device AD18xx, AD19xx codecs |
| 1306 | */ |
| 1307 | #ifdef CONFIG_PM |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1308 | static void ad18xx_resume(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | { |
| 1310 | static unsigned short setup_regs[] = { |
| 1311 | AC97_AD_MISC, AC97_AD_SERIAL_CFG, AC97_AD_JACK_SPDIF, |
| 1312 | }; |
| 1313 | int i, codec; |
| 1314 | |
| 1315 | for (i = 0; i < (int)ARRAY_SIZE(setup_regs); i++) { |
| 1316 | unsigned short reg = setup_regs[i]; |
| 1317 | if (test_bit(reg, ac97->reg_accessed)) { |
| 1318 | snd_ac97_write(ac97, reg, ac97->regs[reg]); |
| 1319 | snd_ac97_read(ac97, reg); |
| 1320 | } |
| 1321 | } |
| 1322 | |
| 1323 | if (! (ac97->flags & AC97_AD_MULTI)) |
| 1324 | /* normal restore */ |
| 1325 | snd_ac97_restore_status(ac97); |
| 1326 | else { |
| 1327 | /* restore the AD18xx codec configurations */ |
| 1328 | for (codec = 0; codec < 3; codec++) { |
| 1329 | if (! ac97->spec.ad18xx.id[codec]) |
| 1330 | continue; |
| 1331 | /* select single codec */ |
| 1332 | snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, |
| 1333 | ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]); |
| 1334 | ac97->bus->ops->write(ac97, AC97_AD_CODEC_CFG, ac97->spec.ad18xx.codec_cfg[codec]); |
| 1335 | } |
| 1336 | /* select all codecs */ |
| 1337 | snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000); |
| 1338 | |
| 1339 | /* restore status */ |
| 1340 | for (i = 2; i < 0x7c ; i += 2) { |
| 1341 | if (i == AC97_POWERDOWN || i == AC97_EXTENDED_ID) |
| 1342 | continue; |
| 1343 | if (test_bit(i, ac97->reg_accessed)) { |
| 1344 | /* handle multi codecs for AD18xx */ |
| 1345 | if (i == AC97_PCM) { |
| 1346 | for (codec = 0; codec < 3; codec++) { |
| 1347 | if (! ac97->spec.ad18xx.id[codec]) |
| 1348 | continue; |
| 1349 | /* select single codec */ |
| 1350 | snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, |
| 1351 | ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]); |
| 1352 | /* update PCM bits */ |
| 1353 | ac97->bus->ops->write(ac97, AC97_PCM, ac97->spec.ad18xx.pcmreg[codec]); |
| 1354 | } |
| 1355 | /* select all codecs */ |
| 1356 | snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000); |
| 1357 | continue; |
| 1358 | } else if (i == AC97_AD_TEST || |
| 1359 | i == AC97_AD_CODEC_CFG || |
| 1360 | i == AC97_AD_SERIAL_CFG) |
| 1361 | continue; /* ignore */ |
| 1362 | } |
| 1363 | snd_ac97_write(ac97, i, ac97->regs[i]); |
| 1364 | snd_ac97_read(ac97, i); |
| 1365 | } |
| 1366 | } |
| 1367 | |
| 1368 | snd_ac97_restore_iec958(ac97); |
| 1369 | } |
| 1370 | #endif |
| 1371 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1372 | int patch_ad1819(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | { |
| 1374 | unsigned short scfg; |
| 1375 | |
| 1376 | // patch for Analog Devices |
| 1377 | scfg = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG); |
| 1378 | snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, scfg | 0x7000); /* select all codecs */ |
| 1379 | return 0; |
| 1380 | } |
| 1381 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1382 | 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] | 1383 | { |
| 1384 | unsigned short val; |
| 1385 | |
| 1386 | // test for unchained codec |
| 1387 | snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, mask); |
| 1388 | snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000); /* ID0C, ID1C, SDIE = off */ |
| 1389 | val = snd_ac97_read(ac97, AC97_VENDOR_ID2); |
| 1390 | if ((val & 0xff40) != 0x5340) |
| 1391 | return 0; |
| 1392 | ac97->spec.ad18xx.unchained[idx] = mask; |
| 1393 | ac97->spec.ad18xx.id[idx] = val; |
| 1394 | ac97->spec.ad18xx.codec_cfg[idx] = 0x0000; |
| 1395 | return mask; |
| 1396 | } |
| 1397 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1398 | 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] | 1399 | { |
| 1400 | static int cfg_bits[3] = { 1<<12, 1<<14, 1<<13 }; |
| 1401 | unsigned short val; |
| 1402 | |
| 1403 | snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, cfg_bits[idx]); |
| 1404 | snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0004); // SDIE |
| 1405 | val = snd_ac97_read(ac97, AC97_VENDOR_ID2); |
| 1406 | if ((val & 0xff40) != 0x5340) |
| 1407 | return 0; |
| 1408 | if (codec_bits) |
| 1409 | snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, codec_bits); |
| 1410 | ac97->spec.ad18xx.chained[idx] = cfg_bits[idx]; |
| 1411 | ac97->spec.ad18xx.id[idx] = val; |
| 1412 | ac97->spec.ad18xx.codec_cfg[idx] = codec_bits ? codec_bits : 0x0004; |
| 1413 | return 1; |
| 1414 | } |
| 1415 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1416 | 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] | 1417 | { |
| 1418 | // already detected? |
| 1419 | if (ac97->spec.ad18xx.unchained[cidx1] || ac97->spec.ad18xx.chained[cidx1]) |
| 1420 | cidx1 = -1; |
| 1421 | if (ac97->spec.ad18xx.unchained[cidx2] || ac97->spec.ad18xx.chained[cidx2]) |
| 1422 | cidx2 = -1; |
| 1423 | if (cidx1 < 0 && cidx2 < 0) |
| 1424 | return; |
| 1425 | // test for chained codecs |
| 1426 | snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, |
| 1427 | ac97->spec.ad18xx.unchained[unchained_idx]); |
| 1428 | snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0002); // ID1C |
| 1429 | ac97->spec.ad18xx.codec_cfg[unchained_idx] = 0x0002; |
| 1430 | if (cidx1 >= 0) { |
| 1431 | if (patch_ad1881_chained1(ac97, cidx1, 0x0006)) // SDIE | ID1C |
| 1432 | patch_ad1881_chained1(ac97, cidx2, 0); |
| 1433 | else if (patch_ad1881_chained1(ac97, cidx2, 0x0006)) // SDIE | ID1C |
| 1434 | patch_ad1881_chained1(ac97, cidx1, 0); |
| 1435 | } else if (cidx2 >= 0) { |
| 1436 | patch_ad1881_chained1(ac97, cidx2, 0); |
| 1437 | } |
| 1438 | } |
| 1439 | |
| 1440 | static struct snd_ac97_build_ops patch_ad1881_build_ops = { |
| 1441 | #ifdef CONFIG_PM |
| 1442 | .resume = ad18xx_resume |
| 1443 | #endif |
| 1444 | }; |
| 1445 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1446 | int patch_ad1881(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | { |
| 1448 | static const char cfg_idxs[3][2] = { |
| 1449 | {2, 1}, |
| 1450 | {0, 2}, |
| 1451 | {0, 1} |
| 1452 | }; |
| 1453 | |
| 1454 | // patch for Analog Devices |
| 1455 | unsigned short codecs[3]; |
| 1456 | unsigned short val; |
| 1457 | int idx, num; |
| 1458 | |
| 1459 | val = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG); |
| 1460 | snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, val); |
| 1461 | codecs[0] = patch_ad1881_unchained(ac97, 0, (1<<12)); |
| 1462 | codecs[1] = patch_ad1881_unchained(ac97, 1, (1<<14)); |
| 1463 | codecs[2] = patch_ad1881_unchained(ac97, 2, (1<<13)); |
| 1464 | |
Takashi Iwai | 7c22f1a | 2005-10-10 11:46:31 +0200 | [diff] [blame] | 1465 | if (! (codecs[0] || codecs[1] || codecs[2])) |
| 1466 | goto __end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | |
| 1468 | for (idx = 0; idx < 3; idx++) |
| 1469 | if (ac97->spec.ad18xx.unchained[idx]) |
| 1470 | patch_ad1881_chained(ac97, idx, cfg_idxs[idx][0], cfg_idxs[idx][1]); |
| 1471 | |
| 1472 | if (ac97->spec.ad18xx.id[1]) { |
| 1473 | ac97->flags |= AC97_AD_MULTI; |
| 1474 | ac97->scaps |= AC97_SCAP_SURROUND_DAC; |
| 1475 | } |
| 1476 | if (ac97->spec.ad18xx.id[2]) { |
| 1477 | ac97->flags |= AC97_AD_MULTI; |
| 1478 | ac97->scaps |= AC97_SCAP_CENTER_LFE_DAC; |
| 1479 | } |
| 1480 | |
| 1481 | __end: |
| 1482 | /* select all codecs */ |
| 1483 | snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000); |
| 1484 | /* check if only one codec is present */ |
| 1485 | for (idx = num = 0; idx < 3; idx++) |
| 1486 | if (ac97->spec.ad18xx.id[idx]) |
| 1487 | num++; |
| 1488 | if (num == 1) { |
| 1489 | /* ok, deselect all ID bits */ |
| 1490 | snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000); |
| 1491 | ac97->spec.ad18xx.codec_cfg[0] = |
| 1492 | ac97->spec.ad18xx.codec_cfg[1] = |
| 1493 | ac97->spec.ad18xx.codec_cfg[2] = 0x0000; |
| 1494 | } |
| 1495 | /* required for AD1886/AD1885 combination */ |
| 1496 | ac97->ext_id = snd_ac97_read(ac97, AC97_EXTENDED_ID); |
| 1497 | if (ac97->spec.ad18xx.id[0]) { |
| 1498 | ac97->id &= 0xffff0000; |
| 1499 | ac97->id |= ac97->spec.ad18xx.id[0]; |
| 1500 | } |
| 1501 | ac97->build_ops = &patch_ad1881_build_ops; |
| 1502 | return 0; |
| 1503 | } |
| 1504 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1505 | static const struct snd_kcontrol_new snd_ac97_controls_ad1885[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1506 | AC97_SINGLE("Digital Mono Direct", AC97_AD_MISC, 11, 1, 0), |
| 1507 | /* AC97_SINGLE("Digital Audio Mode", AC97_AD_MISC, 12, 1, 0), */ /* seems problematic */ |
| 1508 | AC97_SINGLE("Low Power Mixer", AC97_AD_MISC, 14, 1, 0), |
| 1509 | AC97_SINGLE("Zero Fill DAC", AC97_AD_MISC, 15, 1, 0), |
| 1510 | AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 9, 1, 1), /* inverted */ |
| 1511 | AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 8, 1, 1), /* inverted */ |
| 1512 | }; |
| 1513 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1514 | static int patch_ad1885_specific(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1515 | { |
| 1516 | int err; |
| 1517 | |
| 1518 | if ((err = patch_build_controls(ac97, snd_ac97_controls_ad1885, ARRAY_SIZE(snd_ac97_controls_ad1885))) < 0) |
| 1519 | return err; |
| 1520 | return 0; |
| 1521 | } |
| 1522 | |
| 1523 | static struct snd_ac97_build_ops patch_ad1885_build_ops = { |
| 1524 | .build_specific = &patch_ad1885_specific, |
| 1525 | #ifdef CONFIG_PM |
| 1526 | .resume = ad18xx_resume |
| 1527 | #endif |
| 1528 | }; |
| 1529 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1530 | int patch_ad1885(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1531 | { |
| 1532 | patch_ad1881(ac97); |
| 1533 | /* This is required to deal with the Intel D815EEAL2 */ |
| 1534 | /* i.e. Line out is actually headphone out from codec */ |
| 1535 | |
| 1536 | /* set default */ |
| 1537 | snd_ac97_write_cache(ac97, AC97_AD_MISC, 0x0404); |
| 1538 | |
| 1539 | ac97->build_ops = &patch_ad1885_build_ops; |
| 1540 | return 0; |
| 1541 | } |
| 1542 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1543 | int patch_ad1886(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | { |
| 1545 | patch_ad1881(ac97); |
| 1546 | /* Presario700 workaround */ |
| 1547 | /* for Jack Sense/SPDIF Register misetting causing */ |
| 1548 | snd_ac97_write_cache(ac97, AC97_AD_JACK_SPDIF, 0x0010); |
| 1549 | return 0; |
| 1550 | } |
| 1551 | |
| 1552 | /* MISC bits */ |
| 1553 | #define AC97_AD198X_MBC 0x0003 /* mic boost */ |
| 1554 | #define AC97_AD198X_MBC_20 0x0000 /* +20dB */ |
| 1555 | #define AC97_AD198X_MBC_10 0x0001 /* +10dB */ |
| 1556 | #define AC97_AD198X_MBC_30 0x0002 /* +30dB */ |
| 1557 | #define AC97_AD198X_VREFD 0x0004 /* VREF high-Z */ |
| 1558 | #define AC97_AD198X_VREFH 0x0008 /* 2.25V, 3.7V */ |
| 1559 | #define AC97_AD198X_VREF_0 0x000c /* 0V */ |
| 1560 | #define AC97_AD198X_SRU 0x0010 /* sample rate unlock */ |
| 1561 | #define AC97_AD198X_LOSEL 0x0020 /* LINE_OUT amplifiers input select */ |
| 1562 | #define AC97_AD198X_2MIC 0x0040 /* 2-channel mic select */ |
| 1563 | #define AC97_AD198X_SPRD 0x0080 /* SPREAD enable */ |
| 1564 | #define AC97_AD198X_DMIX0 0x0100 /* downmix mode: 0 = 6-to-4, 1 = 6-to-2 downmix */ |
| 1565 | #define AC97_AD198X_DMIX1 0x0200 /* downmix mode: 1 = enabled */ |
| 1566 | #define AC97_AD198X_HPSEL 0x0400 /* headphone amplifier input select */ |
| 1567 | #define AC97_AD198X_CLDIS 0x0800 /* center/lfe disable */ |
| 1568 | #define AC97_AD198X_LODIS 0x1000 /* LINE_OUT disable */ |
| 1569 | #define AC97_AD198X_MSPLT 0x2000 /* mute split */ |
| 1570 | #define AC97_AD198X_AC97NC 0x4000 /* AC97 no compatible mode */ |
| 1571 | #define AC97_AD198X_DACZ 0x8000 /* DAC zero-fill mode */ |
| 1572 | |
| 1573 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1574 | 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] | 1575 | { |
| 1576 | static char *texts[2] = { "AC-Link", "A/D Converter" }; |
| 1577 | |
| 1578 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 1579 | uinfo->count = 1; |
| 1580 | uinfo->value.enumerated.items = 2; |
| 1581 | if (uinfo->value.enumerated.item > 1) |
| 1582 | uinfo->value.enumerated.item = 1; |
| 1583 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); |
| 1584 | return 0; |
| 1585 | } |
| 1586 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1587 | 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] | 1588 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1589 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1590 | unsigned short val; |
| 1591 | |
| 1592 | val = ac97->regs[AC97_AD_SERIAL_CFG]; |
| 1593 | ucontrol->value.enumerated.item[0] = (val >> 2) & 1; |
| 1594 | return 0; |
| 1595 | } |
| 1596 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1597 | 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] | 1598 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1599 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1600 | unsigned short val; |
| 1601 | |
| 1602 | if (ucontrol->value.enumerated.item[0] > 1) |
| 1603 | return -EINVAL; |
| 1604 | val = ucontrol->value.enumerated.item[0] << 2; |
| 1605 | return snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x0004, val); |
| 1606 | } |
| 1607 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1608 | static const struct snd_kcontrol_new snd_ac97_ad198x_spdif_source = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1610 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source", |
| 1611 | .info = snd_ac97_ad198x_spdif_source_info, |
| 1612 | .get = snd_ac97_ad198x_spdif_source_get, |
| 1613 | .put = snd_ac97_ad198x_spdif_source_put, |
| 1614 | }; |
| 1615 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1616 | static int patch_ad198x_post_spdif(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1617 | { |
| 1618 | return patch_build_controls(ac97, &snd_ac97_ad198x_spdif_source, 1); |
| 1619 | } |
| 1620 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1621 | static const struct snd_kcontrol_new snd_ac97_ad1981x_jack_sense[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1622 | AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 11, 1, 0), |
| 1623 | AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0), |
| 1624 | }; |
| 1625 | |
Takashi Iwai | 128a46a | 2006-01-11 18:15:43 +0100 | [diff] [blame] | 1626 | /* black list to avoid HP/Line jack-sense controls |
| 1627 | * (SS vendor << 16 | device) |
| 1628 | */ |
| 1629 | static unsigned int ad1981_jacks_blacklist[] = { |
| 1630 | 0x10140554, /* Thinkpad T42p/R50p */ |
| 1631 | 0 /* end */ |
| 1632 | }; |
| 1633 | |
| 1634 | static int check_list(struct snd_ac97 *ac97, const unsigned int *list) |
| 1635 | { |
| 1636 | u32 subid = ((u32)ac97->subsystem_vendor << 16) | ac97->subsystem_device; |
| 1637 | for (; *list; list++) |
| 1638 | if (*list == subid) |
| 1639 | return 1; |
| 1640 | return 0; |
| 1641 | } |
| 1642 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1643 | static int patch_ad1981a_specific(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1644 | { |
Takashi Iwai | 128a46a | 2006-01-11 18:15:43 +0100 | [diff] [blame] | 1645 | if (check_list(ac97, ad1981_jacks_blacklist)) |
| 1646 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense, |
| 1648 | ARRAY_SIZE(snd_ac97_ad1981x_jack_sense)); |
| 1649 | } |
| 1650 | |
| 1651 | static struct snd_ac97_build_ops patch_ad1981a_build_ops = { |
| 1652 | .build_post_spdif = patch_ad198x_post_spdif, |
| 1653 | .build_specific = patch_ad1981a_specific, |
| 1654 | #ifdef CONFIG_PM |
| 1655 | .resume = ad18xx_resume |
| 1656 | #endif |
| 1657 | }; |
| 1658 | |
Takashi Iwai | 128a46a | 2006-01-11 18:15:43 +0100 | [diff] [blame] | 1659 | /* white list to enable HP jack-sense bits |
| 1660 | * (SS vendor << 16 | device) |
| 1661 | */ |
| 1662 | static unsigned int ad1981_jacks_whitelist[] = { |
| 1663 | 0x0e11005a, /* HP nc4000/4010 */ |
| 1664 | 0x103c0890, /* HP nc6000 */ |
| 1665 | 0x103c0938, /* HP nc4220 */ |
| 1666 | 0x103c099c, /* HP nx6110 */ |
| 1667 | 0x103c0944, /* HP nc6220 */ |
| 1668 | 0x103c0934, /* HP nc8220 */ |
| 1669 | 0x103c006d, /* HP nx9105 */ |
| 1670 | 0x17340088, /* FSC Scenic-W */ |
| 1671 | 0 /* end */ |
| 1672 | }; |
| 1673 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1674 | static void check_ad1981_hp_jack_sense(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | { |
Takashi Iwai | 128a46a | 2006-01-11 18:15:43 +0100 | [diff] [blame] | 1676 | if (check_list(ac97, ad1981_jacks_whitelist)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1677 | /* enable headphone jack sense */ |
| 1678 | 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] | 1679 | } |
| 1680 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1681 | int patch_ad1981a(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1682 | { |
| 1683 | patch_ad1881(ac97); |
| 1684 | ac97->build_ops = &patch_ad1981a_build_ops; |
| 1685 | snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT); |
| 1686 | ac97->flags |= AC97_STEREO_MUTES; |
| 1687 | check_ad1981_hp_jack_sense(ac97); |
| 1688 | return 0; |
| 1689 | } |
| 1690 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1691 | static const struct snd_kcontrol_new snd_ac97_ad198x_2cmic = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1692 | AC97_SINGLE("Stereo Mic", AC97_AD_MISC, 6, 1, 0); |
| 1693 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1694 | static int patch_ad1981b_specific(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1695 | { |
| 1696 | int err; |
| 1697 | |
| 1698 | if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0) |
| 1699 | return err; |
Takashi Iwai | 128a46a | 2006-01-11 18:15:43 +0100 | [diff] [blame] | 1700 | if (check_list(ac97, ad1981_jacks_blacklist)) |
| 1701 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1702 | return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense, |
| 1703 | ARRAY_SIZE(snd_ac97_ad1981x_jack_sense)); |
| 1704 | } |
| 1705 | |
| 1706 | static struct snd_ac97_build_ops patch_ad1981b_build_ops = { |
| 1707 | .build_post_spdif = patch_ad198x_post_spdif, |
| 1708 | .build_specific = patch_ad1981b_specific, |
| 1709 | #ifdef CONFIG_PM |
| 1710 | .resume = ad18xx_resume |
| 1711 | #endif |
| 1712 | }; |
| 1713 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1714 | int patch_ad1981b(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | { |
| 1716 | patch_ad1881(ac97); |
| 1717 | ac97->build_ops = &patch_ad1981b_build_ops; |
| 1718 | snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT); |
| 1719 | ac97->flags |= AC97_STEREO_MUTES; |
| 1720 | check_ad1981_hp_jack_sense(ac97); |
| 1721 | return 0; |
| 1722 | } |
| 1723 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1724 | static int snd_ac97_ad1888_lohpsel_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1725 | { |
| 1726 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 1727 | uinfo->count = 1; |
| 1728 | uinfo->value.integer.min = 0; |
| 1729 | uinfo->value.integer.max = 1; |
| 1730 | return 0; |
| 1731 | } |
| 1732 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1733 | 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] | 1734 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1735 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 | unsigned short val; |
| 1737 | |
| 1738 | val = ac97->regs[AC97_AD_MISC]; |
| 1739 | ucontrol->value.integer.value[0] = !(val & AC97_AD198X_LOSEL); |
| 1740 | return 0; |
| 1741 | } |
| 1742 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1743 | 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] | 1744 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1745 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1746 | unsigned short val; |
| 1747 | |
| 1748 | val = !ucontrol->value.integer.value[0] |
| 1749 | ? (AC97_AD198X_LOSEL | AC97_AD198X_HPSEL) : 0; |
| 1750 | return snd_ac97_update_bits(ac97, AC97_AD_MISC, |
| 1751 | AC97_AD198X_LOSEL | AC97_AD198X_HPSEL, val); |
| 1752 | } |
| 1753 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1754 | 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] | 1755 | { |
| 1756 | static char *texts[3] = {"Off", "6 -> 4", "6 -> 2"}; |
| 1757 | |
| 1758 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 1759 | uinfo->count = 1; |
| 1760 | uinfo->value.enumerated.items = 3; |
| 1761 | if (uinfo->value.enumerated.item > 2) |
| 1762 | uinfo->value.enumerated.item = 2; |
| 1763 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); |
| 1764 | return 0; |
| 1765 | } |
| 1766 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1767 | 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] | 1768 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1769 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | unsigned short val; |
| 1771 | |
| 1772 | val = ac97->regs[AC97_AD_MISC]; |
| 1773 | if (!(val & AC97_AD198X_DMIX1)) |
| 1774 | ucontrol->value.enumerated.item[0] = 0; |
| 1775 | else |
| 1776 | ucontrol->value.enumerated.item[0] = 1 + ((val >> 8) & 1); |
| 1777 | return 0; |
| 1778 | } |
| 1779 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1780 | 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] | 1781 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1782 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1783 | unsigned short val; |
| 1784 | |
| 1785 | if (ucontrol->value.enumerated.item[0] > 2) |
| 1786 | return -EINVAL; |
| 1787 | if (ucontrol->value.enumerated.item[0] == 0) |
| 1788 | val = 0; |
| 1789 | else |
| 1790 | val = AC97_AD198X_DMIX1 | |
| 1791 | ((ucontrol->value.enumerated.item[0] - 1) << 8); |
| 1792 | return snd_ac97_update_bits(ac97, AC97_AD_MISC, |
| 1793 | AC97_AD198X_DMIX0 | AC97_AD198X_DMIX1, val); |
| 1794 | } |
| 1795 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1796 | static void ad1888_update_jacks(struct snd_ac97 *ac97) |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 1797 | { |
Takashi Iwai | 4525c9f | 2005-09-13 11:47:07 +0200 | [diff] [blame] | 1798 | unsigned short val = 0; |
| 1799 | if (! is_shared_linein(ac97)) |
| 1800 | val |= (1 << 12); |
| 1801 | if (! is_shared_micin(ac97)) |
| 1802 | val |= (1 << 11); |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 1803 | /* shared Line-In */ |
Takashi Iwai | 4525c9f | 2005-09-13 11:47:07 +0200 | [diff] [blame] | 1804 | 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] | 1805 | } |
| 1806 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1807 | static const struct snd_kcontrol_new snd_ac97_ad1888_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | { |
| 1809 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1810 | .name = "Exchange Front/Surround", |
| 1811 | .info = snd_ac97_ad1888_lohpsel_info, |
| 1812 | .get = snd_ac97_ad1888_lohpsel_get, |
| 1813 | .put = snd_ac97_ad1888_lohpsel_put |
| 1814 | }, |
| 1815 | AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC, 7, 1, 0), |
| 1816 | { |
| 1817 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1818 | .name = "Downmix", |
| 1819 | .info = snd_ac97_ad1888_downmix_info, |
| 1820 | .get = snd_ac97_ad1888_downmix_get, |
| 1821 | .put = snd_ac97_ad1888_downmix_put |
| 1822 | }, |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 1823 | AC97_SURROUND_JACK_MODE_CTL, |
| 1824 | AC97_CHANNEL_MODE_CTL, |
Sergey Ulanov | eeacb54 | 2005-07-27 17:28:58 +0200 | [diff] [blame] | 1825 | |
| 1826 | AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0), |
| 1827 | AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | }; |
| 1829 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1830 | static int patch_ad1888_specific(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1831 | { |
| 1832 | /* rename 0x04 as "Master" and 0x02 as "Master Surround" */ |
| 1833 | snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Master Surround Playback"); |
| 1834 | snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback"); |
| 1835 | return patch_build_controls(ac97, snd_ac97_ad1888_controls, ARRAY_SIZE(snd_ac97_ad1888_controls)); |
| 1836 | } |
| 1837 | |
| 1838 | static struct snd_ac97_build_ops patch_ad1888_build_ops = { |
| 1839 | .build_post_spdif = patch_ad198x_post_spdif, |
| 1840 | .build_specific = patch_ad1888_specific, |
| 1841 | #ifdef CONFIG_PM |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 1842 | .resume = ad18xx_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | #endif |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 1844 | .update_jacks = ad1888_update_jacks, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | }; |
| 1846 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1847 | int patch_ad1888(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | { |
| 1849 | unsigned short misc; |
| 1850 | |
| 1851 | patch_ad1881(ac97); |
| 1852 | ac97->build_ops = &patch_ad1888_build_ops; |
| 1853 | /* Switch FRONT/SURROUND LINE-OUT/HP-OUT default connection */ |
| 1854 | /* it seems that most vendors connect line-out connector to headphone out of AC'97 */ |
| 1855 | /* AD-compatible mode */ |
| 1856 | /* Stereo mutes enabled */ |
| 1857 | misc = snd_ac97_read(ac97, AC97_AD_MISC); |
| 1858 | snd_ac97_write_cache(ac97, AC97_AD_MISC, misc | |
| 1859 | AC97_AD198X_LOSEL | |
| 1860 | AC97_AD198X_HPSEL | |
| 1861 | AC97_AD198X_MSPLT | |
| 1862 | AC97_AD198X_AC97NC); |
| 1863 | ac97->flags |= AC97_STEREO_MUTES; |
| 1864 | return 0; |
| 1865 | } |
| 1866 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1867 | static int patch_ad1980_specific(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | { |
| 1869 | int err; |
| 1870 | |
| 1871 | if ((err = patch_ad1888_specific(ac97)) < 0) |
| 1872 | return err; |
| 1873 | return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1); |
| 1874 | } |
| 1875 | |
| 1876 | static struct snd_ac97_build_ops patch_ad1980_build_ops = { |
| 1877 | .build_post_spdif = patch_ad198x_post_spdif, |
| 1878 | .build_specific = patch_ad1980_specific, |
| 1879 | #ifdef CONFIG_PM |
Clemens Ladisch | 462c417 | 2005-05-10 14:50:31 +0200 | [diff] [blame] | 1880 | .resume = ad18xx_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1881 | #endif |
Clemens Ladisch | 462c417 | 2005-05-10 14:50:31 +0200 | [diff] [blame] | 1882 | .update_jacks = ad1888_update_jacks, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1883 | }; |
| 1884 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1885 | int patch_ad1980(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1886 | { |
| 1887 | patch_ad1888(ac97); |
| 1888 | ac97->build_ops = &patch_ad1980_build_ops; |
| 1889 | return 0; |
| 1890 | } |
| 1891 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1892 | static const struct snd_kcontrol_new snd_ac97_ad1985_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1893 | AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0) |
| 1894 | }; |
| 1895 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1896 | static void ad1985_update_jacks(struct snd_ac97 *ac97) |
Takashi Iwai | e5b3f45 | 2005-05-17 17:17:57 +0200 | [diff] [blame] | 1897 | { |
Takashi Iwai | 4525c9f | 2005-09-13 11:47:07 +0200 | [diff] [blame] | 1898 | ad1888_update_jacks(ac97); |
Takashi Iwai | fc232c6 | 2005-05-27 10:42:45 +0200 | [diff] [blame] | 1899 | snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 1 << 9, |
| 1900 | is_shared_micin(ac97) ? 0 : 1 << 9); |
Takashi Iwai | e5b3f45 | 2005-05-17 17:17:57 +0200 | [diff] [blame] | 1901 | } |
| 1902 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1903 | static int patch_ad1985_specific(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1904 | { |
| 1905 | int err; |
| 1906 | |
| 1907 | if ((err = patch_ad1980_specific(ac97)) < 0) |
| 1908 | return err; |
| 1909 | return patch_build_controls(ac97, snd_ac97_ad1985_controls, ARRAY_SIZE(snd_ac97_ad1985_controls)); |
| 1910 | } |
| 1911 | |
| 1912 | static struct snd_ac97_build_ops patch_ad1985_build_ops = { |
| 1913 | .build_post_spdif = patch_ad198x_post_spdif, |
| 1914 | .build_specific = patch_ad1985_specific, |
| 1915 | #ifdef CONFIG_PM |
Clemens Ladisch | 462c417 | 2005-05-10 14:50:31 +0200 | [diff] [blame] | 1916 | .resume = ad18xx_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | #endif |
Takashi Iwai | e5b3f45 | 2005-05-17 17:17:57 +0200 | [diff] [blame] | 1918 | .update_jacks = ad1985_update_jacks, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | }; |
| 1920 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1921 | int patch_ad1985(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1922 | { |
| 1923 | unsigned short misc; |
| 1924 | |
| 1925 | patch_ad1881(ac97); |
| 1926 | ac97->build_ops = &patch_ad1985_build_ops; |
| 1927 | misc = snd_ac97_read(ac97, AC97_AD_MISC); |
| 1928 | /* switch front/surround line-out/hp-out */ |
| 1929 | /* center/LFE, mic in 3.75V mode */ |
| 1930 | /* AD-compatible mode */ |
| 1931 | /* Stereo mutes enabled */ |
| 1932 | /* in accordance with ADI driver: misc | 0x5c28 */ |
| 1933 | snd_ac97_write_cache(ac97, AC97_AD_MISC, misc | |
| 1934 | AC97_AD198X_VREFH | |
| 1935 | AC97_AD198X_LOSEL | |
| 1936 | AC97_AD198X_HPSEL | |
| 1937 | AC97_AD198X_CLDIS | |
| 1938 | AC97_AD198X_LODIS | |
| 1939 | AC97_AD198X_MSPLT | |
| 1940 | AC97_AD198X_AC97NC); |
| 1941 | ac97->flags |= AC97_STEREO_MUTES; |
| 1942 | /* on AD1985 rev. 3, AC'97 revision bits are zero */ |
| 1943 | ac97->ext_id = (ac97->ext_id & ~AC97_EI_REV_MASK) | AC97_EI_REV_23; |
| 1944 | return 0; |
| 1945 | } |
| 1946 | |
| 1947 | /* |
| 1948 | * realtek ALC65x/850 codecs |
| 1949 | */ |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1950 | static void alc650_update_jacks(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1951 | { |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 1952 | int shared; |
| 1953 | |
| 1954 | /* shared Line-In */ |
| 1955 | shared = is_shared_linein(ac97); |
| 1956 | snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 9, |
| 1957 | shared ? (1 << 9) : 0); |
| 1958 | /* update shared Mic */ |
| 1959 | shared = is_shared_micin(ac97); |
| 1960 | /* disable/enable vref */ |
| 1961 | snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12, |
| 1962 | shared ? (1 << 12) : 0); |
| 1963 | /* turn on/off center-on-mic */ |
| 1964 | snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 10, |
| 1965 | shared ? (1 << 10) : 0); |
| 1966 | /* GPIO0 high for mic */ |
| 1967 | snd_ac97_update_bits(ac97, AC97_ALC650_GPIO_STATUS, 0x100, |
| 1968 | shared ? 0 : 0x100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1969 | } |
| 1970 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1971 | static const struct snd_kcontrol_new snd_ac97_controls_alc650[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1972 | AC97_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0), |
| 1973 | AC97_SINGLE("Surround Down Mix", AC97_ALC650_MULTICH, 1, 1, 0), |
| 1974 | AC97_SINGLE("Center/LFE Down Mix", AC97_ALC650_MULTICH, 2, 1, 0), |
| 1975 | AC97_SINGLE("Exchange Center/LFE", AC97_ALC650_MULTICH, 3, 1, 0), |
| 1976 | /* 4: Analog Input To Surround */ |
| 1977 | /* 5: Analog Input To Center/LFE */ |
| 1978 | /* 6: Independent Master Volume Right */ |
| 1979 | /* 7: Independent Master Volume Left */ |
| 1980 | /* 8: reserved */ |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 1981 | /* 9: Line-In/Surround share */ |
| 1982 | /* 10: Mic/CLFE share */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | /* 11-13: in IEC958 controls */ |
| 1984 | AC97_SINGLE("Swap Surround Slot", AC97_ALC650_MULTICH, 14, 1, 0), |
| 1985 | #if 0 /* always set in patch_alc650 */ |
| 1986 | AC97_SINGLE("IEC958 Input Clock Enable", AC97_ALC650_CLOCK, 0, 1, 0), |
| 1987 | AC97_SINGLE("IEC958 Input Pin Enable", AC97_ALC650_CLOCK, 1, 1, 0), |
| 1988 | AC97_SINGLE("Surround DAC Switch", AC97_ALC650_SURR_DAC_VOL, 15, 1, 1), |
| 1989 | AC97_DOUBLE("Surround DAC Volume", AC97_ALC650_SURR_DAC_VOL, 8, 0, 31, 1), |
| 1990 | AC97_SINGLE("Center/LFE DAC Switch", AC97_ALC650_LFE_DAC_VOL, 15, 1, 1), |
| 1991 | AC97_DOUBLE("Center/LFE DAC Volume", AC97_ALC650_LFE_DAC_VOL, 8, 0, 31, 1), |
| 1992 | #endif |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 1993 | AC97_SURROUND_JACK_MODE_CTL, |
| 1994 | AC97_CHANNEL_MODE_CTL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1995 | }; |
| 1996 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 1997 | static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc650[] = { |
Clemens Ladisch | 10e8d78 | 2005-08-03 13:40:08 +0200 | [diff] [blame] | 1998 | 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] | 1999 | AC97_SINGLE("Analog to IEC958 Output", AC97_ALC650_MULTICH, 12, 1, 0), |
| 2000 | /* disable this controls since it doesn't work as expected */ |
| 2001 | /* AC97_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 13, 1, 0), */ |
| 2002 | }; |
| 2003 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2004 | static int patch_alc650_specific(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2005 | { |
| 2006 | int err; |
| 2007 | |
| 2008 | if ((err = patch_build_controls(ac97, snd_ac97_controls_alc650, ARRAY_SIZE(snd_ac97_controls_alc650))) < 0) |
| 2009 | return err; |
| 2010 | if (ac97->ext_id & AC97_EI_SPDIF) { |
| 2011 | if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc650, ARRAY_SIZE(snd_ac97_spdif_controls_alc650))) < 0) |
| 2012 | return err; |
| 2013 | } |
| 2014 | return 0; |
| 2015 | } |
| 2016 | |
| 2017 | static struct snd_ac97_build_ops patch_alc650_ops = { |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2018 | .build_specific = patch_alc650_specific, |
| 2019 | .update_jacks = alc650_update_jacks |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2020 | }; |
| 2021 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2022 | int patch_alc650(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2023 | { |
| 2024 | unsigned short val; |
| 2025 | |
| 2026 | ac97->build_ops = &patch_alc650_ops; |
| 2027 | |
| 2028 | /* determine the revision */ |
| 2029 | val = snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f; |
| 2030 | if (val < 3) |
| 2031 | ac97->id = 0x414c4720; /* Old version */ |
| 2032 | else if (val < 0x10) |
| 2033 | ac97->id = 0x414c4721; /* D version */ |
| 2034 | else if (val < 0x20) |
| 2035 | ac97->id = 0x414c4722; /* E version */ |
| 2036 | else if (val < 0x30) |
| 2037 | ac97->id = 0x414c4723; /* F version */ |
| 2038 | |
| 2039 | /* revision E or F */ |
| 2040 | /* FIXME: what about revision D ? */ |
| 2041 | ac97->spec.dev_flags = (ac97->id == 0x414c4722 || |
| 2042 | ac97->id == 0x414c4723); |
| 2043 | |
| 2044 | /* enable AC97_ALC650_GPIO_SETUP, AC97_ALC650_CLOCK for R/W */ |
| 2045 | snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS, |
| 2046 | snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x8000); |
| 2047 | |
| 2048 | /* Enable SPDIF-IN only on Rev.E and above */ |
| 2049 | val = snd_ac97_read(ac97, AC97_ALC650_CLOCK); |
| 2050 | /* SPDIF IN with pin 47 */ |
| 2051 | if (ac97->spec.dev_flags) |
| 2052 | val |= 0x03; /* enable */ |
| 2053 | else |
| 2054 | val &= ~0x03; /* disable */ |
| 2055 | snd_ac97_write_cache(ac97, AC97_ALC650_CLOCK, val); |
| 2056 | |
| 2057 | /* set default: slot 3,4,7,8,6,9 |
| 2058 | spdif-in monitor off, analog-spdif off, spdif-in off |
| 2059 | center on mic off, surround on line-in off |
| 2060 | downmix off, duplicate front off |
| 2061 | */ |
| 2062 | snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 0); |
| 2063 | |
| 2064 | /* set GPIO0 for mic bias */ |
| 2065 | /* GPIO0 pin output, no interrupt, high */ |
| 2066 | snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_SETUP, |
| 2067 | snd_ac97_read(ac97, AC97_ALC650_GPIO_SETUP) | 0x01); |
| 2068 | snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS, |
| 2069 | (snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x100) & ~0x10); |
| 2070 | |
| 2071 | /* full DAC volume */ |
| 2072 | snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808); |
| 2073 | snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808); |
| 2074 | return 0; |
| 2075 | } |
| 2076 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2077 | static void alc655_update_jacks(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2078 | { |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2079 | int shared; |
| 2080 | |
| 2081 | /* shared Line-In */ |
| 2082 | shared = is_shared_linein(ac97); |
| 2083 | ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 9, |
| 2084 | shared ? (1 << 9) : 0, 0); |
| 2085 | /* update shared mic */ |
| 2086 | shared = is_shared_micin(ac97); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2087 | /* misc control; vrefout disable */ |
| 2088 | snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12, |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2089 | shared ? (1 << 12) : 0); |
| 2090 | ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 10, |
| 2091 | shared ? (1 << 10) : 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2092 | } |
| 2093 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2094 | static const struct snd_kcontrol_new snd_ac97_controls_alc655[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2095 | AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0), |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2096 | AC97_SURROUND_JACK_MODE_CTL, |
| 2097 | AC97_CHANNEL_MODE_CTL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2098 | }; |
| 2099 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2100 | 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] | 2101 | { |
| 2102 | static char *texts_655[3] = { "PCM", "Analog In", "IEC958 In" }; |
| 2103 | static char *texts_658[4] = { "PCM", "Analog1 In", "Analog2 In", "IEC958 In" }; |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2104 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2105 | |
| 2106 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 2107 | uinfo->count = 1; |
| 2108 | uinfo->value.enumerated.items = ac97->spec.dev_flags ? 4 : 3; |
| 2109 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
| 2110 | uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; |
| 2111 | strcpy(uinfo->value.enumerated.name, |
| 2112 | ac97->spec.dev_flags ? |
| 2113 | texts_658[uinfo->value.enumerated.item] : |
| 2114 | texts_655[uinfo->value.enumerated.item]); |
| 2115 | return 0; |
| 2116 | } |
| 2117 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2118 | 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] | 2119 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2120 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2121 | unsigned short val; |
| 2122 | |
| 2123 | val = ac97->regs[AC97_ALC650_MULTICH]; |
| 2124 | val = (val >> 12) & 3; |
| 2125 | if (ac97->spec.dev_flags && val == 3) |
| 2126 | val = 0; |
| 2127 | ucontrol->value.enumerated.item[0] = val; |
| 2128 | return 0; |
| 2129 | } |
| 2130 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2131 | 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] | 2132 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2133 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2134 | |
| 2135 | return ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 3 << 12, |
| 2136 | (unsigned short)ucontrol->value.enumerated.item[0] << 12, |
| 2137 | 0); |
| 2138 | } |
| 2139 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2140 | static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc655[] = { |
Clemens Ladisch | 10e8d78 | 2005-08-03 13:40:08 +0200 | [diff] [blame] | 2141 | 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] | 2142 | /* disable this controls since it doesn't work as expected */ |
| 2143 | /* AC97_PAGE_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 14, 1, 0, 0), */ |
| 2144 | { |
| 2145 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Takashi Iwai | 031c95d | 2005-12-05 20:51:43 +0100 | [diff] [blame] | 2146 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2147 | .info = alc655_iec958_route_info, |
| 2148 | .get = alc655_iec958_route_get, |
| 2149 | .put = alc655_iec958_route_put, |
| 2150 | }, |
| 2151 | }; |
| 2152 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2153 | static int patch_alc655_specific(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2154 | { |
| 2155 | int err; |
| 2156 | |
| 2157 | if ((err = patch_build_controls(ac97, snd_ac97_controls_alc655, ARRAY_SIZE(snd_ac97_controls_alc655))) < 0) |
| 2158 | return err; |
| 2159 | if (ac97->ext_id & AC97_EI_SPDIF) { |
| 2160 | if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0) |
| 2161 | return err; |
| 2162 | } |
| 2163 | return 0; |
| 2164 | } |
| 2165 | |
| 2166 | static struct snd_ac97_build_ops patch_alc655_ops = { |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2167 | .build_specific = patch_alc655_specific, |
| 2168 | .update_jacks = alc655_update_jacks |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2169 | }; |
| 2170 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2171 | int patch_alc655(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | { |
| 2173 | unsigned int val; |
| 2174 | |
Takashi Iwai | a5022b0 | 2005-09-02 14:03:05 +0200 | [diff] [blame] | 2175 | if (ac97->id == AC97_ID_ALC658) { |
| 2176 | ac97->spec.dev_flags = 1; /* ALC658 */ |
| 2177 | if ((snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f) == 2) { |
| 2178 | ac97->id = AC97_ID_ALC658D; |
| 2179 | ac97->spec.dev_flags = 2; |
| 2180 | } |
| 2181 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2182 | |
| 2183 | ac97->build_ops = &patch_alc655_ops; |
| 2184 | |
| 2185 | /* assume only page 0 for writing cache */ |
| 2186 | snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR); |
| 2187 | |
| 2188 | /* adjust default values */ |
| 2189 | val = snd_ac97_read(ac97, 0x7a); /* misc control */ |
Takashi Iwai | a5022b0 | 2005-09-02 14:03:05 +0200 | [diff] [blame] | 2190 | if (ac97->spec.dev_flags) /* ALC658 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2191 | val &= ~(1 << 1); /* Pin 47 is spdif input pin */ |
Takashi Iwai | ee71508e | 2005-08-31 17:31:07 +0200 | [diff] [blame] | 2192 | else { /* ALC655 */ |
| 2193 | if (ac97->subsystem_vendor == 0x1462 && |
| 2194 | ac97->subsystem_device == 0x0131) /* MSI S270 laptop */ |
| 2195 | val &= ~(1 << 1); /* Pin 47 is EAPD (for internal speaker) */ |
| 2196 | else |
| 2197 | val |= (1 << 1); /* Pin 47 is spdif input pin */ |
| 2198 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2199 | val &= ~(1 << 12); /* vref enable */ |
| 2200 | snd_ac97_write_cache(ac97, 0x7a, val); |
| 2201 | /* set default: spdif-in enabled, |
| 2202 | spdif-in monitor off, spdif-in PCM off |
| 2203 | center on mic off, surround on line-in off |
| 2204 | duplicate front off |
| 2205 | */ |
| 2206 | snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15); |
| 2207 | |
| 2208 | /* full DAC volume */ |
| 2209 | snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808); |
| 2210 | snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808); |
Takashi Iwai | a5022b0 | 2005-09-02 14:03:05 +0200 | [diff] [blame] | 2211 | |
| 2212 | /* update undocumented bit... */ |
| 2213 | if (ac97->id == AC97_ID_ALC658D) |
| 2214 | snd_ac97_update_bits(ac97, 0x74, 0x0800, 0x0800); |
| 2215 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2216 | return 0; |
| 2217 | } |
| 2218 | |
| 2219 | |
| 2220 | #define AC97_ALC850_JACK_SELECT 0x76 |
| 2221 | #define AC97_ALC850_MISC1 0x7a |
| 2222 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2223 | static void alc850_update_jacks(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2224 | { |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2225 | int shared; |
| 2226 | |
| 2227 | /* shared Line-In */ |
| 2228 | shared = is_shared_linein(ac97); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2229 | /* SURR 1kOhm (bit4), Amp (bit5) */ |
| 2230 | snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<4)|(1<<5), |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2231 | shared ? (1<<5) : (1<<4)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2232 | /* LINE-IN = 0, SURROUND = 2 */ |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2233 | snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 12, |
| 2234 | shared ? (2<<12) : (0<<12)); |
| 2235 | /* update shared mic */ |
| 2236 | shared = is_shared_micin(ac97); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2237 | /* Vref disable (bit12), 1kOhm (bit13) */ |
| 2238 | snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<12)|(1<<13), |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2239 | shared ? (1<<12) : (1<<13)); |
Takashi Iwai | da79e44 | 2006-01-12 11:45:51 +0100 | [diff] [blame] | 2240 | /* MIC-IN = 1, CENTER-LFE = 5 */ |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2241 | snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 4, |
Takashi Iwai | da79e44 | 2006-01-12 11:45:51 +0100 | [diff] [blame] | 2242 | shared ? (5<<4) : (1<<4)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2243 | } |
| 2244 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2245 | static const struct snd_kcontrol_new snd_ac97_controls_alc850[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2246 | AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0), |
Sergey Vlasov | 67e1b51 | 2005-04-25 11:34:33 +0200 | [diff] [blame] | 2247 | 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] | 2248 | AC97_SURROUND_JACK_MODE_CTL, |
| 2249 | AC97_CHANNEL_MODE_CTL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2250 | }; |
| 2251 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2252 | static int patch_alc850_specific(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2253 | { |
| 2254 | int err; |
| 2255 | |
| 2256 | if ((err = patch_build_controls(ac97, snd_ac97_controls_alc850, ARRAY_SIZE(snd_ac97_controls_alc850))) < 0) |
| 2257 | return err; |
| 2258 | if (ac97->ext_id & AC97_EI_SPDIF) { |
| 2259 | if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0) |
| 2260 | return err; |
| 2261 | } |
| 2262 | return 0; |
| 2263 | } |
| 2264 | |
| 2265 | static struct snd_ac97_build_ops patch_alc850_ops = { |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2266 | .build_specific = patch_alc850_specific, |
| 2267 | .update_jacks = alc850_update_jacks |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2268 | }; |
| 2269 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2270 | int patch_alc850(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2271 | { |
| 2272 | ac97->build_ops = &patch_alc850_ops; |
| 2273 | |
| 2274 | ac97->spec.dev_flags = 0; /* for IEC958 playback route - ALC655 compatible */ |
| 2275 | |
| 2276 | /* assume only page 0 for writing cache */ |
| 2277 | snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR); |
| 2278 | |
| 2279 | /* adjust default values */ |
| 2280 | /* set default: spdif-in enabled, |
| 2281 | spdif-in monitor off, spdif-in PCM off |
| 2282 | center on mic off, surround on line-in off |
| 2283 | duplicate front off |
| 2284 | */ |
| 2285 | snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15); |
| 2286 | /* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off |
| 2287 | * Front Amp: on, Vref: enable, Center 1kOhm: on, Mix: on |
| 2288 | */ |
| 2289 | snd_ac97_write_cache(ac97, 0x7a, (1<<1)|(1<<4)|(0<<5)|(1<<6)| |
| 2290 | (1<<7)|(0<<12)|(1<<13)|(0<<14)); |
| 2291 | /* detection UIO2,3: all path floating, UIO3: MIC, Vref2: disable, |
| 2292 | * UIO1: FRONT, Vref3: disable, UIO3: LINE, Front-Mic: mute |
| 2293 | */ |
| 2294 | snd_ac97_write_cache(ac97, 0x76, (0<<0)|(0<<2)|(1<<4)|(1<<7)|(2<<8)| |
| 2295 | (1<<11)|(0<<12)|(1<<15)); |
| 2296 | |
| 2297 | /* full DAC volume */ |
| 2298 | snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808); |
| 2299 | snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808); |
| 2300 | return 0; |
| 2301 | } |
| 2302 | |
| 2303 | |
| 2304 | /* |
| 2305 | * C-Media CM97xx codecs |
| 2306 | */ |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2307 | static void cm9738_update_jacks(struct snd_ac97 *ac97) |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2308 | { |
| 2309 | /* shared Line-In */ |
| 2310 | snd_ac97_update_bits(ac97, AC97_CM9738_VENDOR_CTRL, 1 << 10, |
| 2311 | is_shared_linein(ac97) ? (1 << 10) : 0); |
| 2312 | } |
| 2313 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2314 | static const struct snd_kcontrol_new snd_ac97_cm9738_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2315 | AC97_SINGLE("Duplicate Front", AC97_CM9738_VENDOR_CTRL, 13, 1, 0), |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2316 | AC97_SURROUND_JACK_MODE_CTL, |
| 2317 | AC97_CHANNEL_MODE_4CH_CTL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2318 | }; |
| 2319 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2320 | static int patch_cm9738_specific(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2321 | { |
| 2322 | return patch_build_controls(ac97, snd_ac97_cm9738_controls, ARRAY_SIZE(snd_ac97_cm9738_controls)); |
| 2323 | } |
| 2324 | |
| 2325 | static struct snd_ac97_build_ops patch_cm9738_ops = { |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2326 | .build_specific = patch_cm9738_specific, |
| 2327 | .update_jacks = cm9738_update_jacks |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2328 | }; |
| 2329 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2330 | int patch_cm9738(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2331 | { |
| 2332 | ac97->build_ops = &patch_cm9738_ops; |
| 2333 | /* FIXME: can anyone confirm below? */ |
| 2334 | /* CM9738 has no PCM volume although the register reacts */ |
| 2335 | ac97->flags |= AC97_HAS_NO_PCM_VOL; |
| 2336 | snd_ac97_write_cache(ac97, AC97_PCM, 0x8000); |
| 2337 | |
| 2338 | return 0; |
| 2339 | } |
| 2340 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2341 | 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] | 2342 | { |
| 2343 | static char *texts[] = { "Analog", "Digital" }; |
| 2344 | |
| 2345 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 2346 | uinfo->count = 1; |
| 2347 | uinfo->value.enumerated.items = 2; |
| 2348 | if (uinfo->value.enumerated.item > 1) |
| 2349 | uinfo->value.enumerated.item = 1; |
| 2350 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); |
| 2351 | return 0; |
| 2352 | } |
| 2353 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2354 | 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] | 2355 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2356 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2357 | unsigned short val; |
| 2358 | |
| 2359 | val = ac97->regs[AC97_CM9739_SPDIF_CTRL]; |
| 2360 | ucontrol->value.enumerated.item[0] = (val >> 1) & 0x01; |
| 2361 | return 0; |
| 2362 | } |
| 2363 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2364 | 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] | 2365 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2366 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2367 | |
| 2368 | return snd_ac97_update_bits(ac97, AC97_CM9739_SPDIF_CTRL, |
| 2369 | 0x01 << 1, |
| 2370 | (ucontrol->value.enumerated.item[0] & 0x01) << 1); |
| 2371 | } |
| 2372 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2373 | static const struct snd_kcontrol_new snd_ac97_cm9739_controls_spdif[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2374 | /* BIT 0: SPDI_EN - always true */ |
| 2375 | { /* BIT 1: SPDIFS */ |
| 2376 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2377 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source", |
| 2378 | .info = snd_ac97_cmedia_spdif_playback_source_info, |
| 2379 | .get = snd_ac97_cmedia_spdif_playback_source_get, |
| 2380 | .put = snd_ac97_cmedia_spdif_playback_source_put, |
| 2381 | }, |
| 2382 | /* BIT 2: IG_SPIV */ |
| 2383 | AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9739_SPDIF_CTRL, 2, 1, 0), |
| 2384 | /* BIT 3: SPI2F */ |
| 2385 | AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9739_SPDIF_CTRL, 3, 1, 0), |
| 2386 | /* BIT 4: SPI2SDI */ |
| 2387 | AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9739_SPDIF_CTRL, 4, 1, 0), |
| 2388 | /* BIT 8: SPD32 - 32bit SPDIF - not supported yet */ |
| 2389 | }; |
| 2390 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2391 | static void cm9739_update_jacks(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2392 | { |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2393 | /* shared Line-In */ |
| 2394 | snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 1 << 10, |
| 2395 | is_shared_linein(ac97) ? (1 << 10) : 0); |
| 2396 | /* shared Mic */ |
| 2397 | snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 0x3000, |
| 2398 | is_shared_micin(ac97) ? 0x1000 : 0x2000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2399 | } |
| 2400 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2401 | static const struct snd_kcontrol_new snd_ac97_cm9739_controls[] = { |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2402 | AC97_SURROUND_JACK_MODE_CTL, |
| 2403 | AC97_CHANNEL_MODE_CTL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2404 | }; |
| 2405 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2406 | static int patch_cm9739_specific(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2407 | { |
| 2408 | return patch_build_controls(ac97, snd_ac97_cm9739_controls, ARRAY_SIZE(snd_ac97_cm9739_controls)); |
| 2409 | } |
| 2410 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2411 | static int patch_cm9739_post_spdif(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2412 | { |
| 2413 | return patch_build_controls(ac97, snd_ac97_cm9739_controls_spdif, ARRAY_SIZE(snd_ac97_cm9739_controls_spdif)); |
| 2414 | } |
| 2415 | |
| 2416 | static struct snd_ac97_build_ops patch_cm9739_ops = { |
| 2417 | .build_specific = patch_cm9739_specific, |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2418 | .build_post_spdif = patch_cm9739_post_spdif, |
| 2419 | .update_jacks = cm9739_update_jacks |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2420 | }; |
| 2421 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2422 | int patch_cm9739(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2423 | { |
| 2424 | unsigned short val; |
| 2425 | |
| 2426 | ac97->build_ops = &patch_cm9739_ops; |
| 2427 | |
| 2428 | /* CM9739/A has no Master and PCM volume although the register reacts */ |
| 2429 | ac97->flags |= AC97_HAS_NO_MASTER_VOL | AC97_HAS_NO_PCM_VOL; |
| 2430 | snd_ac97_write_cache(ac97, AC97_MASTER, 0x8000); |
| 2431 | snd_ac97_write_cache(ac97, AC97_PCM, 0x8000); |
| 2432 | |
| 2433 | /* check spdif */ |
| 2434 | val = snd_ac97_read(ac97, AC97_EXTENDED_STATUS); |
| 2435 | if (val & AC97_EA_SPCV) { |
| 2436 | /* enable spdif in */ |
| 2437 | snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL, |
| 2438 | snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) | 0x01); |
| 2439 | ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */ |
| 2440 | } else { |
| 2441 | ac97->ext_id &= ~AC97_EI_SPDIF; /* disable extended-id */ |
| 2442 | ac97->rates[AC97_RATES_SPDIF] = 0; |
| 2443 | } |
| 2444 | |
| 2445 | /* set-up multi channel */ |
| 2446 | /* bit 14: 0 = SPDIF, 1 = EAPD */ |
| 2447 | /* bit 13: enable internal vref output for mic */ |
| 2448 | /* bit 12: disable center/lfe (swithable) */ |
| 2449 | /* bit 10: disable surround/line (switchable) */ |
| 2450 | /* bit 9: mix 2 surround off */ |
| 2451 | /* bit 4: undocumented; 0 mutes the CM9739A, which defaults to 1 */ |
| 2452 | /* bit 3: undocumented; surround? */ |
| 2453 | /* bit 0: dB */ |
| 2454 | val = snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) & (1 << 4); |
| 2455 | val |= (1 << 3); |
| 2456 | val |= (1 << 13); |
| 2457 | if (! (ac97->ext_id & AC97_EI_SPDIF)) |
| 2458 | val |= (1 << 14); |
| 2459 | snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, val); |
| 2460 | |
| 2461 | /* FIXME: set up GPIO */ |
| 2462 | snd_ac97_write_cache(ac97, 0x70, 0x0100); |
| 2463 | snd_ac97_write_cache(ac97, 0x72, 0x0020); |
| 2464 | /* Special exception for ASUS W1000/CMI9739. It does not have an SPDIF in. */ |
| 2465 | if (ac97->pci && |
| 2466 | ac97->subsystem_vendor == 0x1043 && |
| 2467 | ac97->subsystem_device == 0x1843) { |
| 2468 | snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL, |
| 2469 | snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) & ~0x01); |
| 2470 | snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, |
| 2471 | snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) | (1 << 14)); |
| 2472 | } |
| 2473 | |
| 2474 | return 0; |
| 2475 | } |
| 2476 | |
| 2477 | #define AC97_CM9761_MULTI_CHAN 0x64 |
Takashi Iwai | 5f0dccf | 2005-04-07 15:53:20 +0200 | [diff] [blame] | 2478 | #define AC97_CM9761_FUNC 0x66 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2479 | #define AC97_CM9761_SPDIF_CTRL 0x6c |
| 2480 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2481 | static void cm9761_update_jacks(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2482 | { |
Takashi Iwai | 4525c9f | 2005-09-13 11:47:07 +0200 | [diff] [blame] | 2483 | /* FIXME: check the bits for each model |
| 2484 | * model 83 is confirmed to work |
| 2485 | */ |
| 2486 | static unsigned short surr_on[3][2] = { |
| 2487 | { 0x0008, 0x0000 }, /* 9761-78 & 82 */ |
| 2488 | { 0x0000, 0x0008 }, /* 9761-82 rev.B */ |
| 2489 | { 0x0000, 0x0008 }, /* 9761-83 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2490 | }; |
Takashi Iwai | 4525c9f | 2005-09-13 11:47:07 +0200 | [diff] [blame] | 2491 | static unsigned short clfe_on[3][2] = { |
| 2492 | { 0x0000, 0x1000 }, /* 9761-78 & 82 */ |
| 2493 | { 0x1000, 0x0000 }, /* 9761-82 rev.B */ |
| 2494 | { 0x0000, 0x1000 }, /* 9761-83 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2495 | }; |
Takashi Iwai | 4525c9f | 2005-09-13 11:47:07 +0200 | [diff] [blame] | 2496 | static unsigned short surr_shared[3][2] = { |
| 2497 | { 0x0000, 0x0400 }, /* 9761-78 & 82 */ |
| 2498 | { 0x0000, 0x0400 }, /* 9761-82 rev.B */ |
| 2499 | { 0x0000, 0x0400 }, /* 9761-83 */ |
| 2500 | }; |
| 2501 | static unsigned short clfe_shared[3][2] = { |
| 2502 | { 0x2000, 0x0880 }, /* 9761-78 & 82 */ |
| 2503 | { 0x0000, 0x2880 }, /* 9761-82 rev.B */ |
| 2504 | { 0x2000, 0x0800 }, /* 9761-83 */ |
| 2505 | }; |
| 2506 | unsigned short val = 0; |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2507 | |
Takashi Iwai | 4525c9f | 2005-09-13 11:47:07 +0200 | [diff] [blame] | 2508 | val |= surr_on[ac97->spec.dev_flags][is_surround_on(ac97)]; |
| 2509 | val |= clfe_on[ac97->spec.dev_flags][is_clfe_on(ac97)]; |
| 2510 | val |= surr_shared[ac97->spec.dev_flags][is_shared_linein(ac97)]; |
| 2511 | val |= clfe_shared[ac97->spec.dev_flags][is_shared_micin(ac97)]; |
| 2512 | |
| 2513 | snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x3c88, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2514 | } |
| 2515 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2516 | static const struct snd_kcontrol_new snd_ac97_cm9761_controls[] = { |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2517 | AC97_SURROUND_JACK_MODE_CTL, |
| 2518 | AC97_CHANNEL_MODE_CTL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2519 | }; |
| 2520 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2521 | 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] | 2522 | { |
| 2523 | static char *texts[] = { "AC-Link", "ADC", "SPDIF-In" }; |
| 2524 | |
| 2525 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 2526 | uinfo->count = 1; |
| 2527 | uinfo->value.enumerated.items = 3; |
| 2528 | if (uinfo->value.enumerated.item > 2) |
| 2529 | uinfo->value.enumerated.item = 2; |
| 2530 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); |
| 2531 | return 0; |
| 2532 | } |
| 2533 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2534 | 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] | 2535 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2536 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 5f0dccf | 2005-04-07 15:53:20 +0200 | [diff] [blame] | 2537 | |
| 2538 | if (ac97->regs[AC97_CM9761_FUNC] & 0x1) |
| 2539 | ucontrol->value.enumerated.item[0] = 2; /* SPDIF-loopback */ |
| 2540 | else if (ac97->regs[AC97_CM9761_SPDIF_CTRL] & 0x2) |
| 2541 | ucontrol->value.enumerated.item[0] = 1; /* ADC loopback */ |
| 2542 | else |
| 2543 | ucontrol->value.enumerated.item[0] = 0; /* AC-link */ |
| 2544 | return 0; |
| 2545 | } |
| 2546 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2547 | 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] | 2548 | { |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2549 | struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 5f0dccf | 2005-04-07 15:53:20 +0200 | [diff] [blame] | 2550 | |
| 2551 | if (ucontrol->value.enumerated.item[0] == 2) |
| 2552 | return snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0x1); |
| 2553 | snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0); |
| 2554 | return snd_ac97_update_bits(ac97, AC97_CM9761_SPDIF_CTRL, 0x2, |
| 2555 | ucontrol->value.enumerated.item[0] == 1 ? 0x2 : 0); |
| 2556 | } |
| 2557 | |
| 2558 | static const char *cm9761_dac_clock[] = { "AC-Link", "SPDIF-In", "Both" }; |
| 2559 | static const struct ac97_enum cm9761_dac_clock_enum = |
| 2560 | AC97_ENUM_SINGLE(AC97_CM9761_SPDIF_CTRL, 9, 3, cm9761_dac_clock); |
| 2561 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2562 | static const struct snd_kcontrol_new snd_ac97_cm9761_controls_spdif[] = { |
Takashi Iwai | 5f0dccf | 2005-04-07 15:53:20 +0200 | [diff] [blame] | 2563 | { /* BIT 1: SPDIFS */ |
| 2564 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2565 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source", |
| 2566 | .info = cm9761_spdif_out_source_info, |
| 2567 | .get = cm9761_spdif_out_source_get, |
| 2568 | .put = cm9761_spdif_out_source_put, |
| 2569 | }, |
| 2570 | /* BIT 2: IG_SPIV */ |
| 2571 | AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9761_SPDIF_CTRL, 2, 1, 0), |
| 2572 | /* BIT 3: SPI2F */ |
| 2573 | AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9761_SPDIF_CTRL, 3, 1, 0), |
| 2574 | /* BIT 4: SPI2SDI */ |
| 2575 | AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9761_SPDIF_CTRL, 4, 1, 0), |
| 2576 | /* BIT 9-10: DAC_CTL */ |
| 2577 | AC97_ENUM("DAC Clock Source", cm9761_dac_clock_enum), |
| 2578 | }; |
| 2579 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2580 | static int patch_cm9761_post_spdif(struct snd_ac97 * ac97) |
Takashi Iwai | 5f0dccf | 2005-04-07 15:53:20 +0200 | [diff] [blame] | 2581 | { |
| 2582 | return patch_build_controls(ac97, snd_ac97_cm9761_controls_spdif, ARRAY_SIZE(snd_ac97_cm9761_controls_spdif)); |
| 2583 | } |
| 2584 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2585 | static int patch_cm9761_specific(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2586 | { |
| 2587 | return patch_build_controls(ac97, snd_ac97_cm9761_controls, ARRAY_SIZE(snd_ac97_cm9761_controls)); |
| 2588 | } |
| 2589 | |
| 2590 | static struct snd_ac97_build_ops patch_cm9761_ops = { |
| 2591 | .build_specific = patch_cm9761_specific, |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2592 | .build_post_spdif = patch_cm9761_post_spdif, |
| 2593 | .update_jacks = cm9761_update_jacks |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2594 | }; |
| 2595 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2596 | int patch_cm9761(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2597 | { |
| 2598 | unsigned short val; |
| 2599 | |
| 2600 | /* CM9761 has no PCM volume although the register reacts */ |
| 2601 | /* Master volume seems to have _some_ influence on the analog |
| 2602 | * input sounds |
| 2603 | */ |
| 2604 | ac97->flags |= /*AC97_HAS_NO_MASTER_VOL |*/ AC97_HAS_NO_PCM_VOL; |
| 2605 | snd_ac97_write_cache(ac97, AC97_MASTER, 0x8808); |
| 2606 | snd_ac97_write_cache(ac97, AC97_PCM, 0x8808); |
| 2607 | |
Takashi Iwai | 4525c9f | 2005-09-13 11:47:07 +0200 | [diff] [blame] | 2608 | 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] | 2609 | if (ac97->id == AC97_ID_CM9761_82) { |
| 2610 | unsigned short tmp; |
| 2611 | /* check page 1, reg 0x60 */ |
| 2612 | val = snd_ac97_read(ac97, AC97_INT_PAGING); |
| 2613 | snd_ac97_write_cache(ac97, AC97_INT_PAGING, (val & ~0x0f) | 0x01); |
| 2614 | tmp = snd_ac97_read(ac97, 0x60); |
| 2615 | ac97->spec.dev_flags = tmp & 1; /* revision B? */ |
| 2616 | snd_ac97_write_cache(ac97, AC97_INT_PAGING, val); |
Takashi Iwai | 4525c9f | 2005-09-13 11:47:07 +0200 | [diff] [blame] | 2617 | } else if (ac97->id == AC97_ID_CM9761_83) |
| 2618 | ac97->spec.dev_flags = 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2619 | |
| 2620 | ac97->build_ops = &patch_cm9761_ops; |
| 2621 | |
| 2622 | /* enable spdif */ |
| 2623 | /* force the SPDIF bit in ext_id - codec doesn't set this bit! */ |
| 2624 | ac97->ext_id |= AC97_EI_SPDIF; |
| 2625 | /* to be sure: we overwrite the ext status bits */ |
| 2626 | snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, 0x05c0); |
| 2627 | /* Don't set 0x0200 here. This results in the silent analog output */ |
Takashi Iwai | 5f0dccf | 2005-04-07 15:53:20 +0200 | [diff] [blame] | 2628 | 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] | 2629 | ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */ |
| 2630 | |
| 2631 | /* set-up multi channel */ |
| 2632 | /* bit 15: pc master beep off |
Takashi Iwai | 5f0dccf | 2005-04-07 15:53:20 +0200 | [diff] [blame] | 2633 | * bit 14: pin47 = EAPD/SPDIF |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2634 | * bit 13: vref ctl [= cm9739] |
Takashi Iwai | 5f0dccf | 2005-04-07 15:53:20 +0200 | [diff] [blame] | 2635 | * bit 12: CLFE control (reverted on rev B) |
| 2636 | * bit 11: Mic/center share (reverted on rev B) |
| 2637 | * bit 10: suddound/line share |
| 2638 | * bit 9: Analog-in mix -> surround |
| 2639 | * bit 8: Analog-in mix -> CLFE |
| 2640 | * bit 7: Mic/LFE share (mic/center/lfe) |
| 2641 | * bit 5: vref select (9761A) |
| 2642 | * bit 4: front control |
| 2643 | * bit 3: surround control (revereted with rev B) |
| 2644 | * bit 2: front mic |
| 2645 | * bit 1: stereo mic |
| 2646 | * bit 0: mic boost level (0=20dB, 1=30dB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2647 | */ |
| 2648 | |
| 2649 | #if 0 |
| 2650 | if (ac97->spec.dev_flags) |
| 2651 | val = 0x0214; |
| 2652 | else |
| 2653 | val = 0x321c; |
| 2654 | #endif |
| 2655 | val = snd_ac97_read(ac97, AC97_CM9761_MULTI_CHAN); |
| 2656 | val |= (1 << 4); /* front on */ |
| 2657 | snd_ac97_write_cache(ac97, AC97_CM9761_MULTI_CHAN, val); |
| 2658 | |
| 2659 | /* FIXME: set up GPIO */ |
| 2660 | snd_ac97_write_cache(ac97, 0x70, 0x0100); |
| 2661 | snd_ac97_write_cache(ac97, 0x72, 0x0020); |
| 2662 | |
| 2663 | return 0; |
| 2664 | } |
| 2665 | |
Takashi Iwai | 5f0dccf | 2005-04-07 15:53:20 +0200 | [diff] [blame] | 2666 | #define AC97_CM9780_SIDE 0x60 |
| 2667 | #define AC97_CM9780_JACK 0x62 |
| 2668 | #define AC97_CM9780_MIXER 0x64 |
| 2669 | #define AC97_CM9780_MULTI_CHAN 0x66 |
| 2670 | #define AC97_CM9780_SPDIF 0x6c |
| 2671 | |
| 2672 | static const char *cm9780_ch_select[] = { "Front", "Side", "Center/LFE", "Rear" }; |
| 2673 | static const struct ac97_enum cm9780_ch_select_enum = |
| 2674 | AC97_ENUM_SINGLE(AC97_CM9780_MULTI_CHAN, 6, 4, cm9780_ch_select); |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2675 | static const struct snd_kcontrol_new cm9780_controls[] = { |
Takashi Iwai | 5f0dccf | 2005-04-07 15:53:20 +0200 | [diff] [blame] | 2676 | AC97_DOUBLE("Side Playback Switch", AC97_CM9780_SIDE, 15, 7, 1, 1), |
| 2677 | AC97_DOUBLE("Side Playback Volume", AC97_CM9780_SIDE, 8, 0, 31, 0), |
| 2678 | AC97_ENUM("Side Playback Route", cm9780_ch_select_enum), |
| 2679 | }; |
| 2680 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2681 | static int patch_cm9780_specific(struct snd_ac97 *ac97) |
Takashi Iwai | 5f0dccf | 2005-04-07 15:53:20 +0200 | [diff] [blame] | 2682 | { |
| 2683 | return patch_build_controls(ac97, cm9780_controls, ARRAY_SIZE(cm9780_controls)); |
| 2684 | } |
| 2685 | |
| 2686 | static struct snd_ac97_build_ops patch_cm9780_ops = { |
| 2687 | .build_specific = patch_cm9780_specific, |
| 2688 | .build_post_spdif = patch_cm9761_post_spdif /* identical with CM9761 */ |
| 2689 | }; |
| 2690 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2691 | int patch_cm9780(struct snd_ac97 *ac97) |
Takashi Iwai | 5f0dccf | 2005-04-07 15:53:20 +0200 | [diff] [blame] | 2692 | { |
| 2693 | unsigned short val; |
| 2694 | |
| 2695 | ac97->build_ops = &patch_cm9780_ops; |
| 2696 | |
| 2697 | /* enable spdif */ |
| 2698 | if (ac97->ext_id & AC97_EI_SPDIF) { |
| 2699 | ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */ |
| 2700 | val = snd_ac97_read(ac97, AC97_CM9780_SPDIF); |
| 2701 | val |= 0x1; /* SPDI_EN */ |
| 2702 | snd_ac97_write_cache(ac97, AC97_CM9780_SPDIF, val); |
| 2703 | } |
| 2704 | |
| 2705 | return 0; |
| 2706 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2707 | |
| 2708 | /* |
| 2709 | * VIA VT1616 codec |
| 2710 | */ |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2711 | static const struct snd_kcontrol_new snd_ac97_controls_vt1616[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2712 | AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0), |
| 2713 | AC97_SINGLE("Alternate Level to Surround Out", 0x5a, 15, 1, 0), |
| 2714 | AC97_SINGLE("Downmix LFE and Center to Front", 0x5a, 12, 1, 0), |
| 2715 | AC97_SINGLE("Downmix Surround to Front", 0x5a, 11, 1, 0), |
| 2716 | }; |
| 2717 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2718 | static int patch_vt1616_specific(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2719 | { |
| 2720 | int err; |
| 2721 | |
| 2722 | if (snd_ac97_try_bit(ac97, 0x5a, 9)) |
| 2723 | if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[0], 1)) < 0) |
| 2724 | return err; |
| 2725 | if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[1], ARRAY_SIZE(snd_ac97_controls_vt1616) - 1)) < 0) |
| 2726 | return err; |
| 2727 | return 0; |
| 2728 | } |
| 2729 | |
| 2730 | static struct snd_ac97_build_ops patch_vt1616_ops = { |
| 2731 | .build_specific = patch_vt1616_specific |
| 2732 | }; |
| 2733 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2734 | int patch_vt1616(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2735 | { |
| 2736 | ac97->build_ops = &patch_vt1616_ops; |
| 2737 | return 0; |
| 2738 | } |
| 2739 | |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2740 | /* |
Philip Prindeville | 4b49948 | 2005-08-12 16:46:17 +0200 | [diff] [blame] | 2741 | * VT1617A codec |
| 2742 | */ |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2743 | int patch_vt1617a(struct snd_ac97 * ac97) |
Philip Prindeville | 4b49948 | 2005-08-12 16:46:17 +0200 | [diff] [blame] | 2744 | { |
| 2745 | ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */ |
| 2746 | ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000; |
| 2747 | return 0; |
| 2748 | } |
| 2749 | |
| 2750 | /* |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2751 | */ |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2752 | static void it2646_update_jacks(struct snd_ac97 *ac97) |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2753 | { |
| 2754 | /* shared Line-In */ |
| 2755 | snd_ac97_update_bits(ac97, 0x76, 1 << 9, |
| 2756 | is_shared_linein(ac97) ? (1<<9) : 0); |
| 2757 | /* shared Mic */ |
| 2758 | snd_ac97_update_bits(ac97, 0x76, 1 << 10, |
| 2759 | is_shared_micin(ac97) ? (1<<10) : 0); |
| 2760 | } |
| 2761 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2762 | static const struct snd_kcontrol_new snd_ac97_controls_it2646[] = { |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2763 | AC97_SURROUND_JACK_MODE_CTL, |
| 2764 | AC97_CHANNEL_MODE_CTL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2765 | }; |
| 2766 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2767 | static const struct snd_kcontrol_new snd_ac97_spdif_controls_it2646[] = { |
Clemens Ladisch | 10e8d78 | 2005-08-03 13:40:08 +0200 | [diff] [blame] | 2768 | AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 0x76, 11, 1, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2769 | AC97_SINGLE("Analog to IEC958 Output", 0x76, 12, 1, 0), |
| 2770 | AC97_SINGLE("IEC958 Input Monitor", 0x76, 13, 1, 0), |
| 2771 | }; |
| 2772 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2773 | static int patch_it2646_specific(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2774 | { |
| 2775 | int err; |
| 2776 | if ((err = patch_build_controls(ac97, snd_ac97_controls_it2646, ARRAY_SIZE(snd_ac97_controls_it2646))) < 0) |
| 2777 | return err; |
| 2778 | if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_it2646, ARRAY_SIZE(snd_ac97_spdif_controls_it2646))) < 0) |
| 2779 | return err; |
| 2780 | return 0; |
| 2781 | } |
| 2782 | |
| 2783 | static struct snd_ac97_build_ops patch_it2646_ops = { |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2784 | .build_specific = patch_it2646_specific, |
| 2785 | .update_jacks = it2646_update_jacks |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2786 | }; |
| 2787 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2788 | int patch_it2646(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2789 | { |
| 2790 | ac97->build_ops = &patch_it2646_ops; |
| 2791 | /* full DAC volume */ |
| 2792 | snd_ac97_write_cache(ac97, 0x5E, 0x0808); |
| 2793 | snd_ac97_write_cache(ac97, 0x7A, 0x0808); |
| 2794 | return 0; |
| 2795 | } |
| 2796 | |
Sasha Khapyorsky | 87d61c2 | 2005-05-29 15:08:23 +0200 | [diff] [blame] | 2797 | /* |
| 2798 | * Si3036 codec |
| 2799 | */ |
| 2800 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2801 | #define AC97_SI3036_CHIP_ID 0x5a |
Sasha Khapyorsky | 87d61c2 | 2005-05-29 15:08:23 +0200 | [diff] [blame] | 2802 | #define AC97_SI3036_LINE_CFG 0x5c |
| 2803 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2804 | static const struct snd_kcontrol_new snd_ac97_controls_si3036[] = { |
Sasha Khapyorsky | 87d61c2 | 2005-05-29 15:08:23 +0200 | [diff] [blame] | 2805 | AC97_DOUBLE("Modem Speaker Volume", 0x5c, 14, 12, 3, 1) |
| 2806 | }; |
| 2807 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2808 | static int patch_si3036_specific(struct snd_ac97 * ac97) |
Sasha Khapyorsky | 87d61c2 | 2005-05-29 15:08:23 +0200 | [diff] [blame] | 2809 | { |
Sasha Khapyorsky | 27bcaa6 | 2005-09-13 11:23:13 +0200 | [diff] [blame] | 2810 | int idx, err; |
| 2811 | for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_si3036); idx++) |
| 2812 | if ((err = snd_ctl_add(ac97->bus->card, snd_ctl_new1(&snd_ac97_controls_si3036[idx], ac97))) < 0) |
| 2813 | return err; |
| 2814 | return 0; |
Sasha Khapyorsky | 87d61c2 | 2005-05-29 15:08:23 +0200 | [diff] [blame] | 2815 | } |
| 2816 | |
| 2817 | static struct snd_ac97_build_ops patch_si3036_ops = { |
| 2818 | .build_specific = patch_si3036_specific, |
| 2819 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2820 | |
Takashi Iwai | ee42381 | 2005-11-17 14:21:36 +0100 | [diff] [blame] | 2821 | int mpatch_si3036(struct snd_ac97 * ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2822 | { |
Sasha Khapyorsky | 87d61c2 | 2005-05-29 15:08:23 +0200 | [diff] [blame] | 2823 | ac97->build_ops = &patch_si3036_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2824 | snd_ac97_write_cache(ac97, 0x5c, 0xf210 ); |
| 2825 | snd_ac97_write_cache(ac97, 0x68, 0); |
| 2826 | return 0; |
| 2827 | } |
Charl Coetzee | ba22429 | 2006-02-09 11:48:21 +0100 | [diff] [blame] | 2828 | |
| 2829 | /* |
| 2830 | * LM 4550 Codec |
| 2831 | * |
| 2832 | * We use a static resolution table since LM4550 codec cannot be |
| 2833 | * properly autoprobed to determine the resolution via |
| 2834 | * check_volume_resolution(). |
| 2835 | */ |
| 2836 | |
| 2837 | static struct snd_ac97_res_table lm4550_restbl[] = { |
| 2838 | { AC97_MASTER, 0x1f1f }, |
| 2839 | { AC97_HEADPHONE, 0x1f1f }, |
| 2840 | { AC97_MASTER_MONO, 0x001f }, |
| 2841 | { AC97_PC_BEEP, 0x001f }, /* LSB is ignored */ |
| 2842 | { AC97_PHONE, 0x001f }, |
Charl Coetzee | ba22429 | 2006-02-09 11:48:21 +0100 | [diff] [blame] | 2843 | { AC97_MIC, 0x001f }, |
| 2844 | { AC97_LINE, 0x1f1f }, |
| 2845 | { AC97_CD, 0x1f1f }, |
| 2846 | { AC97_VIDEO, 0x1f1f }, |
| 2847 | { AC97_AUX, 0x1f1f }, |
| 2848 | { AC97_PCM, 0x1f1f }, |
| 2849 | { AC97_REC_GAIN, 0x0f0f }, |
| 2850 | { } /* terminator */ |
| 2851 | }; |
| 2852 | |
| 2853 | int patch_lm4550(struct snd_ac97 *ac97) |
| 2854 | { |
| 2855 | ac97->res_table = lm4550_restbl; |
| 2856 | return 0; |
| 2857 | } |