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