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 | |
| 373 | int patch_wolfson03(ac97_t * ac97) |
| 374 | { |
| 375 | /* This is known to work for the ViewSonic ViewPad 1000 |
| 376 | Randolph Bentson <bentson@holmsjoen.com> */ |
| 377 | |
| 378 | // WM9703/9707/9708/9717 |
| 379 | snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808); |
| 380 | snd_ac97_write_cache(ac97, AC97_GENERAL_PURPOSE, 0x8000); |
| 381 | return 0; |
| 382 | } |
| 383 | |
| 384 | int patch_wolfson04(ac97_t * ac97) |
| 385 | { |
| 386 | // WM9704M/9704Q |
| 387 | // set front and rear mixer volume |
| 388 | snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808); |
| 389 | snd_ac97_write_cache(ac97, AC97_WM9704_RMIXER_VOL, 0x0808); |
| 390 | |
| 391 | // patch for DVD noise |
| 392 | snd_ac97_write_cache(ac97, AC97_WM9704_TEST, 0x0200); |
| 393 | |
| 394 | // init vol |
| 395 | snd_ac97_write_cache(ac97, AC97_WM9704_RPCM_VOL, 0x0808); |
| 396 | |
| 397 | // set rear surround volume |
| 398 | snd_ac97_write_cache(ac97, AC97_SURROUND_MASTER, 0x0000); |
| 399 | return 0; |
| 400 | } |
| 401 | |
| 402 | int patch_wolfson05(ac97_t * ac97) |
| 403 | { |
| 404 | // WM9705, WM9710 |
| 405 | // set front mixer volume |
| 406 | snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808); |
| 407 | return 0; |
| 408 | } |
| 409 | |
| 410 | int patch_wolfson11(ac97_t * ac97) |
| 411 | { |
| 412 | // WM9711, WM9712 |
| 413 | // set out3 volume |
| 414 | snd_ac97_write_cache(ac97, AC97_WM9711_OUT3VOL, 0x0808); |
| 415 | return 0; |
| 416 | } |
| 417 | |
| 418 | static const char* wm9713_mic_mixer[] = {"Stereo", "Mic1", "Mic2", "Mute"}; |
| 419 | static const char* wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"}; |
| 420 | static const char* wm9713_rec_src_l[] = {"Mic1", "Mic2", "Line L", "Mono In", "HP Mix L", "Spk Mix", "Mono Mix", "Zh"}; |
| 421 | static const char* wm9713_rec_src_r[] = {"Mic1", "Mic2", "Line R", "Mono In", "HP Mix R", "Spk Mix", "Mono Mix", "Zh"}; |
| 422 | |
| 423 | static const struct ac97_enum wm9713_enum[] = { |
| 424 | AC97_ENUM_SINGLE(AC97_LINE, 3, 4, wm9713_mic_mixer), |
| 425 | AC97_ENUM_SINGLE(AC97_VIDEO, 14, 4, wm9713_rec_mux), |
| 426 | AC97_ENUM_SINGLE(AC97_VIDEO, 9, 4, wm9713_rec_mux), |
| 427 | AC97_ENUM_SINGLE(AC97_VIDEO, 3, 8, wm9713_rec_src_l), |
| 428 | AC97_ENUM_SINGLE(AC97_VIDEO, 0, 8, wm9713_rec_src_r), |
| 429 | }; |
| 430 | |
| 431 | static const snd_kcontrol_new_t wm13_snd_ac97_controls_line_in[] = { |
| 432 | AC97_DOUBLE("Line In Volume", AC97_PC_BEEP, 8, 0, 31, 1), |
| 433 | AC97_SINGLE("Line In to Headphone Mute", AC97_PC_BEEP, 15, 1, 1), |
| 434 | AC97_SINGLE("Line In to Speaker Mute", AC97_PC_BEEP, 14, 1, 1), |
| 435 | AC97_SINGLE("Line In to Mono Mute", AC97_PC_BEEP, 13, 1, 1), |
| 436 | }; |
| 437 | |
| 438 | static const snd_kcontrol_new_t wm13_snd_ac97_controls_dac[] = { |
| 439 | AC97_DOUBLE("DAC Volume", AC97_PHONE, 8, 0, 31, 1), |
| 440 | AC97_SINGLE("DAC to Headphone Mute", AC97_PHONE, 15, 1, 1), |
| 441 | AC97_SINGLE("DAC to Speaker Mute", AC97_PHONE, 14, 1, 1), |
| 442 | AC97_SINGLE("DAC to Mono Mute", AC97_PHONE, 13, 1, 1), |
| 443 | }; |
| 444 | |
| 445 | static const snd_kcontrol_new_t wm13_snd_ac97_controls_mic[] = { |
| 446 | AC97_SINGLE("MICA Volume", AC97_MIC, 8, 31, 1), |
| 447 | AC97_SINGLE("MICB Volume", AC97_MIC, 0, 31, 1), |
| 448 | AC97_SINGLE("MICA to Mono Mute", AC97_LINE, 7, 1, 1), |
| 449 | AC97_SINGLE("MICB to Mono Mute", AC97_LINE, 6, 1, 1), |
| 450 | AC97_SINGLE("MIC Boost (+20dB)", AC97_LINE, 5, 1, 1), |
| 451 | AC97_ENUM("MIC Headphone Routing", wm9713_enum[0]), |
| 452 | AC97_SINGLE("MIC Headphone Mixer Volume", AC97_LINE, 0, 7, 1) |
| 453 | }; |
| 454 | |
| 455 | static const snd_kcontrol_new_t wm13_snd_ac97_controls_adc[] = { |
| 456 | AC97_SINGLE("ADC Mute", AC97_CD, 15, 1, 1), |
| 457 | AC97_DOUBLE("Gain Step Size (1.5dB/0.75dB)", AC97_CD, 14, 6, 1, 1), |
| 458 | AC97_DOUBLE("ADC Volume",AC97_CD, 8, 0, 15, 0), |
| 459 | AC97_SINGLE("ADC Zero Cross", AC97_CD, 7, 1, 1), |
| 460 | }; |
| 461 | |
| 462 | static const snd_kcontrol_new_t wm13_snd_ac97_controls_recsel[] = { |
| 463 | AC97_ENUM("Record to Headphone Path", wm9713_enum[1]), |
| 464 | AC97_SINGLE("Record to Headphone Volume", AC97_VIDEO, 11, 7, 0), |
| 465 | AC97_ENUM("Record to Mono Path", wm9713_enum[2]), |
| 466 | AC97_SINGLE("Record to Mono Boost (+20dB)", AC97_VIDEO, 8, 1, 0), |
| 467 | AC97_SINGLE("Record ADC Boost (+20dB)", AC97_VIDEO, 6, 1, 0), |
| 468 | AC97_ENUM("Record Select Left", wm9713_enum[3]), |
| 469 | AC97_ENUM("Record Select Right", wm9713_enum[4]), |
| 470 | }; |
| 471 | |
| 472 | static int patch_wolfson_wm9713_specific(ac97_t * ac97) |
| 473 | { |
| 474 | int err, i; |
| 475 | |
| 476 | for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_line_in); i++) { |
| 477 | if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_line_in[i], ac97))) < 0) |
| 478 | return err; |
| 479 | } |
| 480 | snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808); |
| 481 | |
| 482 | for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_dac); i++) { |
| 483 | if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_dac[i], ac97))) < 0) |
| 484 | return err; |
| 485 | } |
| 486 | snd_ac97_write_cache(ac97, AC97_PHONE, 0x0808); |
| 487 | |
| 488 | for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_mic); i++) { |
| 489 | if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_mic[i], ac97))) < 0) |
| 490 | return err; |
| 491 | } |
| 492 | snd_ac97_write_cache(ac97, AC97_MIC, 0x0808); |
| 493 | snd_ac97_write_cache(ac97, AC97_LINE, 0x00da); |
| 494 | |
| 495 | for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_adc); i++) { |
| 496 | if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_adc[i], ac97))) < 0) |
| 497 | return err; |
| 498 | } |
| 499 | snd_ac97_write_cache(ac97, AC97_CD, 0x0808); |
| 500 | |
| 501 | for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_recsel); i++) { |
| 502 | if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_recsel[i], ac97))) < 0) |
| 503 | return err; |
| 504 | } |
| 505 | snd_ac97_write_cache(ac97, AC97_VIDEO, 0xd612); |
| 506 | snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x1ba0); |
| 507 | |
| 508 | return 0; |
| 509 | } |
| 510 | |
| 511 | #ifdef CONFIG_PM |
| 512 | static void patch_wolfson_wm9713_suspend (ac97_t * ac97) |
| 513 | { |
| 514 | snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xfeff); |
| 515 | snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0xffff); |
| 516 | } |
| 517 | |
| 518 | static void patch_wolfson_wm9713_resume (ac97_t * ac97) |
| 519 | { |
| 520 | snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00); |
| 521 | snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810); |
| 522 | snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0); |
| 523 | } |
| 524 | #endif |
| 525 | |
| 526 | static struct snd_ac97_build_ops patch_wolfson_wm9713_ops = { |
| 527 | .build_specific = patch_wolfson_wm9713_specific, |
| 528 | #ifdef CONFIG_PM |
| 529 | .suspend = patch_wolfson_wm9713_suspend, |
| 530 | .resume = patch_wolfson_wm9713_resume |
| 531 | #endif |
| 532 | }; |
| 533 | |
| 534 | int patch_wolfson13(ac97_t * ac97) |
| 535 | { |
| 536 | ac97->build_ops = &patch_wolfson_wm9713_ops; |
| 537 | |
| 538 | ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_PHONE | |
| 539 | AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD; |
| 540 | |
| 541 | snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00); |
| 542 | snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810); |
| 543 | snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0); |
| 544 | |
| 545 | return 0; |
| 546 | } |
| 547 | |
| 548 | /* |
| 549 | * Tritech codec |
| 550 | */ |
| 551 | int patch_tritech_tr28028(ac97_t * ac97) |
| 552 | { |
| 553 | snd_ac97_write_cache(ac97, 0x26, 0x0300); |
| 554 | snd_ac97_write_cache(ac97, 0x26, 0x0000); |
| 555 | snd_ac97_write_cache(ac97, AC97_SURROUND_MASTER, 0x0000); |
| 556 | snd_ac97_write_cache(ac97, AC97_SPDIF, 0x0000); |
| 557 | return 0; |
| 558 | } |
| 559 | |
| 560 | /* |
| 561 | * Sigmatel STAC97xx codecs |
| 562 | */ |
| 563 | static int patch_sigmatel_stac9700_3d(ac97_t * ac97) |
| 564 | { |
| 565 | snd_kcontrol_t *kctl; |
| 566 | int err; |
| 567 | |
| 568 | if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0) |
| 569 | return err; |
| 570 | strcpy(kctl->id.name, "3D Control Sigmatel - Depth"); |
| 571 | kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0); |
| 572 | snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000); |
| 573 | return 0; |
| 574 | } |
| 575 | |
| 576 | static int patch_sigmatel_stac9708_3d(ac97_t * ac97) |
| 577 | { |
| 578 | snd_kcontrol_t *kctl; |
| 579 | int err; |
| 580 | |
| 581 | if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0) |
| 582 | return err; |
| 583 | strcpy(kctl->id.name, "3D Control Sigmatel - Depth"); |
| 584 | kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 0, 3, 0); |
| 585 | if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0) |
| 586 | return err; |
| 587 | strcpy(kctl->id.name, "3D Control Sigmatel - Rear Depth"); |
| 588 | kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0); |
| 589 | snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000); |
| 590 | return 0; |
| 591 | } |
| 592 | |
| 593 | static const snd_kcontrol_new_t snd_ac97_sigmatel_4speaker = |
| 594 | AC97_SINGLE("Sigmatel 4-Speaker Stereo Playback Switch", AC97_SIGMATEL_DAC2INVERT, 2, 1, 0); |
| 595 | |
| 596 | static const snd_kcontrol_new_t snd_ac97_sigmatel_phaseinvert = |
| 597 | AC97_SINGLE("Sigmatel Surround Phase Inversion Playback Switch", AC97_SIGMATEL_DAC2INVERT, 3, 1, 0); |
| 598 | |
| 599 | static const snd_kcontrol_new_t snd_ac97_sigmatel_controls[] = { |
| 600 | AC97_SINGLE("Sigmatel DAC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 1, 1, 0), |
| 601 | AC97_SINGLE("Sigmatel ADC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 0, 1, 0) |
| 602 | }; |
| 603 | |
| 604 | static int patch_sigmatel_stac97xx_specific(ac97_t * ac97) |
| 605 | { |
| 606 | int err; |
| 607 | |
| 608 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_ANALOG, snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) & ~0x0003); |
| 609 | if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 1)) |
| 610 | if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[0], 1)) < 0) |
| 611 | return err; |
| 612 | if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 0)) |
| 613 | if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[1], 1)) < 0) |
| 614 | return err; |
| 615 | if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 2)) |
| 616 | if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_4speaker, 1)) < 0) |
| 617 | return err; |
| 618 | if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 3)) |
| 619 | if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_phaseinvert, 1)) < 0) |
| 620 | return err; |
| 621 | return 0; |
| 622 | } |
| 623 | |
| 624 | static struct snd_ac97_build_ops patch_sigmatel_stac9700_ops = { |
| 625 | .build_3d = patch_sigmatel_stac9700_3d, |
| 626 | .build_specific = patch_sigmatel_stac97xx_specific |
| 627 | }; |
| 628 | |
| 629 | int patch_sigmatel_stac9700(ac97_t * ac97) |
| 630 | { |
| 631 | ac97->build_ops = &patch_sigmatel_stac9700_ops; |
| 632 | return 0; |
| 633 | } |
| 634 | |
| 635 | static int snd_ac97_stac9708_put_bias(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) |
| 636 | { |
| 637 | ac97_t *ac97 = snd_kcontrol_chip(kcontrol); |
| 638 | int err; |
| 639 | |
| 640 | down(&ac97->page_mutex); |
| 641 | snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0xabba); |
| 642 | err = snd_ac97_update_bits(ac97, AC97_SIGMATEL_BIAS2, 0x0010, |
| 643 | (ucontrol->value.integer.value[0] & 1) << 4); |
| 644 | snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0); |
| 645 | up(&ac97->page_mutex); |
| 646 | return err; |
| 647 | } |
| 648 | |
| 649 | static const snd_kcontrol_new_t snd_ac97_stac9708_bias_control = { |
| 650 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 651 | .name = "Sigmatel Output Bias Switch", |
| 652 | .info = snd_ac97_info_volsw, |
| 653 | .get = snd_ac97_get_volsw, |
| 654 | .put = snd_ac97_stac9708_put_bias, |
| 655 | .private_value = AC97_SINGLE_VALUE(AC97_SIGMATEL_BIAS2, 4, 1, 0), |
| 656 | }; |
| 657 | |
| 658 | static int patch_sigmatel_stac9708_specific(ac97_t *ac97) |
| 659 | { |
| 660 | int err; |
| 661 | |
| 662 | snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Sigmatel Surround Playback"); |
| 663 | if ((err = patch_build_controls(ac97, &snd_ac97_stac9708_bias_control, 1)) < 0) |
| 664 | return err; |
| 665 | return patch_sigmatel_stac97xx_specific(ac97); |
| 666 | } |
| 667 | |
| 668 | static struct snd_ac97_build_ops patch_sigmatel_stac9708_ops = { |
| 669 | .build_3d = patch_sigmatel_stac9708_3d, |
| 670 | .build_specific = patch_sigmatel_stac9708_specific |
| 671 | }; |
| 672 | |
| 673 | int patch_sigmatel_stac9708(ac97_t * ac97) |
| 674 | { |
| 675 | unsigned int codec72, codec6c; |
| 676 | |
| 677 | ac97->build_ops = &patch_sigmatel_stac9708_ops; |
| 678 | ac97->caps |= 0x10; /* HP (sigmatel surround) support */ |
| 679 | |
| 680 | codec72 = snd_ac97_read(ac97, AC97_SIGMATEL_BIAS2) & 0x8000; |
| 681 | codec6c = snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG); |
| 682 | |
| 683 | if ((codec72==0) && (codec6c==0)) { |
| 684 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); |
| 685 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1000); |
| 686 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba); |
| 687 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0007); |
| 688 | } else if ((codec72==0x8000) && (codec6c==0)) { |
| 689 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); |
| 690 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1001); |
| 691 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_DAC2INVERT, 0x0008); |
| 692 | } else if ((codec72==0x8000) && (codec6c==0x0080)) { |
| 693 | /* nothing */ |
| 694 | } |
| 695 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000); |
| 696 | return 0; |
| 697 | } |
| 698 | |
| 699 | int patch_sigmatel_stac9721(ac97_t * ac97) |
| 700 | { |
| 701 | ac97->build_ops = &patch_sigmatel_stac9700_ops; |
| 702 | if (snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) == 0) { |
| 703 | // patch for SigmaTel |
| 704 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); |
| 705 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x4000); |
| 706 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba); |
| 707 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002); |
| 708 | } |
| 709 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000); |
| 710 | return 0; |
| 711 | } |
| 712 | |
| 713 | int patch_sigmatel_stac9744(ac97_t * ac97) |
| 714 | { |
| 715 | // patch for SigmaTel |
| 716 | ac97->build_ops = &patch_sigmatel_stac9700_ops; |
| 717 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); |
| 718 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */ |
| 719 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba); |
| 720 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002); |
| 721 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000); |
| 722 | return 0; |
| 723 | } |
| 724 | |
| 725 | int patch_sigmatel_stac9756(ac97_t * ac97) |
| 726 | { |
| 727 | // patch for SigmaTel |
| 728 | ac97->build_ops = &patch_sigmatel_stac9700_ops; |
| 729 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba); |
| 730 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */ |
| 731 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba); |
| 732 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002); |
| 733 | snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000); |
| 734 | return 0; |
| 735 | } |
| 736 | |
| 737 | static int snd_ac97_stac9758_output_jack_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo) |
| 738 | { |
| 739 | static char *texts[5] = { "Input/Disabled", "Front Output", |
| 740 | "Rear Output", "Center/LFE Output", "Mixer Output" }; |
| 741 | |
| 742 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 743 | uinfo->count = 1; |
| 744 | uinfo->value.enumerated.items = 5; |
| 745 | if (uinfo->value.enumerated.item > 4) |
| 746 | uinfo->value.enumerated.item = 4; |
| 747 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); |
| 748 | return 0; |
| 749 | } |
| 750 | |
| 751 | static int snd_ac97_stac9758_output_jack_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol) |
| 752 | { |
| 753 | ac97_t *ac97 = snd_kcontrol_chip(kcontrol); |
| 754 | int shift = kcontrol->private_value; |
| 755 | unsigned short val; |
| 756 | |
| 757 | val = ac97->regs[AC97_SIGMATEL_OUTSEL] >> shift; |
| 758 | if (!(val & 4)) |
| 759 | ucontrol->value.enumerated.item[0] = 0; |
| 760 | else |
| 761 | ucontrol->value.enumerated.item[0] = 1 + (val & 3); |
| 762 | return 0; |
| 763 | } |
| 764 | |
| 765 | static int snd_ac97_stac9758_output_jack_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) |
| 766 | { |
| 767 | ac97_t *ac97 = snd_kcontrol_chip(kcontrol); |
| 768 | int shift = kcontrol->private_value; |
| 769 | unsigned short val; |
| 770 | |
| 771 | if (ucontrol->value.enumerated.item[0] > 4) |
| 772 | return -EINVAL; |
| 773 | if (ucontrol->value.enumerated.item[0] == 0) |
| 774 | val = 0; |
| 775 | else |
| 776 | val = 4 | (ucontrol->value.enumerated.item[0] - 1); |
| 777 | return ac97_update_bits_page(ac97, AC97_SIGMATEL_OUTSEL, |
| 778 | 7 << shift, val << shift, 0); |
| 779 | } |
| 780 | |
| 781 | static int snd_ac97_stac9758_input_jack_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo) |
| 782 | { |
| 783 | static char *texts[7] = { "Mic2 Jack", "Mic1 Jack", "Line In Jack", |
| 784 | "Front Jack", "Rear Jack", "Center/LFE Jack", "Mute" }; |
| 785 | |
| 786 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 787 | uinfo->count = 1; |
| 788 | uinfo->value.enumerated.items = 7; |
| 789 | if (uinfo->value.enumerated.item > 6) |
| 790 | uinfo->value.enumerated.item = 6; |
| 791 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); |
| 792 | return 0; |
| 793 | } |
| 794 | |
| 795 | static int snd_ac97_stac9758_input_jack_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol) |
| 796 | { |
| 797 | ac97_t *ac97 = snd_kcontrol_chip(kcontrol); |
| 798 | int shift = kcontrol->private_value; |
| 799 | unsigned short val; |
| 800 | |
| 801 | val = ac97->regs[AC97_SIGMATEL_INSEL]; |
| 802 | ucontrol->value.enumerated.item[0] = (val >> shift) & 7; |
| 803 | return 0; |
| 804 | } |
| 805 | |
| 806 | static int snd_ac97_stac9758_input_jack_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) |
| 807 | { |
| 808 | ac97_t *ac97 = snd_kcontrol_chip(kcontrol); |
| 809 | int shift = kcontrol->private_value; |
| 810 | |
| 811 | return ac97_update_bits_page(ac97, AC97_SIGMATEL_INSEL, 7 << shift, |
| 812 | ucontrol->value.enumerated.item[0] << shift, 0); |
| 813 | } |
| 814 | |
| 815 | static int snd_ac97_stac9758_phonesel_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo) |
| 816 | { |
| 817 | static char *texts[3] = { "None", "Front Jack", "Rear Jack" }; |
| 818 | |
| 819 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 820 | uinfo->count = 1; |
| 821 | uinfo->value.enumerated.items = 3; |
| 822 | if (uinfo->value.enumerated.item > 2) |
| 823 | uinfo->value.enumerated.item = 2; |
| 824 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); |
| 825 | return 0; |
| 826 | } |
| 827 | |
| 828 | static int snd_ac97_stac9758_phonesel_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol) |
| 829 | { |
| 830 | ac97_t *ac97 = snd_kcontrol_chip(kcontrol); |
| 831 | |
| 832 | ucontrol->value.enumerated.item[0] = ac97->regs[AC97_SIGMATEL_IOMISC] & 3; |
| 833 | return 0; |
| 834 | } |
| 835 | |
| 836 | static int snd_ac97_stac9758_phonesel_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) |
| 837 | { |
| 838 | ac97_t *ac97 = snd_kcontrol_chip(kcontrol); |
| 839 | |
| 840 | return ac97_update_bits_page(ac97, AC97_SIGMATEL_IOMISC, 3, |
| 841 | ucontrol->value.enumerated.item[0], 0); |
| 842 | } |
| 843 | |
| 844 | #define STAC9758_OUTPUT_JACK(xname, shift) \ |
| 845 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ |
| 846 | .info = snd_ac97_stac9758_output_jack_info, \ |
| 847 | .get = snd_ac97_stac9758_output_jack_get, \ |
| 848 | .put = snd_ac97_stac9758_output_jack_put, \ |
| 849 | .private_value = shift } |
| 850 | #define STAC9758_INPUT_JACK(xname, shift) \ |
| 851 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ |
| 852 | .info = snd_ac97_stac9758_input_jack_info, \ |
| 853 | .get = snd_ac97_stac9758_input_jack_get, \ |
| 854 | .put = snd_ac97_stac9758_input_jack_put, \ |
| 855 | .private_value = shift } |
| 856 | static const snd_kcontrol_new_t snd_ac97_sigmatel_stac9758_controls[] = { |
| 857 | STAC9758_OUTPUT_JACK("Mic1 Jack", 1), |
| 858 | STAC9758_OUTPUT_JACK("LineIn Jack", 4), |
| 859 | STAC9758_OUTPUT_JACK("Front Jack", 7), |
| 860 | STAC9758_OUTPUT_JACK("Rear Jack", 10), |
| 861 | STAC9758_OUTPUT_JACK("Center/LFE Jack", 13), |
| 862 | STAC9758_INPUT_JACK("Mic Input Source", 0), |
| 863 | STAC9758_INPUT_JACK("Line Input Source", 8), |
| 864 | { |
| 865 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 866 | .name = "Headphone Amp", |
| 867 | .info = snd_ac97_stac9758_phonesel_info, |
| 868 | .get = snd_ac97_stac9758_phonesel_get, |
| 869 | .put = snd_ac97_stac9758_phonesel_put |
| 870 | }, |
| 871 | AC97_SINGLE("Exchange Center/LFE", AC97_SIGMATEL_IOMISC, 4, 1, 0), |
| 872 | AC97_SINGLE("Headphone +3dB Boost", AC97_SIGMATEL_IOMISC, 8, 1, 0) |
| 873 | }; |
| 874 | |
| 875 | static int patch_sigmatel_stac9758_specific(ac97_t *ac97) |
| 876 | { |
| 877 | int err; |
| 878 | |
| 879 | err = patch_sigmatel_stac97xx_specific(ac97); |
| 880 | if (err < 0) |
| 881 | return err; |
| 882 | err = patch_build_controls(ac97, snd_ac97_sigmatel_stac9758_controls, |
| 883 | ARRAY_SIZE(snd_ac97_sigmatel_stac9758_controls)); |
| 884 | if (err < 0) |
| 885 | return err; |
| 886 | /* DAC-A direct */ |
| 887 | snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Front Playback"); |
| 888 | /* DAC-A to Mix = PCM */ |
| 889 | /* DAC-B direct = Surround */ |
| 890 | /* DAC-B to Mix */ |
| 891 | snd_ac97_rename_vol_ctl(ac97, "Video Playback", "Surround Mix Playback"); |
| 892 | /* DAC-C direct = Center/LFE */ |
| 893 | |
| 894 | return 0; |
| 895 | } |
| 896 | |
| 897 | static struct snd_ac97_build_ops patch_sigmatel_stac9758_ops = { |
| 898 | .build_3d = patch_sigmatel_stac9700_3d, |
| 899 | .build_specific = patch_sigmatel_stac9758_specific |
| 900 | }; |
| 901 | |
| 902 | int patch_sigmatel_stac9758(ac97_t * ac97) |
| 903 | { |
| 904 | static unsigned short regs[4] = { |
| 905 | AC97_SIGMATEL_OUTSEL, |
| 906 | AC97_SIGMATEL_IOMISC, |
| 907 | AC97_SIGMATEL_INSEL, |
| 908 | AC97_SIGMATEL_VARIOUS |
| 909 | }; |
| 910 | static unsigned short def_regs[4] = { |
| 911 | /* OUTSEL */ 0xd794, /* CL:CL, SR:SR, LO:MX, LI:DS, MI:DS */ |
| 912 | /* IOMISC */ 0x2001, |
| 913 | /* INSEL */ 0x0201, /* LI:LI, MI:M1 */ |
| 914 | /* VARIOUS */ 0x0040 |
| 915 | }; |
| 916 | static unsigned short m675_regs[4] = { |
| 917 | /* OUTSEL */ 0xfc70, /* CL:MX, SR:MX, LO:DS, LI:MX, MI:DS */ |
| 918 | /* IOMISC */ 0x2102, /* HP amp on */ |
| 919 | /* INSEL */ 0x0203, /* LI:LI, MI:FR */ |
| 920 | /* VARIOUS */ 0x0041 /* stereo mic */ |
| 921 | }; |
| 922 | unsigned short *pregs = def_regs; |
| 923 | int i; |
| 924 | |
| 925 | /* Gateway M675 notebook */ |
| 926 | if (ac97->pci && |
| 927 | ac97->subsystem_vendor == 0x107b && |
| 928 | ac97->subsystem_device == 0x0601) |
| 929 | pregs = m675_regs; |
| 930 | |
| 931 | // patch for SigmaTel |
| 932 | ac97->build_ops = &patch_sigmatel_stac9758_ops; |
| 933 | /* FIXME: assume only page 0 for writing cache */ |
| 934 | snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR); |
| 935 | for (i = 0; i < 4; i++) |
| 936 | snd_ac97_write_cache(ac97, regs[i], pregs[i]); |
| 937 | |
| 938 | ac97->flags |= AC97_STEREO_MUTES; |
| 939 | return 0; |
| 940 | } |
| 941 | |
| 942 | /* |
| 943 | * Cirrus Logic CS42xx codecs |
| 944 | */ |
| 945 | static const snd_kcontrol_new_t snd_ac97_cirrus_controls_spdif[2] = { |
| 946 | AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CSR_SPDIF, 15, 1, 0), |
| 947 | AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "AC97-SPSA", AC97_CSR_ACMODE, 0, 3, 0) |
| 948 | }; |
| 949 | |
| 950 | static int patch_cirrus_build_spdif(ac97_t * ac97) |
| 951 | { |
| 952 | int err; |
| 953 | |
| 954 | /* con mask, pro mask, default */ |
| 955 | if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0) |
| 956 | return err; |
| 957 | /* switch, spsa */ |
| 958 | if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[0], 1)) < 0) |
| 959 | return err; |
| 960 | switch (ac97->id & AC97_ID_CS_MASK) { |
| 961 | case AC97_ID_CS4205: |
| 962 | if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[1], 1)) < 0) |
| 963 | return err; |
| 964 | break; |
| 965 | } |
| 966 | /* set default PCM S/PDIF params */ |
| 967 | /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */ |
| 968 | snd_ac97_write_cache(ac97, AC97_CSR_SPDIF, 0x0a20); |
| 969 | return 0; |
| 970 | } |
| 971 | |
| 972 | static struct snd_ac97_build_ops patch_cirrus_ops = { |
| 973 | .build_spdif = patch_cirrus_build_spdif |
| 974 | }; |
| 975 | |
| 976 | int patch_cirrus_spdif(ac97_t * ac97) |
| 977 | { |
| 978 | /* Basically, the cs4201/cs4205/cs4297a has non-standard sp/dif registers. |
| 979 | WHY CAN'T ANYONE FOLLOW THE BLOODY SPEC? *sigh* |
| 980 | - sp/dif EA ID is not set, but sp/dif is always present. |
| 981 | - enable/disable is spdif register bit 15. |
| 982 | - sp/dif control register is 0x68. differs from AC97: |
| 983 | - valid is bit 14 (vs 15) |
| 984 | - no DRS |
| 985 | - only 44.1/48k [00 = 48, 01=44,1] (AC97 is 00=44.1, 10=48) |
| 986 | - sp/dif ssource select is in 0x5e bits 0,1. |
| 987 | */ |
| 988 | |
| 989 | ac97->build_ops = &patch_cirrus_ops; |
| 990 | ac97->flags |= AC97_CS_SPDIF; |
| 991 | ac97->rates[AC97_RATES_SPDIF] &= ~SNDRV_PCM_RATE_32000; |
| 992 | ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */ |
| 993 | snd_ac97_write_cache(ac97, AC97_CSR_ACMODE, 0x0080); |
| 994 | return 0; |
| 995 | } |
| 996 | |
| 997 | int patch_cirrus_cs4299(ac97_t * ac97) |
| 998 | { |
| 999 | /* force the detection of PC Beep */ |
| 1000 | ac97->flags |= AC97_HAS_PC_BEEP; |
| 1001 | |
| 1002 | return patch_cirrus_spdif(ac97); |
| 1003 | } |
| 1004 | |
| 1005 | /* |
| 1006 | * Conexant codecs |
| 1007 | */ |
| 1008 | static const snd_kcontrol_new_t snd_ac97_conexant_controls_spdif[1] = { |
| 1009 | AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CXR_AUDIO_MISC, 3, 1, 0), |
| 1010 | }; |
| 1011 | |
| 1012 | static int patch_conexant_build_spdif(ac97_t * ac97) |
| 1013 | { |
| 1014 | int err; |
| 1015 | |
| 1016 | /* con mask, pro mask, default */ |
| 1017 | if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0) |
| 1018 | return err; |
| 1019 | /* switch */ |
| 1020 | if ((err = patch_build_controls(ac97, &snd_ac97_conexant_controls_spdif[0], 1)) < 0) |
| 1021 | return err; |
| 1022 | /* set default PCM S/PDIF params */ |
| 1023 | /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */ |
| 1024 | snd_ac97_write_cache(ac97, AC97_CXR_AUDIO_MISC, |
| 1025 | snd_ac97_read(ac97, AC97_CXR_AUDIO_MISC) & ~(AC97_CXR_SPDIFEN|AC97_CXR_COPYRGT|AC97_CXR_SPDIF_MASK)); |
| 1026 | return 0; |
| 1027 | } |
| 1028 | |
| 1029 | static struct snd_ac97_build_ops patch_conexant_ops = { |
| 1030 | .build_spdif = patch_conexant_build_spdif |
| 1031 | }; |
| 1032 | |
| 1033 | int patch_conexant(ac97_t * ac97) |
| 1034 | { |
| 1035 | ac97->build_ops = &patch_conexant_ops; |
| 1036 | ac97->flags |= AC97_CX_SPDIF; |
| 1037 | ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */ |
| 1038 | ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */ |
| 1039 | return 0; |
| 1040 | } |
| 1041 | |
| 1042 | /* |
| 1043 | * Analog Device AD18xx, AD19xx codecs |
| 1044 | */ |
| 1045 | #ifdef CONFIG_PM |
| 1046 | static void ad18xx_resume(ac97_t *ac97) |
| 1047 | { |
| 1048 | static unsigned short setup_regs[] = { |
| 1049 | AC97_AD_MISC, AC97_AD_SERIAL_CFG, AC97_AD_JACK_SPDIF, |
| 1050 | }; |
| 1051 | int i, codec; |
| 1052 | |
| 1053 | for (i = 0; i < (int)ARRAY_SIZE(setup_regs); i++) { |
| 1054 | unsigned short reg = setup_regs[i]; |
| 1055 | if (test_bit(reg, ac97->reg_accessed)) { |
| 1056 | snd_ac97_write(ac97, reg, ac97->regs[reg]); |
| 1057 | snd_ac97_read(ac97, reg); |
| 1058 | } |
| 1059 | } |
| 1060 | |
| 1061 | if (! (ac97->flags & AC97_AD_MULTI)) |
| 1062 | /* normal restore */ |
| 1063 | snd_ac97_restore_status(ac97); |
| 1064 | else { |
| 1065 | /* restore the AD18xx codec configurations */ |
| 1066 | for (codec = 0; codec < 3; codec++) { |
| 1067 | if (! ac97->spec.ad18xx.id[codec]) |
| 1068 | continue; |
| 1069 | /* select single codec */ |
| 1070 | snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, |
| 1071 | ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]); |
| 1072 | ac97->bus->ops->write(ac97, AC97_AD_CODEC_CFG, ac97->spec.ad18xx.codec_cfg[codec]); |
| 1073 | } |
| 1074 | /* select all codecs */ |
| 1075 | snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000); |
| 1076 | |
| 1077 | /* restore status */ |
| 1078 | for (i = 2; i < 0x7c ; i += 2) { |
| 1079 | if (i == AC97_POWERDOWN || i == AC97_EXTENDED_ID) |
| 1080 | continue; |
| 1081 | if (test_bit(i, ac97->reg_accessed)) { |
| 1082 | /* handle multi codecs for AD18xx */ |
| 1083 | if (i == AC97_PCM) { |
| 1084 | for (codec = 0; codec < 3; codec++) { |
| 1085 | if (! ac97->spec.ad18xx.id[codec]) |
| 1086 | continue; |
| 1087 | /* select single codec */ |
| 1088 | snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, |
| 1089 | ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]); |
| 1090 | /* update PCM bits */ |
| 1091 | ac97->bus->ops->write(ac97, AC97_PCM, ac97->spec.ad18xx.pcmreg[codec]); |
| 1092 | } |
| 1093 | /* select all codecs */ |
| 1094 | snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000); |
| 1095 | continue; |
| 1096 | } else if (i == AC97_AD_TEST || |
| 1097 | i == AC97_AD_CODEC_CFG || |
| 1098 | i == AC97_AD_SERIAL_CFG) |
| 1099 | continue; /* ignore */ |
| 1100 | } |
| 1101 | snd_ac97_write(ac97, i, ac97->regs[i]); |
| 1102 | snd_ac97_read(ac97, i); |
| 1103 | } |
| 1104 | } |
| 1105 | |
| 1106 | snd_ac97_restore_iec958(ac97); |
| 1107 | } |
| 1108 | #endif |
| 1109 | |
| 1110 | int patch_ad1819(ac97_t * ac97) |
| 1111 | { |
| 1112 | unsigned short scfg; |
| 1113 | |
| 1114 | // patch for Analog Devices |
| 1115 | scfg = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG); |
| 1116 | snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, scfg | 0x7000); /* select all codecs */ |
| 1117 | return 0; |
| 1118 | } |
| 1119 | |
| 1120 | static unsigned short patch_ad1881_unchained(ac97_t * ac97, int idx, unsigned short mask) |
| 1121 | { |
| 1122 | unsigned short val; |
| 1123 | |
| 1124 | // test for unchained codec |
| 1125 | snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, mask); |
| 1126 | snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000); /* ID0C, ID1C, SDIE = off */ |
| 1127 | val = snd_ac97_read(ac97, AC97_VENDOR_ID2); |
| 1128 | if ((val & 0xff40) != 0x5340) |
| 1129 | return 0; |
| 1130 | ac97->spec.ad18xx.unchained[idx] = mask; |
| 1131 | ac97->spec.ad18xx.id[idx] = val; |
| 1132 | ac97->spec.ad18xx.codec_cfg[idx] = 0x0000; |
| 1133 | return mask; |
| 1134 | } |
| 1135 | |
| 1136 | static int patch_ad1881_chained1(ac97_t * ac97, int idx, unsigned short codec_bits) |
| 1137 | { |
| 1138 | static int cfg_bits[3] = { 1<<12, 1<<14, 1<<13 }; |
| 1139 | unsigned short val; |
| 1140 | |
| 1141 | snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, cfg_bits[idx]); |
| 1142 | snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0004); // SDIE |
| 1143 | val = snd_ac97_read(ac97, AC97_VENDOR_ID2); |
| 1144 | if ((val & 0xff40) != 0x5340) |
| 1145 | return 0; |
| 1146 | if (codec_bits) |
| 1147 | snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, codec_bits); |
| 1148 | ac97->spec.ad18xx.chained[idx] = cfg_bits[idx]; |
| 1149 | ac97->spec.ad18xx.id[idx] = val; |
| 1150 | ac97->spec.ad18xx.codec_cfg[idx] = codec_bits ? codec_bits : 0x0004; |
| 1151 | return 1; |
| 1152 | } |
| 1153 | |
| 1154 | static void patch_ad1881_chained(ac97_t * ac97, int unchained_idx, int cidx1, int cidx2) |
| 1155 | { |
| 1156 | // already detected? |
| 1157 | if (ac97->spec.ad18xx.unchained[cidx1] || ac97->spec.ad18xx.chained[cidx1]) |
| 1158 | cidx1 = -1; |
| 1159 | if (ac97->spec.ad18xx.unchained[cidx2] || ac97->spec.ad18xx.chained[cidx2]) |
| 1160 | cidx2 = -1; |
| 1161 | if (cidx1 < 0 && cidx2 < 0) |
| 1162 | return; |
| 1163 | // test for chained codecs |
| 1164 | snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, |
| 1165 | ac97->spec.ad18xx.unchained[unchained_idx]); |
| 1166 | snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0002); // ID1C |
| 1167 | ac97->spec.ad18xx.codec_cfg[unchained_idx] = 0x0002; |
| 1168 | if (cidx1 >= 0) { |
| 1169 | if (patch_ad1881_chained1(ac97, cidx1, 0x0006)) // SDIE | ID1C |
| 1170 | patch_ad1881_chained1(ac97, cidx2, 0); |
| 1171 | else if (patch_ad1881_chained1(ac97, cidx2, 0x0006)) // SDIE | ID1C |
| 1172 | patch_ad1881_chained1(ac97, cidx1, 0); |
| 1173 | } else if (cidx2 >= 0) { |
| 1174 | patch_ad1881_chained1(ac97, cidx2, 0); |
| 1175 | } |
| 1176 | } |
| 1177 | |
| 1178 | static struct snd_ac97_build_ops patch_ad1881_build_ops = { |
| 1179 | #ifdef CONFIG_PM |
| 1180 | .resume = ad18xx_resume |
| 1181 | #endif |
| 1182 | }; |
| 1183 | |
| 1184 | int patch_ad1881(ac97_t * ac97) |
| 1185 | { |
| 1186 | static const char cfg_idxs[3][2] = { |
| 1187 | {2, 1}, |
| 1188 | {0, 2}, |
| 1189 | {0, 1} |
| 1190 | }; |
| 1191 | |
| 1192 | // patch for Analog Devices |
| 1193 | unsigned short codecs[3]; |
| 1194 | unsigned short val; |
| 1195 | int idx, num; |
| 1196 | |
| 1197 | val = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG); |
| 1198 | snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, val); |
| 1199 | codecs[0] = patch_ad1881_unchained(ac97, 0, (1<<12)); |
| 1200 | codecs[1] = patch_ad1881_unchained(ac97, 1, (1<<14)); |
| 1201 | codecs[2] = patch_ad1881_unchained(ac97, 2, (1<<13)); |
| 1202 | |
| 1203 | snd_runtime_check(codecs[0] | codecs[1] | codecs[2], goto __end); |
| 1204 | |
| 1205 | for (idx = 0; idx < 3; idx++) |
| 1206 | if (ac97->spec.ad18xx.unchained[idx]) |
| 1207 | patch_ad1881_chained(ac97, idx, cfg_idxs[idx][0], cfg_idxs[idx][1]); |
| 1208 | |
| 1209 | if (ac97->spec.ad18xx.id[1]) { |
| 1210 | ac97->flags |= AC97_AD_MULTI; |
| 1211 | ac97->scaps |= AC97_SCAP_SURROUND_DAC; |
| 1212 | } |
| 1213 | if (ac97->spec.ad18xx.id[2]) { |
| 1214 | ac97->flags |= AC97_AD_MULTI; |
| 1215 | ac97->scaps |= AC97_SCAP_CENTER_LFE_DAC; |
| 1216 | } |
| 1217 | |
| 1218 | __end: |
| 1219 | /* select all codecs */ |
| 1220 | snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000); |
| 1221 | /* check if only one codec is present */ |
| 1222 | for (idx = num = 0; idx < 3; idx++) |
| 1223 | if (ac97->spec.ad18xx.id[idx]) |
| 1224 | num++; |
| 1225 | if (num == 1) { |
| 1226 | /* ok, deselect all ID bits */ |
| 1227 | snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000); |
| 1228 | ac97->spec.ad18xx.codec_cfg[0] = |
| 1229 | ac97->spec.ad18xx.codec_cfg[1] = |
| 1230 | ac97->spec.ad18xx.codec_cfg[2] = 0x0000; |
| 1231 | } |
| 1232 | /* required for AD1886/AD1885 combination */ |
| 1233 | ac97->ext_id = snd_ac97_read(ac97, AC97_EXTENDED_ID); |
| 1234 | if (ac97->spec.ad18xx.id[0]) { |
| 1235 | ac97->id &= 0xffff0000; |
| 1236 | ac97->id |= ac97->spec.ad18xx.id[0]; |
| 1237 | } |
| 1238 | ac97->build_ops = &patch_ad1881_build_ops; |
| 1239 | return 0; |
| 1240 | } |
| 1241 | |
| 1242 | static const snd_kcontrol_new_t snd_ac97_controls_ad1885[] = { |
| 1243 | AC97_SINGLE("Digital Mono Direct", AC97_AD_MISC, 11, 1, 0), |
| 1244 | /* AC97_SINGLE("Digital Audio Mode", AC97_AD_MISC, 12, 1, 0), */ /* seems problematic */ |
| 1245 | AC97_SINGLE("Low Power Mixer", AC97_AD_MISC, 14, 1, 0), |
| 1246 | AC97_SINGLE("Zero Fill DAC", AC97_AD_MISC, 15, 1, 0), |
| 1247 | AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 9, 1, 1), /* inverted */ |
| 1248 | AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 8, 1, 1), /* inverted */ |
| 1249 | }; |
| 1250 | |
| 1251 | static int patch_ad1885_specific(ac97_t * ac97) |
| 1252 | { |
| 1253 | int err; |
| 1254 | |
| 1255 | if ((err = patch_build_controls(ac97, snd_ac97_controls_ad1885, ARRAY_SIZE(snd_ac97_controls_ad1885))) < 0) |
| 1256 | return err; |
| 1257 | return 0; |
| 1258 | } |
| 1259 | |
| 1260 | static struct snd_ac97_build_ops patch_ad1885_build_ops = { |
| 1261 | .build_specific = &patch_ad1885_specific, |
| 1262 | #ifdef CONFIG_PM |
| 1263 | .resume = ad18xx_resume |
| 1264 | #endif |
| 1265 | }; |
| 1266 | |
| 1267 | int patch_ad1885(ac97_t * ac97) |
| 1268 | { |
| 1269 | patch_ad1881(ac97); |
| 1270 | /* This is required to deal with the Intel D815EEAL2 */ |
| 1271 | /* i.e. Line out is actually headphone out from codec */ |
| 1272 | |
| 1273 | /* set default */ |
| 1274 | snd_ac97_write_cache(ac97, AC97_AD_MISC, 0x0404); |
| 1275 | |
| 1276 | ac97->build_ops = &patch_ad1885_build_ops; |
| 1277 | return 0; |
| 1278 | } |
| 1279 | |
| 1280 | int patch_ad1886(ac97_t * ac97) |
| 1281 | { |
| 1282 | patch_ad1881(ac97); |
| 1283 | /* Presario700 workaround */ |
| 1284 | /* for Jack Sense/SPDIF Register misetting causing */ |
| 1285 | snd_ac97_write_cache(ac97, AC97_AD_JACK_SPDIF, 0x0010); |
| 1286 | return 0; |
| 1287 | } |
| 1288 | |
| 1289 | /* MISC bits */ |
| 1290 | #define AC97_AD198X_MBC 0x0003 /* mic boost */ |
| 1291 | #define AC97_AD198X_MBC_20 0x0000 /* +20dB */ |
| 1292 | #define AC97_AD198X_MBC_10 0x0001 /* +10dB */ |
| 1293 | #define AC97_AD198X_MBC_30 0x0002 /* +30dB */ |
| 1294 | #define AC97_AD198X_VREFD 0x0004 /* VREF high-Z */ |
| 1295 | #define AC97_AD198X_VREFH 0x0008 /* 2.25V, 3.7V */ |
| 1296 | #define AC97_AD198X_VREF_0 0x000c /* 0V */ |
| 1297 | #define AC97_AD198X_SRU 0x0010 /* sample rate unlock */ |
| 1298 | #define AC97_AD198X_LOSEL 0x0020 /* LINE_OUT amplifiers input select */ |
| 1299 | #define AC97_AD198X_2MIC 0x0040 /* 2-channel mic select */ |
| 1300 | #define AC97_AD198X_SPRD 0x0080 /* SPREAD enable */ |
| 1301 | #define AC97_AD198X_DMIX0 0x0100 /* downmix mode: 0 = 6-to-4, 1 = 6-to-2 downmix */ |
| 1302 | #define AC97_AD198X_DMIX1 0x0200 /* downmix mode: 1 = enabled */ |
| 1303 | #define AC97_AD198X_HPSEL 0x0400 /* headphone amplifier input select */ |
| 1304 | #define AC97_AD198X_CLDIS 0x0800 /* center/lfe disable */ |
| 1305 | #define AC97_AD198X_LODIS 0x1000 /* LINE_OUT disable */ |
| 1306 | #define AC97_AD198X_MSPLT 0x2000 /* mute split */ |
| 1307 | #define AC97_AD198X_AC97NC 0x4000 /* AC97 no compatible mode */ |
| 1308 | #define AC97_AD198X_DACZ 0x8000 /* DAC zero-fill mode */ |
| 1309 | |
| 1310 | |
| 1311 | static int snd_ac97_ad198x_spdif_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) |
| 1312 | { |
| 1313 | static char *texts[2] = { "AC-Link", "A/D Converter" }; |
| 1314 | |
| 1315 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 1316 | uinfo->count = 1; |
| 1317 | uinfo->value.enumerated.items = 2; |
| 1318 | if (uinfo->value.enumerated.item > 1) |
| 1319 | uinfo->value.enumerated.item = 1; |
| 1320 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); |
| 1321 | return 0; |
| 1322 | } |
| 1323 | |
| 1324 | static int snd_ac97_ad198x_spdif_source_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) |
| 1325 | { |
| 1326 | ac97_t *ac97 = snd_kcontrol_chip(kcontrol); |
| 1327 | unsigned short val; |
| 1328 | |
| 1329 | val = ac97->regs[AC97_AD_SERIAL_CFG]; |
| 1330 | ucontrol->value.enumerated.item[0] = (val >> 2) & 1; |
| 1331 | return 0; |
| 1332 | } |
| 1333 | |
| 1334 | static int snd_ac97_ad198x_spdif_source_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) |
| 1335 | { |
| 1336 | ac97_t *ac97 = snd_kcontrol_chip(kcontrol); |
| 1337 | unsigned short val; |
| 1338 | |
| 1339 | if (ucontrol->value.enumerated.item[0] > 1) |
| 1340 | return -EINVAL; |
| 1341 | val = ucontrol->value.enumerated.item[0] << 2; |
| 1342 | return snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x0004, val); |
| 1343 | } |
| 1344 | |
| 1345 | static const snd_kcontrol_new_t snd_ac97_ad198x_spdif_source = { |
| 1346 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1347 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source", |
| 1348 | .info = snd_ac97_ad198x_spdif_source_info, |
| 1349 | .get = snd_ac97_ad198x_spdif_source_get, |
| 1350 | .put = snd_ac97_ad198x_spdif_source_put, |
| 1351 | }; |
| 1352 | |
| 1353 | static int patch_ad198x_post_spdif(ac97_t * ac97) |
| 1354 | { |
| 1355 | return patch_build_controls(ac97, &snd_ac97_ad198x_spdif_source, 1); |
| 1356 | } |
| 1357 | |
| 1358 | static const snd_kcontrol_new_t snd_ac97_ad1981x_jack_sense[] = { |
| 1359 | AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 11, 1, 0), |
| 1360 | AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0), |
| 1361 | }; |
| 1362 | |
| 1363 | static int patch_ad1981a_specific(ac97_t * ac97) |
| 1364 | { |
| 1365 | return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense, |
| 1366 | ARRAY_SIZE(snd_ac97_ad1981x_jack_sense)); |
| 1367 | } |
| 1368 | |
| 1369 | static struct snd_ac97_build_ops patch_ad1981a_build_ops = { |
| 1370 | .build_post_spdif = patch_ad198x_post_spdif, |
| 1371 | .build_specific = patch_ad1981a_specific, |
| 1372 | #ifdef CONFIG_PM |
| 1373 | .resume = ad18xx_resume |
| 1374 | #endif |
| 1375 | }; |
| 1376 | |
| 1377 | static void check_ad1981_hp_jack_sense(ac97_t *ac97) |
| 1378 | { |
| 1379 | u32 subid = ((u32)ac97->subsystem_vendor << 16) | ac97->subsystem_device; |
| 1380 | switch (subid) { |
| 1381 | case 0x103c0890: /* HP nc6000 */ |
| 1382 | case 0x103c006d: /* HP nx9105 */ |
| 1383 | case 0x17340088: /* FSC Scenic-W */ |
| 1384 | /* enable headphone jack sense */ |
| 1385 | snd_ac97_update_bits(ac97, AC97_AD_JACK_SPDIF, 1<<11, 1<<11); |
| 1386 | break; |
| 1387 | } |
| 1388 | } |
| 1389 | |
| 1390 | int patch_ad1981a(ac97_t *ac97) |
| 1391 | { |
| 1392 | patch_ad1881(ac97); |
| 1393 | ac97->build_ops = &patch_ad1981a_build_ops; |
| 1394 | snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT); |
| 1395 | ac97->flags |= AC97_STEREO_MUTES; |
| 1396 | check_ad1981_hp_jack_sense(ac97); |
| 1397 | return 0; |
| 1398 | } |
| 1399 | |
| 1400 | static const snd_kcontrol_new_t snd_ac97_ad198x_2cmic = |
| 1401 | AC97_SINGLE("Stereo Mic", AC97_AD_MISC, 6, 1, 0); |
| 1402 | |
| 1403 | static int patch_ad1981b_specific(ac97_t *ac97) |
| 1404 | { |
| 1405 | int err; |
| 1406 | |
| 1407 | if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0) |
| 1408 | return err; |
| 1409 | return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense, |
| 1410 | ARRAY_SIZE(snd_ac97_ad1981x_jack_sense)); |
| 1411 | } |
| 1412 | |
| 1413 | static struct snd_ac97_build_ops patch_ad1981b_build_ops = { |
| 1414 | .build_post_spdif = patch_ad198x_post_spdif, |
| 1415 | .build_specific = patch_ad1981b_specific, |
| 1416 | #ifdef CONFIG_PM |
| 1417 | .resume = ad18xx_resume |
| 1418 | #endif |
| 1419 | }; |
| 1420 | |
| 1421 | int patch_ad1981b(ac97_t *ac97) |
| 1422 | { |
| 1423 | patch_ad1881(ac97); |
| 1424 | ac97->build_ops = &patch_ad1981b_build_ops; |
| 1425 | snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT); |
| 1426 | ac97->flags |= AC97_STEREO_MUTES; |
| 1427 | check_ad1981_hp_jack_sense(ac97); |
| 1428 | return 0; |
| 1429 | } |
| 1430 | |
| 1431 | static int snd_ac97_ad1888_lohpsel_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo) |
| 1432 | { |
| 1433 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 1434 | uinfo->count = 1; |
| 1435 | uinfo->value.integer.min = 0; |
| 1436 | uinfo->value.integer.max = 1; |
| 1437 | return 0; |
| 1438 | } |
| 1439 | |
| 1440 | static int snd_ac97_ad1888_lohpsel_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol) |
| 1441 | { |
| 1442 | ac97_t *ac97 = snd_kcontrol_chip(kcontrol); |
| 1443 | unsigned short val; |
| 1444 | |
| 1445 | val = ac97->regs[AC97_AD_MISC]; |
| 1446 | ucontrol->value.integer.value[0] = !(val & AC97_AD198X_LOSEL); |
| 1447 | return 0; |
| 1448 | } |
| 1449 | |
| 1450 | static int snd_ac97_ad1888_lohpsel_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) |
| 1451 | { |
| 1452 | ac97_t *ac97 = snd_kcontrol_chip(kcontrol); |
| 1453 | unsigned short val; |
| 1454 | |
| 1455 | val = !ucontrol->value.integer.value[0] |
| 1456 | ? (AC97_AD198X_LOSEL | AC97_AD198X_HPSEL) : 0; |
| 1457 | return snd_ac97_update_bits(ac97, AC97_AD_MISC, |
| 1458 | AC97_AD198X_LOSEL | AC97_AD198X_HPSEL, val); |
| 1459 | } |
| 1460 | |
| 1461 | static int snd_ac97_ad1888_downmix_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo) |
| 1462 | { |
| 1463 | static char *texts[3] = {"Off", "6 -> 4", "6 -> 2"}; |
| 1464 | |
| 1465 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 1466 | uinfo->count = 1; |
| 1467 | uinfo->value.enumerated.items = 3; |
| 1468 | if (uinfo->value.enumerated.item > 2) |
| 1469 | uinfo->value.enumerated.item = 2; |
| 1470 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); |
| 1471 | return 0; |
| 1472 | } |
| 1473 | |
| 1474 | static int snd_ac97_ad1888_downmix_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol) |
| 1475 | { |
| 1476 | ac97_t *ac97 = snd_kcontrol_chip(kcontrol); |
| 1477 | unsigned short val; |
| 1478 | |
| 1479 | val = ac97->regs[AC97_AD_MISC]; |
| 1480 | if (!(val & AC97_AD198X_DMIX1)) |
| 1481 | ucontrol->value.enumerated.item[0] = 0; |
| 1482 | else |
| 1483 | ucontrol->value.enumerated.item[0] = 1 + ((val >> 8) & 1); |
| 1484 | return 0; |
| 1485 | } |
| 1486 | |
| 1487 | static int snd_ac97_ad1888_downmix_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) |
| 1488 | { |
| 1489 | ac97_t *ac97 = snd_kcontrol_chip(kcontrol); |
| 1490 | unsigned short val; |
| 1491 | |
| 1492 | if (ucontrol->value.enumerated.item[0] > 2) |
| 1493 | return -EINVAL; |
| 1494 | if (ucontrol->value.enumerated.item[0] == 0) |
| 1495 | val = 0; |
| 1496 | else |
| 1497 | val = AC97_AD198X_DMIX1 | |
| 1498 | ((ucontrol->value.enumerated.item[0] - 1) << 8); |
| 1499 | return snd_ac97_update_bits(ac97, AC97_AD_MISC, |
| 1500 | AC97_AD198X_DMIX0 | AC97_AD198X_DMIX1, val); |
| 1501 | } |
| 1502 | |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 1503 | static void ad1888_update_jacks(ac97_t *ac97) |
| 1504 | { |
| 1505 | /* shared Line-In */ |
| 1506 | snd_ac97_update_bits(ac97, AC97_AD_MISC, 1 << 12, |
| 1507 | is_shared_linein(ac97) ? 0 : 1 << 12); |
| 1508 | /* shared Mic */ |
| 1509 | snd_ac97_update_bits(ac97, AC97_AD_MISC, 1 << 11, |
Clemens Ladisch | 3296480 | 2005-05-10 14:48:37 +0200 | [diff] [blame] | 1510 | is_shared_micin(ac97) ? 0 : 1 << 11); |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 1511 | } |
| 1512 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | static const snd_kcontrol_new_t snd_ac97_ad1888_controls[] = { |
| 1514 | { |
| 1515 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1516 | .name = "Exchange Front/Surround", |
| 1517 | .info = snd_ac97_ad1888_lohpsel_info, |
| 1518 | .get = snd_ac97_ad1888_lohpsel_get, |
| 1519 | .put = snd_ac97_ad1888_lohpsel_put |
| 1520 | }, |
| 1521 | AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC, 7, 1, 0), |
| 1522 | { |
| 1523 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1524 | .name = "Downmix", |
| 1525 | .info = snd_ac97_ad1888_downmix_info, |
| 1526 | .get = snd_ac97_ad1888_downmix_get, |
| 1527 | .put = snd_ac97_ad1888_downmix_put |
| 1528 | }, |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 1529 | AC97_SURROUND_JACK_MODE_CTL, |
| 1530 | AC97_CHANNEL_MODE_CTL, |
Sergey Ulanov | eeacb54 | 2005-07-27 17:28:58 +0200 | [diff] [blame^] | 1531 | |
| 1532 | AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0), |
| 1533 | AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | }; |
| 1535 | |
| 1536 | static int patch_ad1888_specific(ac97_t *ac97) |
| 1537 | { |
| 1538 | /* rename 0x04 as "Master" and 0x02 as "Master Surround" */ |
| 1539 | snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Master Surround Playback"); |
| 1540 | snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback"); |
| 1541 | return patch_build_controls(ac97, snd_ac97_ad1888_controls, ARRAY_SIZE(snd_ac97_ad1888_controls)); |
| 1542 | } |
| 1543 | |
| 1544 | static struct snd_ac97_build_ops patch_ad1888_build_ops = { |
| 1545 | .build_post_spdif = patch_ad198x_post_spdif, |
| 1546 | .build_specific = patch_ad1888_specific, |
| 1547 | #ifdef CONFIG_PM |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 1548 | .resume = ad18xx_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1549 | #endif |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 1550 | .update_jacks = ad1888_update_jacks, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1551 | }; |
| 1552 | |
| 1553 | int patch_ad1888(ac97_t * ac97) |
| 1554 | { |
| 1555 | unsigned short misc; |
| 1556 | |
| 1557 | patch_ad1881(ac97); |
| 1558 | ac97->build_ops = &patch_ad1888_build_ops; |
| 1559 | /* Switch FRONT/SURROUND LINE-OUT/HP-OUT default connection */ |
| 1560 | /* it seems that most vendors connect line-out connector to headphone out of AC'97 */ |
| 1561 | /* AD-compatible mode */ |
| 1562 | /* Stereo mutes enabled */ |
| 1563 | misc = snd_ac97_read(ac97, AC97_AD_MISC); |
| 1564 | snd_ac97_write_cache(ac97, AC97_AD_MISC, misc | |
| 1565 | AC97_AD198X_LOSEL | |
| 1566 | AC97_AD198X_HPSEL | |
| 1567 | AC97_AD198X_MSPLT | |
| 1568 | AC97_AD198X_AC97NC); |
| 1569 | ac97->flags |= AC97_STEREO_MUTES; |
| 1570 | return 0; |
| 1571 | } |
| 1572 | |
| 1573 | static int patch_ad1980_specific(ac97_t *ac97) |
| 1574 | { |
| 1575 | int err; |
| 1576 | |
| 1577 | if ((err = patch_ad1888_specific(ac97)) < 0) |
| 1578 | return err; |
| 1579 | return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1); |
| 1580 | } |
| 1581 | |
| 1582 | static struct snd_ac97_build_ops patch_ad1980_build_ops = { |
| 1583 | .build_post_spdif = patch_ad198x_post_spdif, |
| 1584 | .build_specific = patch_ad1980_specific, |
| 1585 | #ifdef CONFIG_PM |
Clemens Ladisch | 462c417 | 2005-05-10 14:50:31 +0200 | [diff] [blame] | 1586 | .resume = ad18xx_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | #endif |
Clemens Ladisch | 462c417 | 2005-05-10 14:50:31 +0200 | [diff] [blame] | 1588 | .update_jacks = ad1888_update_jacks, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1589 | }; |
| 1590 | |
| 1591 | int patch_ad1980(ac97_t * ac97) |
| 1592 | { |
| 1593 | patch_ad1888(ac97); |
| 1594 | ac97->build_ops = &patch_ad1980_build_ops; |
| 1595 | return 0; |
| 1596 | } |
| 1597 | |
| 1598 | static const snd_kcontrol_new_t snd_ac97_ad1985_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0) |
| 1600 | }; |
| 1601 | |
Takashi Iwai | e5b3f45 | 2005-05-17 17:17:57 +0200 | [diff] [blame] | 1602 | static void ad1985_update_jacks(ac97_t *ac97) |
| 1603 | { |
| 1604 | /* shared Line-In */ |
| 1605 | snd_ac97_update_bits(ac97, AC97_AD_MISC, 1 << 12, |
| 1606 | is_shared_linein(ac97) ? 0 : 1 << 12); |
| 1607 | /* shared Mic */ |
| 1608 | snd_ac97_update_bits(ac97, AC97_AD_MISC, 1 << 11, |
| 1609 | is_shared_micin(ac97) ? 0 : 1 << 11); |
Takashi Iwai | fc232c6 | 2005-05-27 10:42:45 +0200 | [diff] [blame] | 1610 | snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 1 << 9, |
| 1611 | is_shared_micin(ac97) ? 0 : 1 << 9); |
Takashi Iwai | e5b3f45 | 2005-05-17 17:17:57 +0200 | [diff] [blame] | 1612 | } |
| 1613 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1614 | static int patch_ad1985_specific(ac97_t *ac97) |
| 1615 | { |
| 1616 | int err; |
| 1617 | |
| 1618 | if ((err = patch_ad1980_specific(ac97)) < 0) |
| 1619 | return err; |
| 1620 | return patch_build_controls(ac97, snd_ac97_ad1985_controls, ARRAY_SIZE(snd_ac97_ad1985_controls)); |
| 1621 | } |
| 1622 | |
| 1623 | static struct snd_ac97_build_ops patch_ad1985_build_ops = { |
| 1624 | .build_post_spdif = patch_ad198x_post_spdif, |
| 1625 | .build_specific = patch_ad1985_specific, |
| 1626 | #ifdef CONFIG_PM |
Clemens Ladisch | 462c417 | 2005-05-10 14:50:31 +0200 | [diff] [blame] | 1627 | .resume = ad18xx_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | #endif |
Takashi Iwai | e5b3f45 | 2005-05-17 17:17:57 +0200 | [diff] [blame] | 1629 | .update_jacks = ad1985_update_jacks, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1630 | }; |
| 1631 | |
| 1632 | int patch_ad1985(ac97_t * ac97) |
| 1633 | { |
| 1634 | unsigned short misc; |
| 1635 | |
| 1636 | patch_ad1881(ac97); |
| 1637 | ac97->build_ops = &patch_ad1985_build_ops; |
| 1638 | misc = snd_ac97_read(ac97, AC97_AD_MISC); |
| 1639 | /* switch front/surround line-out/hp-out */ |
| 1640 | /* center/LFE, mic in 3.75V mode */ |
| 1641 | /* AD-compatible mode */ |
| 1642 | /* Stereo mutes enabled */ |
| 1643 | /* in accordance with ADI driver: misc | 0x5c28 */ |
| 1644 | snd_ac97_write_cache(ac97, AC97_AD_MISC, misc | |
| 1645 | AC97_AD198X_VREFH | |
| 1646 | AC97_AD198X_LOSEL | |
| 1647 | AC97_AD198X_HPSEL | |
| 1648 | AC97_AD198X_CLDIS | |
| 1649 | AC97_AD198X_LODIS | |
| 1650 | AC97_AD198X_MSPLT | |
| 1651 | AC97_AD198X_AC97NC); |
| 1652 | ac97->flags |= AC97_STEREO_MUTES; |
| 1653 | /* on AD1985 rev. 3, AC'97 revision bits are zero */ |
| 1654 | ac97->ext_id = (ac97->ext_id & ~AC97_EI_REV_MASK) | AC97_EI_REV_23; |
| 1655 | return 0; |
| 1656 | } |
| 1657 | |
| 1658 | /* |
| 1659 | * realtek ALC65x/850 codecs |
| 1660 | */ |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 1661 | static void alc650_update_jacks(ac97_t *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | { |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 1663 | int shared; |
| 1664 | |
| 1665 | /* shared Line-In */ |
| 1666 | shared = is_shared_linein(ac97); |
| 1667 | snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 9, |
| 1668 | shared ? (1 << 9) : 0); |
| 1669 | /* update shared Mic */ |
| 1670 | shared = is_shared_micin(ac97); |
| 1671 | /* disable/enable vref */ |
| 1672 | snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12, |
| 1673 | shared ? (1 << 12) : 0); |
| 1674 | /* turn on/off center-on-mic */ |
| 1675 | snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 10, |
| 1676 | shared ? (1 << 10) : 0); |
| 1677 | /* GPIO0 high for mic */ |
| 1678 | snd_ac97_update_bits(ac97, AC97_ALC650_GPIO_STATUS, 0x100, |
| 1679 | shared ? 0 : 0x100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1680 | } |
| 1681 | |
| 1682 | static const snd_kcontrol_new_t snd_ac97_controls_alc650[] = { |
| 1683 | AC97_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0), |
| 1684 | AC97_SINGLE("Surround Down Mix", AC97_ALC650_MULTICH, 1, 1, 0), |
| 1685 | AC97_SINGLE("Center/LFE Down Mix", AC97_ALC650_MULTICH, 2, 1, 0), |
| 1686 | AC97_SINGLE("Exchange Center/LFE", AC97_ALC650_MULTICH, 3, 1, 0), |
| 1687 | /* 4: Analog Input To Surround */ |
| 1688 | /* 5: Analog Input To Center/LFE */ |
| 1689 | /* 6: Independent Master Volume Right */ |
| 1690 | /* 7: Independent Master Volume Left */ |
| 1691 | /* 8: reserved */ |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 1692 | /* 9: Line-In/Surround share */ |
| 1693 | /* 10: Mic/CLFE share */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1694 | /* 11-13: in IEC958 controls */ |
| 1695 | AC97_SINGLE("Swap Surround Slot", AC97_ALC650_MULTICH, 14, 1, 0), |
| 1696 | #if 0 /* always set in patch_alc650 */ |
| 1697 | AC97_SINGLE("IEC958 Input Clock Enable", AC97_ALC650_CLOCK, 0, 1, 0), |
| 1698 | AC97_SINGLE("IEC958 Input Pin Enable", AC97_ALC650_CLOCK, 1, 1, 0), |
| 1699 | AC97_SINGLE("Surround DAC Switch", AC97_ALC650_SURR_DAC_VOL, 15, 1, 1), |
| 1700 | AC97_DOUBLE("Surround DAC Volume", AC97_ALC650_SURR_DAC_VOL, 8, 0, 31, 1), |
| 1701 | AC97_SINGLE("Center/LFE DAC Switch", AC97_ALC650_LFE_DAC_VOL, 15, 1, 1), |
| 1702 | AC97_DOUBLE("Center/LFE DAC Volume", AC97_ALC650_LFE_DAC_VOL, 8, 0, 31, 1), |
| 1703 | #endif |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 1704 | AC97_SURROUND_JACK_MODE_CTL, |
| 1705 | AC97_CHANNEL_MODE_CTL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | }; |
| 1707 | |
| 1708 | static const snd_kcontrol_new_t snd_ac97_spdif_controls_alc650[] = { |
| 1709 | AC97_SINGLE("IEC958 Capture Switch", AC97_ALC650_MULTICH, 11, 1, 0), |
| 1710 | AC97_SINGLE("Analog to IEC958 Output", AC97_ALC650_MULTICH, 12, 1, 0), |
| 1711 | /* disable this controls since it doesn't work as expected */ |
| 1712 | /* AC97_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 13, 1, 0), */ |
| 1713 | }; |
| 1714 | |
| 1715 | static int patch_alc650_specific(ac97_t * ac97) |
| 1716 | { |
| 1717 | int err; |
| 1718 | |
| 1719 | if ((err = patch_build_controls(ac97, snd_ac97_controls_alc650, ARRAY_SIZE(snd_ac97_controls_alc650))) < 0) |
| 1720 | return err; |
| 1721 | if (ac97->ext_id & AC97_EI_SPDIF) { |
| 1722 | if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc650, ARRAY_SIZE(snd_ac97_spdif_controls_alc650))) < 0) |
| 1723 | return err; |
| 1724 | } |
| 1725 | return 0; |
| 1726 | } |
| 1727 | |
| 1728 | static struct snd_ac97_build_ops patch_alc650_ops = { |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 1729 | .build_specific = patch_alc650_specific, |
| 1730 | .update_jacks = alc650_update_jacks |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1731 | }; |
| 1732 | |
| 1733 | int patch_alc650(ac97_t * ac97) |
| 1734 | { |
| 1735 | unsigned short val; |
| 1736 | |
| 1737 | ac97->build_ops = &patch_alc650_ops; |
| 1738 | |
| 1739 | /* determine the revision */ |
| 1740 | val = snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f; |
| 1741 | if (val < 3) |
| 1742 | ac97->id = 0x414c4720; /* Old version */ |
| 1743 | else if (val < 0x10) |
| 1744 | ac97->id = 0x414c4721; /* D version */ |
| 1745 | else if (val < 0x20) |
| 1746 | ac97->id = 0x414c4722; /* E version */ |
| 1747 | else if (val < 0x30) |
| 1748 | ac97->id = 0x414c4723; /* F version */ |
| 1749 | |
| 1750 | /* revision E or F */ |
| 1751 | /* FIXME: what about revision D ? */ |
| 1752 | ac97->spec.dev_flags = (ac97->id == 0x414c4722 || |
| 1753 | ac97->id == 0x414c4723); |
| 1754 | |
| 1755 | /* enable AC97_ALC650_GPIO_SETUP, AC97_ALC650_CLOCK for R/W */ |
| 1756 | snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS, |
| 1757 | snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x8000); |
| 1758 | |
| 1759 | /* Enable SPDIF-IN only on Rev.E and above */ |
| 1760 | val = snd_ac97_read(ac97, AC97_ALC650_CLOCK); |
| 1761 | /* SPDIF IN with pin 47 */ |
| 1762 | if (ac97->spec.dev_flags) |
| 1763 | val |= 0x03; /* enable */ |
| 1764 | else |
| 1765 | val &= ~0x03; /* disable */ |
| 1766 | snd_ac97_write_cache(ac97, AC97_ALC650_CLOCK, val); |
| 1767 | |
| 1768 | /* set default: slot 3,4,7,8,6,9 |
| 1769 | spdif-in monitor off, analog-spdif off, spdif-in off |
| 1770 | center on mic off, surround on line-in off |
| 1771 | downmix off, duplicate front off |
| 1772 | */ |
| 1773 | snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 0); |
| 1774 | |
| 1775 | /* set GPIO0 for mic bias */ |
| 1776 | /* GPIO0 pin output, no interrupt, high */ |
| 1777 | snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_SETUP, |
| 1778 | snd_ac97_read(ac97, AC97_ALC650_GPIO_SETUP) | 0x01); |
| 1779 | snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS, |
| 1780 | (snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x100) & ~0x10); |
| 1781 | |
| 1782 | /* full DAC volume */ |
| 1783 | snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808); |
| 1784 | snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808); |
| 1785 | return 0; |
| 1786 | } |
| 1787 | |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 1788 | static void alc655_update_jacks(ac97_t *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1789 | { |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 1790 | int shared; |
| 1791 | |
| 1792 | /* shared Line-In */ |
| 1793 | shared = is_shared_linein(ac97); |
| 1794 | ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 9, |
| 1795 | shared ? (1 << 9) : 0, 0); |
| 1796 | /* update shared mic */ |
| 1797 | shared = is_shared_micin(ac97); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1798 | /* misc control; vrefout disable */ |
| 1799 | snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12, |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 1800 | shared ? (1 << 12) : 0); |
| 1801 | ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 10, |
| 1802 | shared ? (1 << 10) : 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1803 | } |
| 1804 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | static const snd_kcontrol_new_t snd_ac97_controls_alc655[] = { |
| 1806 | AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0), |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 1807 | AC97_SURROUND_JACK_MODE_CTL, |
| 1808 | AC97_CHANNEL_MODE_CTL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | }; |
| 1810 | |
| 1811 | static int alc655_iec958_route_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo) |
| 1812 | { |
| 1813 | static char *texts_655[3] = { "PCM", "Analog In", "IEC958 In" }; |
| 1814 | static char *texts_658[4] = { "PCM", "Analog1 In", "Analog2 In", "IEC958 In" }; |
| 1815 | ac97_t *ac97 = snd_kcontrol_chip(kcontrol); |
| 1816 | |
| 1817 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 1818 | uinfo->count = 1; |
| 1819 | uinfo->value.enumerated.items = ac97->spec.dev_flags ? 4 : 3; |
| 1820 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
| 1821 | uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; |
| 1822 | strcpy(uinfo->value.enumerated.name, |
| 1823 | ac97->spec.dev_flags ? |
| 1824 | texts_658[uinfo->value.enumerated.item] : |
| 1825 | texts_655[uinfo->value.enumerated.item]); |
| 1826 | return 0; |
| 1827 | } |
| 1828 | |
| 1829 | static int alc655_iec958_route_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) |
| 1830 | { |
| 1831 | ac97_t *ac97 = snd_kcontrol_chip(kcontrol); |
| 1832 | unsigned short val; |
| 1833 | |
| 1834 | val = ac97->regs[AC97_ALC650_MULTICH]; |
| 1835 | val = (val >> 12) & 3; |
| 1836 | if (ac97->spec.dev_flags && val == 3) |
| 1837 | val = 0; |
| 1838 | ucontrol->value.enumerated.item[0] = val; |
| 1839 | return 0; |
| 1840 | } |
| 1841 | |
| 1842 | static int alc655_iec958_route_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) |
| 1843 | { |
| 1844 | ac97_t *ac97 = snd_kcontrol_chip(kcontrol); |
| 1845 | |
| 1846 | return ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 3 << 12, |
| 1847 | (unsigned short)ucontrol->value.enumerated.item[0] << 12, |
| 1848 | 0); |
| 1849 | } |
| 1850 | |
| 1851 | static const snd_kcontrol_new_t snd_ac97_spdif_controls_alc655[] = { |
| 1852 | AC97_PAGE_SINGLE("IEC958 Capture Switch", AC97_ALC650_MULTICH, 11, 1, 0, 0), |
| 1853 | /* disable this controls since it doesn't work as expected */ |
| 1854 | /* AC97_PAGE_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 14, 1, 0, 0), */ |
| 1855 | { |
| 1856 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1857 | .name = "IEC958 Playback Route", |
| 1858 | .info = alc655_iec958_route_info, |
| 1859 | .get = alc655_iec958_route_get, |
| 1860 | .put = alc655_iec958_route_put, |
| 1861 | }, |
| 1862 | }; |
| 1863 | |
| 1864 | static int patch_alc655_specific(ac97_t * ac97) |
| 1865 | { |
| 1866 | int err; |
| 1867 | |
| 1868 | if ((err = patch_build_controls(ac97, snd_ac97_controls_alc655, ARRAY_SIZE(snd_ac97_controls_alc655))) < 0) |
| 1869 | return err; |
| 1870 | if (ac97->ext_id & AC97_EI_SPDIF) { |
| 1871 | if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0) |
| 1872 | return err; |
| 1873 | } |
| 1874 | return 0; |
| 1875 | } |
| 1876 | |
| 1877 | static struct snd_ac97_build_ops patch_alc655_ops = { |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 1878 | .build_specific = patch_alc655_specific, |
| 1879 | .update_jacks = alc655_update_jacks |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1880 | }; |
| 1881 | |
| 1882 | int patch_alc655(ac97_t * ac97) |
| 1883 | { |
| 1884 | unsigned int val; |
| 1885 | |
| 1886 | ac97->spec.dev_flags = (ac97->id == 0x414c4780); /* ALC658 */ |
| 1887 | |
| 1888 | ac97->build_ops = &patch_alc655_ops; |
| 1889 | |
| 1890 | /* assume only page 0 for writing cache */ |
| 1891 | snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR); |
| 1892 | |
| 1893 | /* adjust default values */ |
| 1894 | val = snd_ac97_read(ac97, 0x7a); /* misc control */ |
| 1895 | if (ac97->id == 0x414c4780) /* ALC658 */ |
| 1896 | val &= ~(1 << 1); /* Pin 47 is spdif input pin */ |
| 1897 | else /* ALC655 */ |
| 1898 | val |= (1 << 1); /* Pin 47 is spdif input pin */ |
| 1899 | val &= ~(1 << 12); /* vref enable */ |
| 1900 | snd_ac97_write_cache(ac97, 0x7a, val); |
| 1901 | /* set default: spdif-in enabled, |
| 1902 | spdif-in monitor off, spdif-in PCM off |
| 1903 | center on mic off, surround on line-in off |
| 1904 | duplicate front off |
| 1905 | */ |
| 1906 | snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15); |
| 1907 | |
| 1908 | /* full DAC volume */ |
| 1909 | snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808); |
| 1910 | snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808); |
| 1911 | return 0; |
| 1912 | } |
| 1913 | |
| 1914 | |
| 1915 | #define AC97_ALC850_JACK_SELECT 0x76 |
| 1916 | #define AC97_ALC850_MISC1 0x7a |
| 1917 | |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 1918 | static void alc850_update_jacks(ac97_t *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | { |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 1920 | int shared; |
| 1921 | |
| 1922 | /* shared Line-In */ |
| 1923 | shared = is_shared_linein(ac97); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1924 | /* SURR 1kOhm (bit4), Amp (bit5) */ |
| 1925 | snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<4)|(1<<5), |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 1926 | shared ? (1<<5) : (1<<4)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1927 | /* LINE-IN = 0, SURROUND = 2 */ |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 1928 | snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 12, |
| 1929 | shared ? (2<<12) : (0<<12)); |
| 1930 | /* update shared mic */ |
| 1931 | shared = is_shared_micin(ac97); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1932 | /* Vref disable (bit12), 1kOhm (bit13) */ |
| 1933 | snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<12)|(1<<13), |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 1934 | shared ? (1<<12) : (1<<13)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1935 | /* MIC-IN = 1, CENTER-LFE = 2 */ |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 1936 | snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 4, |
| 1937 | shared ? (2<<4) : (1<<4)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1938 | } |
| 1939 | |
| 1940 | static const snd_kcontrol_new_t snd_ac97_controls_alc850[] = { |
| 1941 | AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0), |
Sergey Vlasov | 67e1b51 | 2005-04-25 11:34:33 +0200 | [diff] [blame] | 1942 | 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] | 1943 | AC97_SURROUND_JACK_MODE_CTL, |
| 1944 | AC97_CHANNEL_MODE_CTL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1945 | }; |
| 1946 | |
| 1947 | static int patch_alc850_specific(ac97_t *ac97) |
| 1948 | { |
| 1949 | int err; |
| 1950 | |
| 1951 | if ((err = patch_build_controls(ac97, snd_ac97_controls_alc850, ARRAY_SIZE(snd_ac97_controls_alc850))) < 0) |
| 1952 | return err; |
| 1953 | if (ac97->ext_id & AC97_EI_SPDIF) { |
| 1954 | if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0) |
| 1955 | return err; |
| 1956 | } |
| 1957 | return 0; |
| 1958 | } |
| 1959 | |
| 1960 | static struct snd_ac97_build_ops patch_alc850_ops = { |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 1961 | .build_specific = patch_alc850_specific, |
| 1962 | .update_jacks = alc850_update_jacks |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | }; |
| 1964 | |
| 1965 | int patch_alc850(ac97_t *ac97) |
| 1966 | { |
| 1967 | ac97->build_ops = &patch_alc850_ops; |
| 1968 | |
| 1969 | ac97->spec.dev_flags = 0; /* for IEC958 playback route - ALC655 compatible */ |
| 1970 | |
| 1971 | /* assume only page 0 for writing cache */ |
| 1972 | snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR); |
| 1973 | |
| 1974 | /* adjust default values */ |
| 1975 | /* set default: spdif-in enabled, |
| 1976 | spdif-in monitor off, spdif-in PCM off |
| 1977 | center on mic off, surround on line-in off |
| 1978 | duplicate front off |
| 1979 | */ |
| 1980 | snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15); |
| 1981 | /* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off |
| 1982 | * Front Amp: on, Vref: enable, Center 1kOhm: on, Mix: on |
| 1983 | */ |
| 1984 | snd_ac97_write_cache(ac97, 0x7a, (1<<1)|(1<<4)|(0<<5)|(1<<6)| |
| 1985 | (1<<7)|(0<<12)|(1<<13)|(0<<14)); |
| 1986 | /* detection UIO2,3: all path floating, UIO3: MIC, Vref2: disable, |
| 1987 | * UIO1: FRONT, Vref3: disable, UIO3: LINE, Front-Mic: mute |
| 1988 | */ |
| 1989 | snd_ac97_write_cache(ac97, 0x76, (0<<0)|(0<<2)|(1<<4)|(1<<7)|(2<<8)| |
| 1990 | (1<<11)|(0<<12)|(1<<15)); |
| 1991 | |
| 1992 | /* full DAC volume */ |
| 1993 | snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808); |
| 1994 | snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808); |
| 1995 | return 0; |
| 1996 | } |
| 1997 | |
| 1998 | |
| 1999 | /* |
| 2000 | * C-Media CM97xx codecs |
| 2001 | */ |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2002 | static void cm9738_update_jacks(ac97_t *ac97) |
| 2003 | { |
| 2004 | /* shared Line-In */ |
| 2005 | snd_ac97_update_bits(ac97, AC97_CM9738_VENDOR_CTRL, 1 << 10, |
| 2006 | is_shared_linein(ac97) ? (1 << 10) : 0); |
| 2007 | } |
| 2008 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2009 | static const snd_kcontrol_new_t snd_ac97_cm9738_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | AC97_SINGLE("Duplicate Front", AC97_CM9738_VENDOR_CTRL, 13, 1, 0), |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2011 | AC97_SURROUND_JACK_MODE_CTL, |
| 2012 | AC97_CHANNEL_MODE_4CH_CTL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | }; |
| 2014 | |
| 2015 | static int patch_cm9738_specific(ac97_t * ac97) |
| 2016 | { |
| 2017 | return patch_build_controls(ac97, snd_ac97_cm9738_controls, ARRAY_SIZE(snd_ac97_cm9738_controls)); |
| 2018 | } |
| 2019 | |
| 2020 | static struct snd_ac97_build_ops patch_cm9738_ops = { |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2021 | .build_specific = patch_cm9738_specific, |
| 2022 | .update_jacks = cm9738_update_jacks |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2023 | }; |
| 2024 | |
| 2025 | int patch_cm9738(ac97_t * ac97) |
| 2026 | { |
| 2027 | ac97->build_ops = &patch_cm9738_ops; |
| 2028 | /* FIXME: can anyone confirm below? */ |
| 2029 | /* CM9738 has no PCM volume although the register reacts */ |
| 2030 | ac97->flags |= AC97_HAS_NO_PCM_VOL; |
| 2031 | snd_ac97_write_cache(ac97, AC97_PCM, 0x8000); |
| 2032 | |
| 2033 | return 0; |
| 2034 | } |
| 2035 | |
| 2036 | static int snd_ac97_cmedia_spdif_playback_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) |
| 2037 | { |
| 2038 | static char *texts[] = { "Analog", "Digital" }; |
| 2039 | |
| 2040 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 2041 | uinfo->count = 1; |
| 2042 | uinfo->value.enumerated.items = 2; |
| 2043 | if (uinfo->value.enumerated.item > 1) |
| 2044 | uinfo->value.enumerated.item = 1; |
| 2045 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); |
| 2046 | return 0; |
| 2047 | } |
| 2048 | |
| 2049 | static int snd_ac97_cmedia_spdif_playback_source_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) |
| 2050 | { |
| 2051 | ac97_t *ac97 = snd_kcontrol_chip(kcontrol); |
| 2052 | unsigned short val; |
| 2053 | |
| 2054 | val = ac97->regs[AC97_CM9739_SPDIF_CTRL]; |
| 2055 | ucontrol->value.enumerated.item[0] = (val >> 1) & 0x01; |
| 2056 | return 0; |
| 2057 | } |
| 2058 | |
| 2059 | static int snd_ac97_cmedia_spdif_playback_source_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) |
| 2060 | { |
| 2061 | ac97_t *ac97 = snd_kcontrol_chip(kcontrol); |
| 2062 | |
| 2063 | return snd_ac97_update_bits(ac97, AC97_CM9739_SPDIF_CTRL, |
| 2064 | 0x01 << 1, |
| 2065 | (ucontrol->value.enumerated.item[0] & 0x01) << 1); |
| 2066 | } |
| 2067 | |
| 2068 | static const snd_kcontrol_new_t snd_ac97_cm9739_controls_spdif[] = { |
| 2069 | /* BIT 0: SPDI_EN - always true */ |
| 2070 | { /* BIT 1: SPDIFS */ |
| 2071 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2072 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source", |
| 2073 | .info = snd_ac97_cmedia_spdif_playback_source_info, |
| 2074 | .get = snd_ac97_cmedia_spdif_playback_source_get, |
| 2075 | .put = snd_ac97_cmedia_spdif_playback_source_put, |
| 2076 | }, |
| 2077 | /* BIT 2: IG_SPIV */ |
| 2078 | AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9739_SPDIF_CTRL, 2, 1, 0), |
| 2079 | /* BIT 3: SPI2F */ |
| 2080 | AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9739_SPDIF_CTRL, 3, 1, 0), |
| 2081 | /* BIT 4: SPI2SDI */ |
| 2082 | AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9739_SPDIF_CTRL, 4, 1, 0), |
| 2083 | /* BIT 8: SPD32 - 32bit SPDIF - not supported yet */ |
| 2084 | }; |
| 2085 | |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2086 | static void cm9739_update_jacks(ac97_t *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2087 | { |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2088 | /* shared Line-In */ |
| 2089 | snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 1 << 10, |
| 2090 | is_shared_linein(ac97) ? (1 << 10) : 0); |
| 2091 | /* shared Mic */ |
| 2092 | snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 0x3000, |
| 2093 | is_shared_micin(ac97) ? 0x1000 : 0x2000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2094 | } |
| 2095 | |
| 2096 | static const snd_kcontrol_new_t snd_ac97_cm9739_controls[] = { |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2097 | AC97_SURROUND_JACK_MODE_CTL, |
| 2098 | AC97_CHANNEL_MODE_CTL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2099 | }; |
| 2100 | |
| 2101 | static int patch_cm9739_specific(ac97_t * ac97) |
| 2102 | { |
| 2103 | return patch_build_controls(ac97, snd_ac97_cm9739_controls, ARRAY_SIZE(snd_ac97_cm9739_controls)); |
| 2104 | } |
| 2105 | |
| 2106 | static int patch_cm9739_post_spdif(ac97_t * ac97) |
| 2107 | { |
| 2108 | return patch_build_controls(ac97, snd_ac97_cm9739_controls_spdif, ARRAY_SIZE(snd_ac97_cm9739_controls_spdif)); |
| 2109 | } |
| 2110 | |
| 2111 | static struct snd_ac97_build_ops patch_cm9739_ops = { |
| 2112 | .build_specific = patch_cm9739_specific, |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2113 | .build_post_spdif = patch_cm9739_post_spdif, |
| 2114 | .update_jacks = cm9739_update_jacks |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | }; |
| 2116 | |
| 2117 | int patch_cm9739(ac97_t * ac97) |
| 2118 | { |
| 2119 | unsigned short val; |
| 2120 | |
| 2121 | ac97->build_ops = &patch_cm9739_ops; |
| 2122 | |
| 2123 | /* CM9739/A has no Master and PCM volume although the register reacts */ |
| 2124 | ac97->flags |= AC97_HAS_NO_MASTER_VOL | AC97_HAS_NO_PCM_VOL; |
| 2125 | snd_ac97_write_cache(ac97, AC97_MASTER, 0x8000); |
| 2126 | snd_ac97_write_cache(ac97, AC97_PCM, 0x8000); |
| 2127 | |
| 2128 | /* check spdif */ |
| 2129 | val = snd_ac97_read(ac97, AC97_EXTENDED_STATUS); |
| 2130 | if (val & AC97_EA_SPCV) { |
| 2131 | /* enable spdif in */ |
| 2132 | snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL, |
| 2133 | snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) | 0x01); |
| 2134 | ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */ |
| 2135 | } else { |
| 2136 | ac97->ext_id &= ~AC97_EI_SPDIF; /* disable extended-id */ |
| 2137 | ac97->rates[AC97_RATES_SPDIF] = 0; |
| 2138 | } |
| 2139 | |
| 2140 | /* set-up multi channel */ |
| 2141 | /* bit 14: 0 = SPDIF, 1 = EAPD */ |
| 2142 | /* bit 13: enable internal vref output for mic */ |
| 2143 | /* bit 12: disable center/lfe (swithable) */ |
| 2144 | /* bit 10: disable surround/line (switchable) */ |
| 2145 | /* bit 9: mix 2 surround off */ |
| 2146 | /* bit 4: undocumented; 0 mutes the CM9739A, which defaults to 1 */ |
| 2147 | /* bit 3: undocumented; surround? */ |
| 2148 | /* bit 0: dB */ |
| 2149 | val = snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) & (1 << 4); |
| 2150 | val |= (1 << 3); |
| 2151 | val |= (1 << 13); |
| 2152 | if (! (ac97->ext_id & AC97_EI_SPDIF)) |
| 2153 | val |= (1 << 14); |
| 2154 | snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, val); |
| 2155 | |
| 2156 | /* FIXME: set up GPIO */ |
| 2157 | snd_ac97_write_cache(ac97, 0x70, 0x0100); |
| 2158 | snd_ac97_write_cache(ac97, 0x72, 0x0020); |
| 2159 | /* Special exception for ASUS W1000/CMI9739. It does not have an SPDIF in. */ |
| 2160 | if (ac97->pci && |
| 2161 | ac97->subsystem_vendor == 0x1043 && |
| 2162 | ac97->subsystem_device == 0x1843) { |
| 2163 | snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL, |
| 2164 | snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) & ~0x01); |
| 2165 | snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, |
| 2166 | snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) | (1 << 14)); |
| 2167 | } |
| 2168 | |
| 2169 | return 0; |
| 2170 | } |
| 2171 | |
| 2172 | #define AC97_CM9761_MULTI_CHAN 0x64 |
Takashi Iwai | 5f0dccf | 2005-04-07 15:53:20 +0200 | [diff] [blame] | 2173 | #define AC97_CM9761_FUNC 0x66 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2174 | #define AC97_CM9761_SPDIF_CTRL 0x6c |
| 2175 | |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2176 | static void cm9761_update_jacks(ac97_t *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2177 | { |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2178 | unsigned short surr_vals[2][2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2179 | { 0x0008, 0x0400 }, /* off, on */ |
| 2180 | { 0x0000, 0x0408 }, /* off, on (9761-82 rev.B) */ |
| 2181 | }; |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2182 | unsigned short clfe_vals[2][2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2183 | { 0x2000, 0x1880 }, /* off, on */ |
| 2184 | { 0x1000, 0x2880 }, /* off, on (9761-82 rev.B) */ |
| 2185 | }; |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2186 | |
| 2187 | /* shared Line-In */ |
| 2188 | snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x0408, |
| 2189 | surr_vals[ac97->spec.dev_flags][is_shared_linein(ac97)]); |
| 2190 | /* shared Mic */ |
| 2191 | snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x3880, |
| 2192 | clfe_vals[ac97->spec.dev_flags][is_shared_micin(ac97)]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2193 | } |
| 2194 | |
| 2195 | static const snd_kcontrol_new_t snd_ac97_cm9761_controls[] = { |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2196 | AC97_SURROUND_JACK_MODE_CTL, |
| 2197 | AC97_CHANNEL_MODE_CTL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2198 | }; |
| 2199 | |
Takashi Iwai | 5f0dccf | 2005-04-07 15:53:20 +0200 | [diff] [blame] | 2200 | static int cm9761_spdif_out_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo) |
| 2201 | { |
| 2202 | static char *texts[] = { "AC-Link", "ADC", "SPDIF-In" }; |
| 2203 | |
| 2204 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 2205 | uinfo->count = 1; |
| 2206 | uinfo->value.enumerated.items = 3; |
| 2207 | if (uinfo->value.enumerated.item > 2) |
| 2208 | uinfo->value.enumerated.item = 2; |
| 2209 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); |
| 2210 | return 0; |
| 2211 | } |
| 2212 | |
| 2213 | static int cm9761_spdif_out_source_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) |
| 2214 | { |
| 2215 | ac97_t *ac97 = snd_kcontrol_chip(kcontrol); |
| 2216 | |
| 2217 | if (ac97->regs[AC97_CM9761_FUNC] & 0x1) |
| 2218 | ucontrol->value.enumerated.item[0] = 2; /* SPDIF-loopback */ |
| 2219 | else if (ac97->regs[AC97_CM9761_SPDIF_CTRL] & 0x2) |
| 2220 | ucontrol->value.enumerated.item[0] = 1; /* ADC loopback */ |
| 2221 | else |
| 2222 | ucontrol->value.enumerated.item[0] = 0; /* AC-link */ |
| 2223 | return 0; |
| 2224 | } |
| 2225 | |
| 2226 | static int cm9761_spdif_out_source_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) |
| 2227 | { |
| 2228 | ac97_t *ac97 = snd_kcontrol_chip(kcontrol); |
| 2229 | |
| 2230 | if (ucontrol->value.enumerated.item[0] == 2) |
| 2231 | return snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0x1); |
| 2232 | snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0); |
| 2233 | return snd_ac97_update_bits(ac97, AC97_CM9761_SPDIF_CTRL, 0x2, |
| 2234 | ucontrol->value.enumerated.item[0] == 1 ? 0x2 : 0); |
| 2235 | } |
| 2236 | |
| 2237 | static const char *cm9761_dac_clock[] = { "AC-Link", "SPDIF-In", "Both" }; |
| 2238 | static const struct ac97_enum cm9761_dac_clock_enum = |
| 2239 | AC97_ENUM_SINGLE(AC97_CM9761_SPDIF_CTRL, 9, 3, cm9761_dac_clock); |
| 2240 | |
| 2241 | static const snd_kcontrol_new_t snd_ac97_cm9761_controls_spdif[] = { |
| 2242 | { /* BIT 1: SPDIFS */ |
| 2243 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2244 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source", |
| 2245 | .info = cm9761_spdif_out_source_info, |
| 2246 | .get = cm9761_spdif_out_source_get, |
| 2247 | .put = cm9761_spdif_out_source_put, |
| 2248 | }, |
| 2249 | /* BIT 2: IG_SPIV */ |
| 2250 | AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9761_SPDIF_CTRL, 2, 1, 0), |
| 2251 | /* BIT 3: SPI2F */ |
| 2252 | AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9761_SPDIF_CTRL, 3, 1, 0), |
| 2253 | /* BIT 4: SPI2SDI */ |
| 2254 | AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9761_SPDIF_CTRL, 4, 1, 0), |
| 2255 | /* BIT 9-10: DAC_CTL */ |
| 2256 | AC97_ENUM("DAC Clock Source", cm9761_dac_clock_enum), |
| 2257 | }; |
| 2258 | |
| 2259 | static int patch_cm9761_post_spdif(ac97_t * ac97) |
| 2260 | { |
| 2261 | return patch_build_controls(ac97, snd_ac97_cm9761_controls_spdif, ARRAY_SIZE(snd_ac97_cm9761_controls_spdif)); |
| 2262 | } |
| 2263 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2264 | static int patch_cm9761_specific(ac97_t * ac97) |
| 2265 | { |
| 2266 | return patch_build_controls(ac97, snd_ac97_cm9761_controls, ARRAY_SIZE(snd_ac97_cm9761_controls)); |
| 2267 | } |
| 2268 | |
| 2269 | static struct snd_ac97_build_ops patch_cm9761_ops = { |
| 2270 | .build_specific = patch_cm9761_specific, |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2271 | .build_post_spdif = patch_cm9761_post_spdif, |
| 2272 | .update_jacks = cm9761_update_jacks |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2273 | }; |
| 2274 | |
| 2275 | int patch_cm9761(ac97_t *ac97) |
| 2276 | { |
| 2277 | unsigned short val; |
| 2278 | |
| 2279 | /* CM9761 has no PCM volume although the register reacts */ |
| 2280 | /* Master volume seems to have _some_ influence on the analog |
| 2281 | * input sounds |
| 2282 | */ |
| 2283 | ac97->flags |= /*AC97_HAS_NO_MASTER_VOL |*/ AC97_HAS_NO_PCM_VOL; |
| 2284 | snd_ac97_write_cache(ac97, AC97_MASTER, 0x8808); |
| 2285 | snd_ac97_write_cache(ac97, AC97_PCM, 0x8808); |
| 2286 | |
| 2287 | ac97->spec.dev_flags = 0; /* 1 = model 82 revision B */ |
| 2288 | if (ac97->id == AC97_ID_CM9761_82) { |
| 2289 | unsigned short tmp; |
| 2290 | /* check page 1, reg 0x60 */ |
| 2291 | val = snd_ac97_read(ac97, AC97_INT_PAGING); |
| 2292 | snd_ac97_write_cache(ac97, AC97_INT_PAGING, (val & ~0x0f) | 0x01); |
| 2293 | tmp = snd_ac97_read(ac97, 0x60); |
| 2294 | ac97->spec.dev_flags = tmp & 1; /* revision B? */ |
| 2295 | snd_ac97_write_cache(ac97, AC97_INT_PAGING, val); |
| 2296 | } |
| 2297 | |
| 2298 | ac97->build_ops = &patch_cm9761_ops; |
| 2299 | |
| 2300 | /* enable spdif */ |
| 2301 | /* force the SPDIF bit in ext_id - codec doesn't set this bit! */ |
| 2302 | ac97->ext_id |= AC97_EI_SPDIF; |
| 2303 | /* to be sure: we overwrite the ext status bits */ |
| 2304 | snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, 0x05c0); |
| 2305 | /* Don't set 0x0200 here. This results in the silent analog output */ |
Takashi Iwai | 5f0dccf | 2005-04-07 15:53:20 +0200 | [diff] [blame] | 2306 | 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] | 2307 | ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */ |
| 2308 | |
| 2309 | /* set-up multi channel */ |
| 2310 | /* bit 15: pc master beep off |
Takashi Iwai | 5f0dccf | 2005-04-07 15:53:20 +0200 | [diff] [blame] | 2311 | * bit 14: pin47 = EAPD/SPDIF |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2312 | * bit 13: vref ctl [= cm9739] |
Takashi Iwai | 5f0dccf | 2005-04-07 15:53:20 +0200 | [diff] [blame] | 2313 | * bit 12: CLFE control (reverted on rev B) |
| 2314 | * bit 11: Mic/center share (reverted on rev B) |
| 2315 | * bit 10: suddound/line share |
| 2316 | * bit 9: Analog-in mix -> surround |
| 2317 | * bit 8: Analog-in mix -> CLFE |
| 2318 | * bit 7: Mic/LFE share (mic/center/lfe) |
| 2319 | * bit 5: vref select (9761A) |
| 2320 | * bit 4: front control |
| 2321 | * bit 3: surround control (revereted with rev B) |
| 2322 | * bit 2: front mic |
| 2323 | * bit 1: stereo mic |
| 2324 | * bit 0: mic boost level (0=20dB, 1=30dB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2325 | */ |
| 2326 | |
| 2327 | #if 0 |
| 2328 | if (ac97->spec.dev_flags) |
| 2329 | val = 0x0214; |
| 2330 | else |
| 2331 | val = 0x321c; |
| 2332 | #endif |
| 2333 | val = snd_ac97_read(ac97, AC97_CM9761_MULTI_CHAN); |
| 2334 | val |= (1 << 4); /* front on */ |
| 2335 | snd_ac97_write_cache(ac97, AC97_CM9761_MULTI_CHAN, val); |
| 2336 | |
| 2337 | /* FIXME: set up GPIO */ |
| 2338 | snd_ac97_write_cache(ac97, 0x70, 0x0100); |
| 2339 | snd_ac97_write_cache(ac97, 0x72, 0x0020); |
| 2340 | |
| 2341 | return 0; |
| 2342 | } |
| 2343 | |
Takashi Iwai | 5f0dccf | 2005-04-07 15:53:20 +0200 | [diff] [blame] | 2344 | #define AC97_CM9780_SIDE 0x60 |
| 2345 | #define AC97_CM9780_JACK 0x62 |
| 2346 | #define AC97_CM9780_MIXER 0x64 |
| 2347 | #define AC97_CM9780_MULTI_CHAN 0x66 |
| 2348 | #define AC97_CM9780_SPDIF 0x6c |
| 2349 | |
| 2350 | static const char *cm9780_ch_select[] = { "Front", "Side", "Center/LFE", "Rear" }; |
| 2351 | static const struct ac97_enum cm9780_ch_select_enum = |
| 2352 | AC97_ENUM_SINGLE(AC97_CM9780_MULTI_CHAN, 6, 4, cm9780_ch_select); |
| 2353 | static const snd_kcontrol_new_t cm9780_controls[] = { |
| 2354 | AC97_DOUBLE("Side Playback Switch", AC97_CM9780_SIDE, 15, 7, 1, 1), |
| 2355 | AC97_DOUBLE("Side Playback Volume", AC97_CM9780_SIDE, 8, 0, 31, 0), |
| 2356 | AC97_ENUM("Side Playback Route", cm9780_ch_select_enum), |
| 2357 | }; |
| 2358 | |
| 2359 | static int patch_cm9780_specific(ac97_t *ac97) |
| 2360 | { |
| 2361 | return patch_build_controls(ac97, cm9780_controls, ARRAY_SIZE(cm9780_controls)); |
| 2362 | } |
| 2363 | |
| 2364 | static struct snd_ac97_build_ops patch_cm9780_ops = { |
| 2365 | .build_specific = patch_cm9780_specific, |
| 2366 | .build_post_spdif = patch_cm9761_post_spdif /* identical with CM9761 */ |
| 2367 | }; |
| 2368 | |
| 2369 | int patch_cm9780(ac97_t *ac97) |
| 2370 | { |
| 2371 | unsigned short val; |
| 2372 | |
| 2373 | ac97->build_ops = &patch_cm9780_ops; |
| 2374 | |
| 2375 | /* enable spdif */ |
| 2376 | if (ac97->ext_id & AC97_EI_SPDIF) { |
| 2377 | ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */ |
| 2378 | val = snd_ac97_read(ac97, AC97_CM9780_SPDIF); |
| 2379 | val |= 0x1; /* SPDI_EN */ |
| 2380 | snd_ac97_write_cache(ac97, AC97_CM9780_SPDIF, val); |
| 2381 | } |
| 2382 | |
| 2383 | return 0; |
| 2384 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2385 | |
| 2386 | /* |
| 2387 | * VIA VT1616 codec |
| 2388 | */ |
| 2389 | static const snd_kcontrol_new_t snd_ac97_controls_vt1616[] = { |
| 2390 | AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0), |
| 2391 | AC97_SINGLE("Alternate Level to Surround Out", 0x5a, 15, 1, 0), |
| 2392 | AC97_SINGLE("Downmix LFE and Center to Front", 0x5a, 12, 1, 0), |
| 2393 | AC97_SINGLE("Downmix Surround to Front", 0x5a, 11, 1, 0), |
| 2394 | }; |
| 2395 | |
| 2396 | static int patch_vt1616_specific(ac97_t * ac97) |
| 2397 | { |
| 2398 | int err; |
| 2399 | |
| 2400 | if (snd_ac97_try_bit(ac97, 0x5a, 9)) |
| 2401 | if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[0], 1)) < 0) |
| 2402 | return err; |
| 2403 | if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[1], ARRAY_SIZE(snd_ac97_controls_vt1616) - 1)) < 0) |
| 2404 | return err; |
| 2405 | return 0; |
| 2406 | } |
| 2407 | |
| 2408 | static struct snd_ac97_build_ops patch_vt1616_ops = { |
| 2409 | .build_specific = patch_vt1616_specific |
| 2410 | }; |
| 2411 | |
| 2412 | int patch_vt1616(ac97_t * ac97) |
| 2413 | { |
| 2414 | ac97->build_ops = &patch_vt1616_ops; |
| 2415 | return 0; |
| 2416 | } |
| 2417 | |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2418 | /* |
| 2419 | */ |
| 2420 | static void it2646_update_jacks(ac97_t *ac97) |
| 2421 | { |
| 2422 | /* shared Line-In */ |
| 2423 | snd_ac97_update_bits(ac97, 0x76, 1 << 9, |
| 2424 | is_shared_linein(ac97) ? (1<<9) : 0); |
| 2425 | /* shared Mic */ |
| 2426 | snd_ac97_update_bits(ac97, 0x76, 1 << 10, |
| 2427 | is_shared_micin(ac97) ? (1<<10) : 0); |
| 2428 | } |
| 2429 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2430 | static const snd_kcontrol_new_t snd_ac97_controls_it2646[] = { |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2431 | AC97_SURROUND_JACK_MODE_CTL, |
| 2432 | AC97_CHANNEL_MODE_CTL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2433 | }; |
| 2434 | |
| 2435 | static const snd_kcontrol_new_t snd_ac97_spdif_controls_it2646[] = { |
| 2436 | AC97_SINGLE("IEC958 Capture Switch", 0x76, 11, 1, 0), |
| 2437 | AC97_SINGLE("Analog to IEC958 Output", 0x76, 12, 1, 0), |
| 2438 | AC97_SINGLE("IEC958 Input Monitor", 0x76, 13, 1, 0), |
| 2439 | }; |
| 2440 | |
| 2441 | static int patch_it2646_specific(ac97_t * ac97) |
| 2442 | { |
| 2443 | int err; |
| 2444 | if ((err = patch_build_controls(ac97, snd_ac97_controls_it2646, ARRAY_SIZE(snd_ac97_controls_it2646))) < 0) |
| 2445 | return err; |
| 2446 | if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_it2646, ARRAY_SIZE(snd_ac97_spdif_controls_it2646))) < 0) |
| 2447 | return err; |
| 2448 | return 0; |
| 2449 | } |
| 2450 | |
| 2451 | static struct snd_ac97_build_ops patch_it2646_ops = { |
Takashi Iwai | eb8caf3 | 2005-04-13 14:32:57 +0200 | [diff] [blame] | 2452 | .build_specific = patch_it2646_specific, |
| 2453 | .update_jacks = it2646_update_jacks |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2454 | }; |
| 2455 | |
| 2456 | int patch_it2646(ac97_t * ac97) |
| 2457 | { |
| 2458 | ac97->build_ops = &patch_it2646_ops; |
| 2459 | /* full DAC volume */ |
| 2460 | snd_ac97_write_cache(ac97, 0x5E, 0x0808); |
| 2461 | snd_ac97_write_cache(ac97, 0x7A, 0x0808); |
| 2462 | return 0; |
| 2463 | } |
| 2464 | |
Sasha Khapyorsky | 87d61c2 | 2005-05-29 15:08:23 +0200 | [diff] [blame] | 2465 | /* |
| 2466 | * Si3036 codec |
| 2467 | */ |
| 2468 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2469 | #define AC97_SI3036_CHIP_ID 0x5a |
Sasha Khapyorsky | 87d61c2 | 2005-05-29 15:08:23 +0200 | [diff] [blame] | 2470 | #define AC97_SI3036_LINE_CFG 0x5c |
| 2471 | |
| 2472 | static const snd_kcontrol_new_t snd_ac97_controls_si3036[] = { |
| 2473 | AC97_DOUBLE("Modem Speaker Volume", 0x5c, 14, 12, 3, 1) |
| 2474 | }; |
| 2475 | |
| 2476 | static int patch_si3036_specific(ac97_t * ac97) |
| 2477 | { |
| 2478 | return patch_build_controls(ac97, snd_ac97_controls_si3036, ARRAY_SIZE(snd_ac97_controls_si3036)); |
| 2479 | } |
| 2480 | |
| 2481 | static struct snd_ac97_build_ops patch_si3036_ops = { |
| 2482 | .build_specific = patch_si3036_specific, |
| 2483 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2484 | |
| 2485 | int mpatch_si3036(ac97_t * ac97) |
| 2486 | { |
Sasha Khapyorsky | 87d61c2 | 2005-05-29 15:08:23 +0200 | [diff] [blame] | 2487 | ac97->build_ops = &patch_si3036_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2488 | snd_ac97_write_cache(ac97, 0x5c, 0xf210 ); |
| 2489 | snd_ac97_write_cache(ac97, 0x68, 0); |
| 2490 | return 0; |
| 2491 | } |