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