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