1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>, 4 * Takashi Iwai <tiwai@suse.de> 5 * Creative Labs, Inc. 6 * Routines for control of EMU10K1 chips / mixer routines 7 * Multichannel PCM support Copyright (c) Lee Revell <rlrevell@joe-job.com> 8 * 9 * Copyright (c) by James Courtier-Dutton <James@superbug.co.uk> 10 * Added EMU 1010 support. 11 * 12 * BUGS: 13 * -- 14 * 15 * TODO: 16 * -- 17 */ 18 19 #include <linux/time.h> 20 #include <linux/init.h> 21 #include <sound/core.h> 22 #include <sound/emu10k1.h> 23 #include <linux/delay.h> 24 #include <sound/tlv.h> 25 26 #include "p17v.h" 27 28 #define AC97_ID_STAC9758 0x83847658 29 30 static const DECLARE_TLV_DB_SCALE(snd_audigy_db_scale2, -10350, 50, 1); /* WM8775 gain scale */ 31 32 33 static int add_ctls(struct snd_emu10k1 *emu, const struct snd_kcontrol_new *tpl, 34 const char * const *ctls, unsigned nctls) 35 { 36 struct snd_kcontrol_new kctl = *tpl; 37 int err; 38 39 for (unsigned i = 0; i < nctls; i++) { 40 kctl.name = ctls[i]; 41 kctl.private_value = i; 42 err = snd_ctl_add(emu->card, snd_ctl_new1(&kctl, emu)); 43 if (err < 0) 44 return err; 45 } 46 return 0; 47 } 48 49 50 static int snd_emu10k1_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 51 { 52 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; 53 uinfo->count = 1; 54 return 0; 55 } 56 57 static int snd_emu10k1_spdif_get(struct snd_kcontrol *kcontrol, 58 struct snd_ctl_elem_value *ucontrol) 59 { 60 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 61 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 62 63 /* Limit: emu->spdif_bits */ 64 if (idx >= 3) 65 return -EINVAL; 66 ucontrol->value.iec958.status[0] = (emu->spdif_bits[idx] >> 0) & 0xff; 67 ucontrol->value.iec958.status[1] = (emu->spdif_bits[idx] >> 8) & 0xff; 68 ucontrol->value.iec958.status[2] = (emu->spdif_bits[idx] >> 16) & 0xff; 69 ucontrol->value.iec958.status[3] = (emu->spdif_bits[idx] >> 24) & 0xff; 70 return 0; 71 } 72 73 static int snd_emu10k1_spdif_get_mask(struct snd_kcontrol *kcontrol, 74 struct snd_ctl_elem_value *ucontrol) 75 { 76 ucontrol->value.iec958.status[0] = 0xff; 77 ucontrol->value.iec958.status[1] = 0xff; 78 ucontrol->value.iec958.status[2] = 0xff; 79 ucontrol->value.iec958.status[3] = 0xff; 80 return 0; 81 } 82 83 #define PAIR_PS(base, one, two, sfx) base " " one sfx, base " " two sfx 84 #define LR_PS(base, sfx) PAIR_PS(base, "Left", "Right", sfx) 85 86 #define ADAT_PS(pfx, sfx) \ 87 pfx "ADAT 0" sfx, pfx "ADAT 1" sfx, pfx "ADAT 2" sfx, pfx "ADAT 3" sfx, \ 88 pfx "ADAT 4" sfx, pfx "ADAT 5" sfx, pfx "ADAT 6" sfx, pfx "ADAT 7" sfx 89 90 #define PAIR_REGS(base, one, two) \ 91 base ## one ## 1, \ 92 base ## two ## 1 93 94 #define LR_REGS(base) PAIR_REGS(base, _LEFT, _RIGHT) 95 96 #define ADAT_REGS(base) \ 97 base+0, base+1, base+2, base+3, base+4, base+5, base+6, base+7 98 99 /* 100 * List of data sources available for each destination 101 */ 102 103 #define DSP_TEXTS \ 104 "DSP 0", "DSP 1", "DSP 2", "DSP 3", "DSP 4", "DSP 5", "DSP 6", "DSP 7", \ 105 "DSP 8", "DSP 9", "DSP 10", "DSP 11", "DSP 12", "DSP 13", "DSP 14", "DSP 15", \ 106 "DSP 16", "DSP 17", "DSP 18", "DSP 19", "DSP 20", "DSP 21", "DSP 22", "DSP 23", \ 107 "DSP 24", "DSP 25", "DSP 26", "DSP 27", "DSP 28", "DSP 29", "DSP 30", "DSP 31" 108 109 #define PAIR_TEXTS(base, one, two) PAIR_PS(base, one, two, "") 110 #define LR_TEXTS(base) LR_PS(base, "") 111 #define ADAT_TEXTS(pfx) ADAT_PS(pfx, "") 112 113 #define EMU32_SRC_REGS \ 114 EMU_SRC_ALICE_EMU32A, \ 115 EMU_SRC_ALICE_EMU32A+1, \ 116 EMU_SRC_ALICE_EMU32A+2, \ 117 EMU_SRC_ALICE_EMU32A+3, \ 118 EMU_SRC_ALICE_EMU32A+4, \ 119 EMU_SRC_ALICE_EMU32A+5, \ 120 EMU_SRC_ALICE_EMU32A+6, \ 121 EMU_SRC_ALICE_EMU32A+7, \ 122 EMU_SRC_ALICE_EMU32A+8, \ 123 EMU_SRC_ALICE_EMU32A+9, \ 124 EMU_SRC_ALICE_EMU32A+0xa, \ 125 EMU_SRC_ALICE_EMU32A+0xb, \ 126 EMU_SRC_ALICE_EMU32A+0xc, \ 127 EMU_SRC_ALICE_EMU32A+0xd, \ 128 EMU_SRC_ALICE_EMU32A+0xe, \ 129 EMU_SRC_ALICE_EMU32A+0xf, \ 130 EMU_SRC_ALICE_EMU32B, \ 131 EMU_SRC_ALICE_EMU32B+1, \ 132 EMU_SRC_ALICE_EMU32B+2, \ 133 EMU_SRC_ALICE_EMU32B+3, \ 134 EMU_SRC_ALICE_EMU32B+4, \ 135 EMU_SRC_ALICE_EMU32B+5, \ 136 EMU_SRC_ALICE_EMU32B+6, \ 137 EMU_SRC_ALICE_EMU32B+7, \ 138 EMU_SRC_ALICE_EMU32B+8, \ 139 EMU_SRC_ALICE_EMU32B+9, \ 140 EMU_SRC_ALICE_EMU32B+0xa, \ 141 EMU_SRC_ALICE_EMU32B+0xb, \ 142 EMU_SRC_ALICE_EMU32B+0xc, \ 143 EMU_SRC_ALICE_EMU32B+0xd, \ 144 EMU_SRC_ALICE_EMU32B+0xe, \ 145 EMU_SRC_ALICE_EMU32B+0xf 146 147 #define EMU1010_COMMON_TEXTS \ 148 "Silence", \ 149 PAIR_TEXTS("Dock Mic", "A", "B"), \ 150 LR_TEXTS("Dock ADC1"), \ 151 LR_TEXTS("Dock ADC2"), \ 152 LR_TEXTS("Dock ADC3"), \ 153 LR_TEXTS("0202 ADC"), \ 154 LR_TEXTS("1010 SPDIF"), \ 155 ADAT_TEXTS("1010 ") 156 157 static const char * const emu1010_src_texts[] = { 158 EMU1010_COMMON_TEXTS, 159 DSP_TEXTS, 160 }; 161 162 static const unsigned short emu1010_src_regs[] = { 163 EMU_SRC_SILENCE, 164 PAIR_REGS(EMU_SRC_DOCK_MIC, _A, _B), 165 LR_REGS(EMU_SRC_DOCK_ADC1), 166 LR_REGS(EMU_SRC_DOCK_ADC2), 167 LR_REGS(EMU_SRC_DOCK_ADC3), 168 LR_REGS(EMU_SRC_HAMOA_ADC), 169 LR_REGS(EMU_SRC_HANA_SPDIF), 170 ADAT_REGS(EMU_SRC_HANA_ADAT), 171 EMU32_SRC_REGS, 172 }; 173 static_assert(ARRAY_SIZE(emu1010_src_regs) == ARRAY_SIZE(emu1010_src_texts)); 174 175 /* 1616(m) cardbus */ 176 177 #define EMU1616_COMMON_TEXTS \ 178 "Silence", \ 179 PAIR_TEXTS("Mic", "A", "B"), \ 180 LR_TEXTS("ADC1"), \ 181 LR_TEXTS("ADC2"), \ 182 LR_TEXTS("SPDIF"), \ 183 ADAT_TEXTS("") 184 185 static const char * const emu1616_src_texts[] = { 186 EMU1616_COMMON_TEXTS, 187 DSP_TEXTS, 188 }; 189 190 static const unsigned short emu1616_src_regs[] = { 191 EMU_SRC_SILENCE, 192 PAIR_REGS(EMU_SRC_DOCK_MIC, _A, _B), 193 LR_REGS(EMU_SRC_DOCK_ADC1), 194 LR_REGS(EMU_SRC_DOCK_ADC2), 195 LR_REGS(EMU_SRC_MDOCK_SPDIF), 196 ADAT_REGS(EMU_SRC_MDOCK_ADAT), 197 EMU32_SRC_REGS, 198 }; 199 static_assert(ARRAY_SIZE(emu1616_src_regs) == ARRAY_SIZE(emu1616_src_texts)); 200 201 /* 202 * Data destinations - physical EMU outputs. 203 * Each destination has an enum mixer control to choose a data source 204 */ 205 206 #define LR_CTLS(base) LR_PS(base, " Playback Enum") 207 #define ADAT_CTLS(pfx) ADAT_PS(pfx, " Playback Enum") 208 209 static const char * const emu1010_output_texts[] = { 210 LR_CTLS("Dock DAC1"), 211 LR_CTLS("Dock DAC2"), 212 LR_CTLS("Dock DAC3"), 213 LR_CTLS("Dock DAC4"), 214 LR_CTLS("Dock Phones"), 215 LR_CTLS("Dock SPDIF"), 216 LR_CTLS("0202 DAC"), 217 LR_CTLS("1010 SPDIF"), 218 ADAT_CTLS("1010 "), 219 }; 220 221 static const unsigned short emu1010_output_dst[] = { 222 LR_REGS(EMU_DST_DOCK_DAC1), 223 LR_REGS(EMU_DST_DOCK_DAC2), 224 LR_REGS(EMU_DST_DOCK_DAC3), 225 LR_REGS(EMU_DST_DOCK_DAC4), 226 LR_REGS(EMU_DST_DOCK_PHONES), 227 LR_REGS(EMU_DST_DOCK_SPDIF), 228 LR_REGS(EMU_DST_HAMOA_DAC), 229 LR_REGS(EMU_DST_HANA_SPDIF), 230 ADAT_REGS(EMU_DST_HANA_ADAT), 231 }; 232 static_assert(ARRAY_SIZE(emu1010_output_dst) == ARRAY_SIZE(emu1010_output_texts)); 233 234 /* 1616(m) cardbus */ 235 236 static const char * const snd_emu1616_output_texts[] = { 237 LR_CTLS("Dock DAC1"), 238 LR_CTLS("Dock DAC2"), 239 LR_CTLS("Dock DAC3"), 240 LR_CTLS("Dock SPDIF"), 241 ADAT_CTLS("Dock "), 242 LR_CTLS("Mana DAC"), 243 }; 244 245 static const unsigned short emu1616_output_dst[] = { 246 LR_REGS(EMU_DST_DOCK_DAC1), 247 LR_REGS(EMU_DST_DOCK_DAC2), 248 LR_REGS(EMU_DST_DOCK_DAC3), 249 LR_REGS(EMU_DST_MDOCK_SPDIF), 250 ADAT_REGS(EMU_DST_MDOCK_ADAT), 251 EMU_DST_MANA_DAC_LEFT, EMU_DST_MANA_DAC_RIGHT, 252 }; 253 static_assert(ARRAY_SIZE(emu1616_output_dst) == ARRAY_SIZE(snd_emu1616_output_texts)); 254 255 /* 256 * Data destinations - FPGA outputs going to Alice2 (Audigy) for 257 * capture (EMU32 + I2S links) 258 * Each destination has an enum mixer control to choose a data source 259 */ 260 261 static const char * const emu1010_input_texts[] = { 262 "DSP 0 Capture Enum", 263 "DSP 1 Capture Enum", 264 "DSP 2 Capture Enum", 265 "DSP 3 Capture Enum", 266 "DSP 4 Capture Enum", 267 "DSP 5 Capture Enum", 268 "DSP 6 Capture Enum", 269 "DSP 7 Capture Enum", 270 "DSP 8 Capture Enum", 271 "DSP 9 Capture Enum", 272 "DSP A Capture Enum", 273 "DSP B Capture Enum", 274 "DSP C Capture Enum", 275 "DSP D Capture Enum", 276 "DSP E Capture Enum", 277 "DSP F Capture Enum", 278 /* These exist only on rev1 EMU1010 cards. */ 279 "DSP 10 Capture Enum", 280 "DSP 11 Capture Enum", 281 "DSP 12 Capture Enum", 282 "DSP 13 Capture Enum", 283 "DSP 14 Capture Enum", 284 "DSP 15 Capture Enum", 285 }; 286 287 static const unsigned short emu1010_input_dst[] = { 288 EMU_DST_ALICE2_EMU32_0, 289 EMU_DST_ALICE2_EMU32_1, 290 EMU_DST_ALICE2_EMU32_2, 291 EMU_DST_ALICE2_EMU32_3, 292 EMU_DST_ALICE2_EMU32_4, 293 EMU_DST_ALICE2_EMU32_5, 294 EMU_DST_ALICE2_EMU32_6, 295 EMU_DST_ALICE2_EMU32_7, 296 EMU_DST_ALICE2_EMU32_8, 297 EMU_DST_ALICE2_EMU32_9, 298 EMU_DST_ALICE2_EMU32_A, 299 EMU_DST_ALICE2_EMU32_B, 300 EMU_DST_ALICE2_EMU32_C, 301 EMU_DST_ALICE2_EMU32_D, 302 EMU_DST_ALICE2_EMU32_E, 303 EMU_DST_ALICE2_EMU32_F, 304 /* These exist only on rev1 EMU1010 cards. */ 305 EMU_DST_ALICE_I2S0_LEFT, 306 EMU_DST_ALICE_I2S0_RIGHT, 307 EMU_DST_ALICE_I2S1_LEFT, 308 EMU_DST_ALICE_I2S1_RIGHT, 309 EMU_DST_ALICE_I2S2_LEFT, 310 EMU_DST_ALICE_I2S2_RIGHT, 311 }; 312 static_assert(ARRAY_SIZE(emu1010_input_dst) == ARRAY_SIZE(emu1010_input_texts)); 313 314 struct snd_emu1010_routing_info { 315 const char * const *src_texts; 316 const unsigned short *src_regs; 317 const unsigned short *out_regs; 318 const unsigned short *in_regs; 319 unsigned n_srcs; 320 unsigned n_outs; 321 unsigned n_ins; 322 }; 323 324 const struct snd_emu1010_routing_info emu1010_routing_info[] = { 325 { 326 .src_regs = emu1010_src_regs, 327 .src_texts = emu1010_src_texts, 328 .n_srcs = ARRAY_SIZE(emu1010_src_texts), 329 330 .out_regs = emu1010_output_dst, 331 .n_outs = ARRAY_SIZE(emu1010_output_dst), 332 333 .in_regs = emu1010_input_dst, 334 .n_ins = ARRAY_SIZE(emu1010_input_dst), 335 }, 336 { 337 /* 1616(m) cardbus */ 338 .src_regs = emu1616_src_regs, 339 .src_texts = emu1616_src_texts, 340 .n_srcs = ARRAY_SIZE(emu1616_src_texts), 341 342 .out_regs = emu1616_output_dst, 343 .n_outs = ARRAY_SIZE(emu1616_output_dst), 344 345 .in_regs = emu1010_input_dst, 346 .n_ins = ARRAY_SIZE(emu1010_input_dst) - 6, 347 }, 348 }; 349 350 static unsigned emu1010_idx(struct snd_emu10k1 *emu) 351 { 352 if (emu->card_capabilities->emu_model == EMU_MODEL_EMU1616) 353 return 1; 354 else 355 return 0; 356 } 357 358 static void snd_emu1010_output_source_apply(struct snd_emu10k1 *emu, 359 int channel, int src) 360 { 361 const struct snd_emu1010_routing_info *emu_ri = 362 &emu1010_routing_info[emu1010_idx(emu)]; 363 364 snd_emu1010_fpga_link_dst_src_write(emu, 365 emu_ri->out_regs[channel], emu_ri->src_regs[src]); 366 } 367 368 static void snd_emu1010_input_source_apply(struct snd_emu10k1 *emu, 369 int channel, int src) 370 { 371 const struct snd_emu1010_routing_info *emu_ri = 372 &emu1010_routing_info[emu1010_idx(emu)]; 373 374 snd_emu1010_fpga_link_dst_src_write(emu, 375 emu_ri->in_regs[channel], emu_ri->src_regs[src]); 376 } 377 378 static int snd_emu1010_input_output_source_info(struct snd_kcontrol *kcontrol, 379 struct snd_ctl_elem_info *uinfo) 380 { 381 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 382 const struct snd_emu1010_routing_info *emu_ri = 383 &emu1010_routing_info[emu1010_idx(emu)]; 384 385 return snd_ctl_enum_info(uinfo, 1, emu_ri->n_srcs, emu_ri->src_texts); 386 } 387 388 static int snd_emu1010_output_source_get(struct snd_kcontrol *kcontrol, 389 struct snd_ctl_elem_value *ucontrol) 390 { 391 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 392 const struct snd_emu1010_routing_info *emu_ri = 393 &emu1010_routing_info[emu1010_idx(emu)]; 394 unsigned channel = kcontrol->private_value; 395 396 if (channel >= emu_ri->n_outs) 397 return -EINVAL; 398 ucontrol->value.enumerated.item[0] = emu->emu1010.output_source[channel]; 399 return 0; 400 } 401 402 static int snd_emu1010_output_source_put(struct snd_kcontrol *kcontrol, 403 struct snd_ctl_elem_value *ucontrol) 404 { 405 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 406 const struct snd_emu1010_routing_info *emu_ri = 407 &emu1010_routing_info[emu1010_idx(emu)]; 408 unsigned val = ucontrol->value.enumerated.item[0]; 409 unsigned channel = kcontrol->private_value; 410 int change; 411 412 if (val >= emu_ri->n_srcs) 413 return -EINVAL; 414 if (channel >= emu_ri->n_outs) 415 return -EINVAL; 416 change = (emu->emu1010.output_source[channel] != val); 417 if (change) { 418 emu->emu1010.output_source[channel] = val; 419 snd_emu1010_output_source_apply(emu, channel, val); 420 } 421 return change; 422 } 423 424 static const struct snd_kcontrol_new emu1010_output_source_ctl = { 425 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 426 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, 427 .info = snd_emu1010_input_output_source_info, 428 .get = snd_emu1010_output_source_get, 429 .put = snd_emu1010_output_source_put 430 }; 431 432 static int snd_emu1010_input_source_get(struct snd_kcontrol *kcontrol, 433 struct snd_ctl_elem_value *ucontrol) 434 { 435 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 436 const struct snd_emu1010_routing_info *emu_ri = 437 &emu1010_routing_info[emu1010_idx(emu)]; 438 unsigned channel = kcontrol->private_value; 439 440 if (channel >= emu_ri->n_ins) 441 return -EINVAL; 442 ucontrol->value.enumerated.item[0] = emu->emu1010.input_source[channel]; 443 return 0; 444 } 445 446 static int snd_emu1010_input_source_put(struct snd_kcontrol *kcontrol, 447 struct snd_ctl_elem_value *ucontrol) 448 { 449 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 450 const struct snd_emu1010_routing_info *emu_ri = 451 &emu1010_routing_info[emu1010_idx(emu)]; 452 unsigned val = ucontrol->value.enumerated.item[0]; 453 unsigned channel = kcontrol->private_value; 454 int change; 455 456 if (val >= emu_ri->n_srcs) 457 return -EINVAL; 458 if (channel >= emu_ri->n_ins) 459 return -EINVAL; 460 change = (emu->emu1010.input_source[channel] != val); 461 if (change) { 462 emu->emu1010.input_source[channel] = val; 463 snd_emu1010_input_source_apply(emu, channel, val); 464 } 465 return change; 466 } 467 468 static const struct snd_kcontrol_new emu1010_input_source_ctl = { 469 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 470 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, 471 .info = snd_emu1010_input_output_source_info, 472 .get = snd_emu1010_input_source_get, 473 .put = snd_emu1010_input_source_put 474 }; 475 476 477 static const char * const snd_emu1010_adc_pads[] = { 478 "ADC1 14dB PAD Audio Dock Capture Switch", 479 "ADC2 14dB PAD Audio Dock Capture Switch", 480 "ADC3 14dB PAD Audio Dock Capture Switch", 481 "ADC1 14dB PAD 0202 Capture Switch", 482 }; 483 484 static const unsigned short snd_emu1010_adc_pad_regs[] = { 485 EMU_HANA_DOCK_ADC_PAD1, 486 EMU_HANA_DOCK_ADC_PAD2, 487 EMU_HANA_DOCK_ADC_PAD3, 488 EMU_HANA_0202_ADC_PAD1, 489 }; 490 491 #define snd_emu1010_adc_pads_info snd_ctl_boolean_mono_info 492 493 static int snd_emu1010_adc_pads_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 494 { 495 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 496 unsigned int mask = snd_emu1010_adc_pad_regs[kcontrol->private_value]; 497 498 ucontrol->value.integer.value[0] = (emu->emu1010.adc_pads & mask) ? 1 : 0; 499 return 0; 500 } 501 502 static int snd_emu1010_adc_pads_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 503 { 504 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 505 unsigned int mask = snd_emu1010_adc_pad_regs[kcontrol->private_value]; 506 unsigned int val, cache; 507 val = ucontrol->value.integer.value[0]; 508 cache = emu->emu1010.adc_pads; 509 if (val == 1) 510 cache = cache | mask; 511 else 512 cache = cache & ~mask; 513 if (cache != emu->emu1010.adc_pads) { 514 snd_emu1010_fpga_write(emu, EMU_HANA_ADC_PADS, cache ); 515 emu->emu1010.adc_pads = cache; 516 } 517 518 return 0; 519 } 520 521 static const struct snd_kcontrol_new emu1010_adc_pads_ctl = { 522 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 523 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, 524 .info = snd_emu1010_adc_pads_info, 525 .get = snd_emu1010_adc_pads_get, 526 .put = snd_emu1010_adc_pads_put 527 }; 528 529 530 static const char * const snd_emu1010_dac_pads[] = { 531 "DAC1 Audio Dock 14dB PAD Playback Switch", 532 "DAC2 Audio Dock 14dB PAD Playback Switch", 533 "DAC3 Audio Dock 14dB PAD Playback Switch", 534 "DAC4 Audio Dock 14dB PAD Playback Switch", 535 "DAC1 0202 14dB PAD Playback Switch", 536 }; 537 538 static const unsigned short snd_emu1010_dac_regs[] = { 539 EMU_HANA_DOCK_DAC_PAD1, 540 EMU_HANA_DOCK_DAC_PAD2, 541 EMU_HANA_DOCK_DAC_PAD3, 542 EMU_HANA_DOCK_DAC_PAD4, 543 EMU_HANA_0202_DAC_PAD1, 544 }; 545 546 #define snd_emu1010_dac_pads_info snd_ctl_boolean_mono_info 547 548 static int snd_emu1010_dac_pads_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 549 { 550 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 551 unsigned int mask = snd_emu1010_dac_regs[kcontrol->private_value]; 552 553 ucontrol->value.integer.value[0] = (emu->emu1010.dac_pads & mask) ? 1 : 0; 554 return 0; 555 } 556 557 static int snd_emu1010_dac_pads_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 558 { 559 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 560 unsigned int mask = snd_emu1010_dac_regs[kcontrol->private_value]; 561 unsigned int val, cache; 562 val = ucontrol->value.integer.value[0]; 563 cache = emu->emu1010.dac_pads; 564 if (val == 1) 565 cache = cache | mask; 566 else 567 cache = cache & ~mask; 568 if (cache != emu->emu1010.dac_pads) { 569 snd_emu1010_fpga_write(emu, EMU_HANA_DAC_PADS, cache ); 570 emu->emu1010.dac_pads = cache; 571 } 572 573 return 0; 574 } 575 576 static const struct snd_kcontrol_new emu1010_dac_pads_ctl = { 577 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 578 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, 579 .info = snd_emu1010_dac_pads_info, 580 .get = snd_emu1010_dac_pads_get, 581 .put = snd_emu1010_dac_pads_put 582 }; 583 584 585 static int snd_emu1010_internal_clock_info(struct snd_kcontrol *kcontrol, 586 struct snd_ctl_elem_info *uinfo) 587 { 588 static const char * const texts[4] = { 589 "44100", "48000", "SPDIF", "ADAT" 590 }; 591 592 return snd_ctl_enum_info(uinfo, 1, 4, texts); 593 } 594 595 static int snd_emu1010_internal_clock_get(struct snd_kcontrol *kcontrol, 596 struct snd_ctl_elem_value *ucontrol) 597 { 598 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 599 600 ucontrol->value.enumerated.item[0] = emu->emu1010.internal_clock; 601 return 0; 602 } 603 604 static int snd_emu1010_internal_clock_put(struct snd_kcontrol *kcontrol, 605 struct snd_ctl_elem_value *ucontrol) 606 { 607 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 608 unsigned int val; 609 int change = 0; 610 611 val = ucontrol->value.enumerated.item[0] ; 612 /* Limit: uinfo->value.enumerated.items = 4; */ 613 if (val >= 4) 614 return -EINVAL; 615 change = (emu->emu1010.internal_clock != val); 616 if (change) { 617 emu->emu1010.internal_clock = val; 618 switch (val) { 619 case 0: 620 /* 44100 */ 621 /* Mute all */ 622 snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_MUTE ); 623 /* Default fallback clock 44.1kHz */ 624 snd_emu1010_fpga_write(emu, EMU_HANA_DEFCLOCK, EMU_HANA_DEFCLOCK_44_1K ); 625 /* Word Clock source, Internal 44.1kHz x1 */ 626 snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK, 627 EMU_HANA_WCLOCK_INT_44_1K | EMU_HANA_WCLOCK_1X ); 628 /* Set LEDs on Audio Dock */ 629 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_LEDS_2, 630 EMU_HANA_DOCK_LEDS_2_44K | EMU_HANA_DOCK_LEDS_2_LOCK ); 631 /* Allow DLL to settle */ 632 msleep(10); 633 /* Unmute all */ 634 snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE ); 635 break; 636 case 1: 637 /* 48000 */ 638 /* Mute all */ 639 snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_MUTE ); 640 /* Default fallback clock 48kHz */ 641 snd_emu1010_fpga_write(emu, EMU_HANA_DEFCLOCK, EMU_HANA_DEFCLOCK_48K ); 642 /* Word Clock source, Internal 48kHz x1 */ 643 snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK, 644 EMU_HANA_WCLOCK_INT_48K | EMU_HANA_WCLOCK_1X ); 645 /* Set LEDs on Audio Dock */ 646 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_LEDS_2, 647 EMU_HANA_DOCK_LEDS_2_48K | EMU_HANA_DOCK_LEDS_2_LOCK ); 648 /* Allow DLL to settle */ 649 msleep(10); 650 /* Unmute all */ 651 snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE ); 652 break; 653 654 case 2: /* Take clock from S/PDIF IN */ 655 /* Mute all */ 656 snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_MUTE ); 657 /* Default fallback clock 48kHz */ 658 snd_emu1010_fpga_write(emu, EMU_HANA_DEFCLOCK, EMU_HANA_DEFCLOCK_48K ); 659 /* Word Clock source, sync to S/PDIF input */ 660 snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK, 661 EMU_HANA_WCLOCK_HANA_SPDIF_IN | EMU_HANA_WCLOCK_1X ); 662 /* Set LEDs on Audio Dock */ 663 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_LEDS_2, 664 EMU_HANA_DOCK_LEDS_2_EXT | EMU_HANA_DOCK_LEDS_2_LOCK ); 665 /* FIXME: We should set EMU_HANA_DOCK_LEDS_2_LOCK only when clock signal is present and valid */ 666 /* Allow DLL to settle */ 667 msleep(10); 668 /* Unmute all */ 669 snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE ); 670 break; 671 672 case 3: 673 /* Take clock from ADAT IN */ 674 /* Mute all */ 675 snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_MUTE ); 676 /* Default fallback clock 48kHz */ 677 snd_emu1010_fpga_write(emu, EMU_HANA_DEFCLOCK, EMU_HANA_DEFCLOCK_48K ); 678 /* Word Clock source, sync to ADAT input */ 679 snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK, 680 EMU_HANA_WCLOCK_HANA_ADAT_IN | EMU_HANA_WCLOCK_1X ); 681 /* Set LEDs on Audio Dock */ 682 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_LEDS_2, EMU_HANA_DOCK_LEDS_2_EXT | EMU_HANA_DOCK_LEDS_2_LOCK ); 683 /* FIXME: We should set EMU_HANA_DOCK_LEDS_2_LOCK only when clock signal is present and valid */ 684 /* Allow DLL to settle */ 685 msleep(10); 686 /* Unmute all */ 687 snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE ); 688 689 690 break; 691 } 692 } 693 return change; 694 } 695 696 static const struct snd_kcontrol_new snd_emu1010_internal_clock = 697 { 698 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, 699 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 700 .name = "Clock Internal Rate", 701 .count = 1, 702 .info = snd_emu1010_internal_clock_info, 703 .get = snd_emu1010_internal_clock_get, 704 .put = snd_emu1010_internal_clock_put 705 }; 706 707 static int snd_emu1010_optical_out_info(struct snd_kcontrol *kcontrol, 708 struct snd_ctl_elem_info *uinfo) 709 { 710 static const char * const texts[2] = { 711 "SPDIF", "ADAT" 712 }; 713 714 return snd_ctl_enum_info(uinfo, 1, 2, texts); 715 } 716 717 static int snd_emu1010_optical_out_get(struct snd_kcontrol *kcontrol, 718 struct snd_ctl_elem_value *ucontrol) 719 { 720 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 721 722 ucontrol->value.enumerated.item[0] = emu->emu1010.optical_out; 723 return 0; 724 } 725 726 static int snd_emu1010_optical_out_put(struct snd_kcontrol *kcontrol, 727 struct snd_ctl_elem_value *ucontrol) 728 { 729 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 730 unsigned int val; 731 u32 tmp; 732 int change = 0; 733 734 val = ucontrol->value.enumerated.item[0]; 735 /* Limit: uinfo->value.enumerated.items = 2; */ 736 if (val >= 2) 737 return -EINVAL; 738 change = (emu->emu1010.optical_out != val); 739 if (change) { 740 emu->emu1010.optical_out = val; 741 tmp = (emu->emu1010.optical_in ? EMU_HANA_OPTICAL_IN_ADAT : EMU_HANA_OPTICAL_IN_SPDIF) | 742 (emu->emu1010.optical_out ? EMU_HANA_OPTICAL_OUT_ADAT : EMU_HANA_OPTICAL_OUT_SPDIF); 743 snd_emu1010_fpga_write(emu, EMU_HANA_OPTICAL_TYPE, tmp); 744 } 745 return change; 746 } 747 748 static const struct snd_kcontrol_new snd_emu1010_optical_out = { 749 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, 750 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 751 .name = "Optical Output Mode", 752 .count = 1, 753 .info = snd_emu1010_optical_out_info, 754 .get = snd_emu1010_optical_out_get, 755 .put = snd_emu1010_optical_out_put 756 }; 757 758 static int snd_emu1010_optical_in_info(struct snd_kcontrol *kcontrol, 759 struct snd_ctl_elem_info *uinfo) 760 { 761 static const char * const texts[2] = { 762 "SPDIF", "ADAT" 763 }; 764 765 return snd_ctl_enum_info(uinfo, 1, 2, texts); 766 } 767 768 static int snd_emu1010_optical_in_get(struct snd_kcontrol *kcontrol, 769 struct snd_ctl_elem_value *ucontrol) 770 { 771 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 772 773 ucontrol->value.enumerated.item[0] = emu->emu1010.optical_in; 774 return 0; 775 } 776 777 static int snd_emu1010_optical_in_put(struct snd_kcontrol *kcontrol, 778 struct snd_ctl_elem_value *ucontrol) 779 { 780 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 781 unsigned int val; 782 u32 tmp; 783 int change = 0; 784 785 val = ucontrol->value.enumerated.item[0]; 786 /* Limit: uinfo->value.enumerated.items = 2; */ 787 if (val >= 2) 788 return -EINVAL; 789 change = (emu->emu1010.optical_in != val); 790 if (change) { 791 emu->emu1010.optical_in = val; 792 tmp = (emu->emu1010.optical_in ? EMU_HANA_OPTICAL_IN_ADAT : EMU_HANA_OPTICAL_IN_SPDIF) | 793 (emu->emu1010.optical_out ? EMU_HANA_OPTICAL_OUT_ADAT : EMU_HANA_OPTICAL_OUT_SPDIF); 794 snd_emu1010_fpga_write(emu, EMU_HANA_OPTICAL_TYPE, tmp); 795 } 796 return change; 797 } 798 799 static const struct snd_kcontrol_new snd_emu1010_optical_in = { 800 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, 801 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 802 .name = "Optical Input Mode", 803 .count = 1, 804 .info = snd_emu1010_optical_in_info, 805 .get = snd_emu1010_optical_in_get, 806 .put = snd_emu1010_optical_in_put 807 }; 808 809 static int snd_audigy_i2c_capture_source_info(struct snd_kcontrol *kcontrol, 810 struct snd_ctl_elem_info *uinfo) 811 { 812 #if 0 813 static const char * const texts[4] = { 814 "Unknown1", "Unknown2", "Mic", "Line" 815 }; 816 #endif 817 static const char * const texts[2] = { 818 "Mic", "Line" 819 }; 820 821 return snd_ctl_enum_info(uinfo, 1, 2, texts); 822 } 823 824 static int snd_audigy_i2c_capture_source_get(struct snd_kcontrol *kcontrol, 825 struct snd_ctl_elem_value *ucontrol) 826 { 827 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 828 829 ucontrol->value.enumerated.item[0] = emu->i2c_capture_source; 830 return 0; 831 } 832 833 static int snd_audigy_i2c_capture_source_put(struct snd_kcontrol *kcontrol, 834 struct snd_ctl_elem_value *ucontrol) 835 { 836 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 837 unsigned int source_id; 838 unsigned int ngain, ogain; 839 u16 gpio; 840 int change = 0; 841 unsigned long flags; 842 u32 source; 843 /* If the capture source has changed, 844 * update the capture volume from the cached value 845 * for the particular source. 846 */ 847 source_id = ucontrol->value.enumerated.item[0]; 848 /* Limit: uinfo->value.enumerated.items = 2; */ 849 /* emu->i2c_capture_volume */ 850 if (source_id >= 2) 851 return -EINVAL; 852 change = (emu->i2c_capture_source != source_id); 853 if (change) { 854 snd_emu10k1_i2c_write(emu, ADC_MUX, 0); /* Mute input */ 855 spin_lock_irqsave(&emu->emu_lock, flags); 856 gpio = inw(emu->port + A_IOCFG); 857 if (source_id==0) 858 outw(gpio | 0x4, emu->port + A_IOCFG); 859 else 860 outw(gpio & ~0x4, emu->port + A_IOCFG); 861 spin_unlock_irqrestore(&emu->emu_lock, flags); 862 863 ngain = emu->i2c_capture_volume[source_id][0]; /* Left */ 864 ogain = emu->i2c_capture_volume[emu->i2c_capture_source][0]; /* Left */ 865 if (ngain != ogain) 866 snd_emu10k1_i2c_write(emu, ADC_ATTEN_ADCL, ((ngain) & 0xff)); 867 ngain = emu->i2c_capture_volume[source_id][1]; /* Right */ 868 ogain = emu->i2c_capture_volume[emu->i2c_capture_source][1]; /* Right */ 869 if (ngain != ogain) 870 snd_emu10k1_i2c_write(emu, ADC_ATTEN_ADCR, ((ngain) & 0xff)); 871 872 source = 1 << (source_id + 2); 873 snd_emu10k1_i2c_write(emu, ADC_MUX, source); /* Set source */ 874 emu->i2c_capture_source = source_id; 875 } 876 return change; 877 } 878 879 static const struct snd_kcontrol_new snd_audigy_i2c_capture_source = 880 { 881 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 882 .name = "Capture Source", 883 .info = snd_audigy_i2c_capture_source_info, 884 .get = snd_audigy_i2c_capture_source_get, 885 .put = snd_audigy_i2c_capture_source_put 886 }; 887 888 static int snd_audigy_i2c_volume_info(struct snd_kcontrol *kcontrol, 889 struct snd_ctl_elem_info *uinfo) 890 { 891 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 892 uinfo->count = 2; 893 uinfo->value.integer.min = 0; 894 uinfo->value.integer.max = 255; 895 return 0; 896 } 897 898 static int snd_audigy_i2c_volume_get(struct snd_kcontrol *kcontrol, 899 struct snd_ctl_elem_value *ucontrol) 900 { 901 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 902 unsigned int source_id; 903 904 source_id = kcontrol->private_value; 905 /* Limit: emu->i2c_capture_volume */ 906 /* capture_source: uinfo->value.enumerated.items = 2 */ 907 if (source_id >= 2) 908 return -EINVAL; 909 910 ucontrol->value.integer.value[0] = emu->i2c_capture_volume[source_id][0]; 911 ucontrol->value.integer.value[1] = emu->i2c_capture_volume[source_id][1]; 912 return 0; 913 } 914 915 static int snd_audigy_i2c_volume_put(struct snd_kcontrol *kcontrol, 916 struct snd_ctl_elem_value *ucontrol) 917 { 918 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 919 unsigned int ogain; 920 unsigned int ngain0, ngain1; 921 unsigned int source_id; 922 int change = 0; 923 924 source_id = kcontrol->private_value; 925 /* Limit: emu->i2c_capture_volume */ 926 /* capture_source: uinfo->value.enumerated.items = 2 */ 927 if (source_id >= 2) 928 return -EINVAL; 929 ngain0 = ucontrol->value.integer.value[0]; 930 ngain1 = ucontrol->value.integer.value[1]; 931 if (ngain0 > 0xff) 932 return -EINVAL; 933 if (ngain1 > 0xff) 934 return -EINVAL; 935 ogain = emu->i2c_capture_volume[source_id][0]; /* Left */ 936 if (ogain != ngain0) { 937 if (emu->i2c_capture_source == source_id) 938 snd_emu10k1_i2c_write(emu, ADC_ATTEN_ADCL, ngain0); 939 emu->i2c_capture_volume[source_id][0] = ngain0; 940 change = 1; 941 } 942 ogain = emu->i2c_capture_volume[source_id][1]; /* Right */ 943 if (ogain != ngain1) { 944 if (emu->i2c_capture_source == source_id) 945 snd_emu10k1_i2c_write(emu, ADC_ATTEN_ADCR, ngain1); 946 emu->i2c_capture_volume[source_id][1] = ngain1; 947 change = 1; 948 } 949 950 return change; 951 } 952 953 static const struct snd_kcontrol_new i2c_volume_ctl = { 954 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 955 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | 956 SNDRV_CTL_ELEM_ACCESS_TLV_READ, 957 .info = snd_audigy_i2c_volume_info, 958 .get = snd_audigy_i2c_volume_get, 959 .put = snd_audigy_i2c_volume_put, 960 .tlv = { .p = snd_audigy_db_scale2 } 961 }; 962 963 static const char * const snd_audigy_i2c_volume_ctls[] = { 964 "Mic Capture Volume", 965 "Line Capture Volume", 966 }; 967 968 #if 0 969 static int snd_audigy_spdif_output_rate_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 970 { 971 static const char * const texts[] = {"44100", "48000", "96000"}; 972 973 return snd_ctl_enum_info(uinfo, 1, 3, texts); 974 } 975 976 static int snd_audigy_spdif_output_rate_get(struct snd_kcontrol *kcontrol, 977 struct snd_ctl_elem_value *ucontrol) 978 { 979 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 980 unsigned int tmp; 981 982 tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0); 983 switch (tmp & A_SPDIF_RATE_MASK) { 984 case A_SPDIF_44100: 985 ucontrol->value.enumerated.item[0] = 0; 986 break; 987 case A_SPDIF_48000: 988 ucontrol->value.enumerated.item[0] = 1; 989 break; 990 case A_SPDIF_96000: 991 ucontrol->value.enumerated.item[0] = 2; 992 break; 993 default: 994 ucontrol->value.enumerated.item[0] = 1; 995 } 996 return 0; 997 } 998 999 static int snd_audigy_spdif_output_rate_put(struct snd_kcontrol *kcontrol, 1000 struct snd_ctl_elem_value *ucontrol) 1001 { 1002 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 1003 int change; 1004 unsigned int reg, val, tmp; 1005 unsigned long flags; 1006 1007 switch(ucontrol->value.enumerated.item[0]) { 1008 case 0: 1009 val = A_SPDIF_44100; 1010 break; 1011 case 1: 1012 val = A_SPDIF_48000; 1013 break; 1014 case 2: 1015 val = A_SPDIF_96000; 1016 break; 1017 default: 1018 val = A_SPDIF_48000; 1019 break; 1020 } 1021 1022 1023 spin_lock_irqsave(&emu->reg_lock, flags); 1024 reg = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0); 1025 tmp = reg & ~A_SPDIF_RATE_MASK; 1026 tmp |= val; 1027 change = (tmp != reg); 1028 if (change) 1029 snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, 0, tmp); 1030 spin_unlock_irqrestore(&emu->reg_lock, flags); 1031 return change; 1032 } 1033 1034 static const struct snd_kcontrol_new snd_audigy_spdif_output_rate = 1035 { 1036 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, 1037 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1038 .name = "Audigy SPDIF Output Sample Rate", 1039 .count = 1, 1040 .info = snd_audigy_spdif_output_rate_info, 1041 .get = snd_audigy_spdif_output_rate_get, 1042 .put = snd_audigy_spdif_output_rate_put 1043 }; 1044 #endif 1045 1046 static int snd_emu10k1_spdif_put(struct snd_kcontrol *kcontrol, 1047 struct snd_ctl_elem_value *ucontrol) 1048 { 1049 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 1050 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 1051 int change; 1052 unsigned int val; 1053 1054 /* Limit: emu->spdif_bits */ 1055 if (idx >= 3) 1056 return -EINVAL; 1057 val = (ucontrol->value.iec958.status[0] << 0) | 1058 (ucontrol->value.iec958.status[1] << 8) | 1059 (ucontrol->value.iec958.status[2] << 16) | 1060 (ucontrol->value.iec958.status[3] << 24); 1061 change = val != emu->spdif_bits[idx]; 1062 if (change) { 1063 snd_emu10k1_ptr_write(emu, SPCS0 + idx, 0, val); 1064 emu->spdif_bits[idx] = val; 1065 } 1066 return change; 1067 } 1068 1069 static const struct snd_kcontrol_new snd_emu10k1_spdif_mask_control = 1070 { 1071 .access = SNDRV_CTL_ELEM_ACCESS_READ, 1072 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 1073 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK), 1074 .count = 3, 1075 .info = snd_emu10k1_spdif_info, 1076 .get = snd_emu10k1_spdif_get_mask 1077 }; 1078 1079 static const struct snd_kcontrol_new snd_emu10k1_spdif_control = 1080 { 1081 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 1082 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT), 1083 .count = 3, 1084 .info = snd_emu10k1_spdif_info, 1085 .get = snd_emu10k1_spdif_get, 1086 .put = snd_emu10k1_spdif_put 1087 }; 1088 1089 1090 static void update_emu10k1_fxrt(struct snd_emu10k1 *emu, int voice, unsigned char *route) 1091 { 1092 if (emu->audigy) { 1093 snd_emu10k1_ptr_write(emu, A_FXRT1, voice, 1094 snd_emu10k1_compose_audigy_fxrt1(route)); 1095 snd_emu10k1_ptr_write(emu, A_FXRT2, voice, 1096 snd_emu10k1_compose_audigy_fxrt2(route)); 1097 } else { 1098 snd_emu10k1_ptr_write(emu, FXRT, voice, 1099 snd_emu10k1_compose_send_routing(route)); 1100 } 1101 } 1102 1103 static void update_emu10k1_send_volume(struct snd_emu10k1 *emu, int voice, unsigned char *volume) 1104 { 1105 snd_emu10k1_ptr_write(emu, PTRX_FXSENDAMOUNT_A, voice, volume[0]); 1106 snd_emu10k1_ptr_write(emu, PTRX_FXSENDAMOUNT_B, voice, volume[1]); 1107 snd_emu10k1_ptr_write(emu, PSST_FXSENDAMOUNT_C, voice, volume[2]); 1108 snd_emu10k1_ptr_write(emu, DSL_FXSENDAMOUNT_D, voice, volume[3]); 1109 if (emu->audigy) { 1110 snd_emu10k1_ptr_write(emu, A_SENDAMOUNTS, voice, 1111 snd_emu10k1_compose_audigy_sendamounts(volume)); 1112 } 1113 } 1114 1115 /* PCM stream controls */ 1116 1117 static int snd_emu10k1_send_routing_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1118 { 1119 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 1120 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 1121 uinfo->count = emu->audigy ? 3*8 : 3*4; 1122 uinfo->value.integer.min = 0; 1123 uinfo->value.integer.max = emu->audigy ? 0x3f : 0x0f; 1124 return 0; 1125 } 1126 1127 static int snd_emu10k1_send_routing_get(struct snd_kcontrol *kcontrol, 1128 struct snd_ctl_elem_value *ucontrol) 1129 { 1130 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 1131 struct snd_emu10k1_pcm_mixer *mix = 1132 &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)]; 1133 int voice, idx; 1134 int num_efx = emu->audigy ? 8 : 4; 1135 int mask = emu->audigy ? 0x3f : 0x0f; 1136 1137 for (voice = 0; voice < 3; voice++) 1138 for (idx = 0; idx < num_efx; idx++) 1139 ucontrol->value.integer.value[(voice * num_efx) + idx] = 1140 mix->send_routing[voice][idx] & mask; 1141 return 0; 1142 } 1143 1144 static int snd_emu10k1_send_routing_put(struct snd_kcontrol *kcontrol, 1145 struct snd_ctl_elem_value *ucontrol) 1146 { 1147 unsigned long flags; 1148 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 1149 struct snd_emu10k1_pcm_mixer *mix = 1150 &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)]; 1151 int change = 0, voice, idx, val; 1152 int num_efx = emu->audigy ? 8 : 4; 1153 int mask = emu->audigy ? 0x3f : 0x0f; 1154 1155 spin_lock_irqsave(&emu->reg_lock, flags); 1156 for (voice = 0; voice < 3; voice++) 1157 for (idx = 0; idx < num_efx; idx++) { 1158 val = ucontrol->value.integer.value[(voice * num_efx) + idx] & mask; 1159 if (mix->send_routing[voice][idx] != val) { 1160 mix->send_routing[voice][idx] = val; 1161 change = 1; 1162 } 1163 } 1164 if (change && mix->epcm) { 1165 if (mix->epcm->voices[0] && mix->epcm->voices[1]) { 1166 update_emu10k1_fxrt(emu, mix->epcm->voices[0]->number, 1167 &mix->send_routing[1][0]); 1168 update_emu10k1_fxrt(emu, mix->epcm->voices[1]->number, 1169 &mix->send_routing[2][0]); 1170 } else if (mix->epcm->voices[0]) { 1171 update_emu10k1_fxrt(emu, mix->epcm->voices[0]->number, 1172 &mix->send_routing[0][0]); 1173 } 1174 } 1175 spin_unlock_irqrestore(&emu->reg_lock, flags); 1176 return change; 1177 } 1178 1179 static const struct snd_kcontrol_new snd_emu10k1_send_routing_control = 1180 { 1181 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE, 1182 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 1183 .name = "EMU10K1 PCM Send Routing", 1184 .count = 32, 1185 .info = snd_emu10k1_send_routing_info, 1186 .get = snd_emu10k1_send_routing_get, 1187 .put = snd_emu10k1_send_routing_put 1188 }; 1189 1190 static int snd_emu10k1_send_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1191 { 1192 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 1193 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 1194 uinfo->count = emu->audigy ? 3*8 : 3*4; 1195 uinfo->value.integer.min = 0; 1196 uinfo->value.integer.max = 255; 1197 return 0; 1198 } 1199 1200 static int snd_emu10k1_send_volume_get(struct snd_kcontrol *kcontrol, 1201 struct snd_ctl_elem_value *ucontrol) 1202 { 1203 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 1204 struct snd_emu10k1_pcm_mixer *mix = 1205 &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)]; 1206 int idx; 1207 int num_efx = emu->audigy ? 8 : 4; 1208 1209 for (idx = 0; idx < 3*num_efx; idx++) 1210 ucontrol->value.integer.value[idx] = mix->send_volume[idx/num_efx][idx%num_efx]; 1211 return 0; 1212 } 1213 1214 static int snd_emu10k1_send_volume_put(struct snd_kcontrol *kcontrol, 1215 struct snd_ctl_elem_value *ucontrol) 1216 { 1217 unsigned long flags; 1218 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 1219 struct snd_emu10k1_pcm_mixer *mix = 1220 &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)]; 1221 int change = 0, idx, val; 1222 int num_efx = emu->audigy ? 8 : 4; 1223 1224 spin_lock_irqsave(&emu->reg_lock, flags); 1225 for (idx = 0; idx < 3*num_efx; idx++) { 1226 val = ucontrol->value.integer.value[idx] & 255; 1227 if (mix->send_volume[idx/num_efx][idx%num_efx] != val) { 1228 mix->send_volume[idx/num_efx][idx%num_efx] = val; 1229 change = 1; 1230 } 1231 } 1232 if (change && mix->epcm) { 1233 if (mix->epcm->voices[0] && mix->epcm->voices[1]) { 1234 update_emu10k1_send_volume(emu, mix->epcm->voices[0]->number, 1235 &mix->send_volume[1][0]); 1236 update_emu10k1_send_volume(emu, mix->epcm->voices[1]->number, 1237 &mix->send_volume[2][0]); 1238 } else if (mix->epcm->voices[0]) { 1239 update_emu10k1_send_volume(emu, mix->epcm->voices[0]->number, 1240 &mix->send_volume[0][0]); 1241 } 1242 } 1243 spin_unlock_irqrestore(&emu->reg_lock, flags); 1244 return change; 1245 } 1246 1247 static const struct snd_kcontrol_new snd_emu10k1_send_volume_control = 1248 { 1249 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE, 1250 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 1251 .name = "EMU10K1 PCM Send Volume", 1252 .count = 32, 1253 .info = snd_emu10k1_send_volume_info, 1254 .get = snd_emu10k1_send_volume_get, 1255 .put = snd_emu10k1_send_volume_put 1256 }; 1257 1258 static int snd_emu10k1_attn_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1259 { 1260 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 1261 uinfo->count = 3; 1262 uinfo->value.integer.min = 0; 1263 uinfo->value.integer.max = 0x1fffd; 1264 return 0; 1265 } 1266 1267 static int snd_emu10k1_attn_get(struct snd_kcontrol *kcontrol, 1268 struct snd_ctl_elem_value *ucontrol) 1269 { 1270 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 1271 struct snd_emu10k1_pcm_mixer *mix = 1272 &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)]; 1273 int idx; 1274 1275 for (idx = 0; idx < 3; idx++) 1276 ucontrol->value.integer.value[idx] = mix->attn[idx] * 0xffffU / 0x8000U; 1277 return 0; 1278 } 1279 1280 static int snd_emu10k1_attn_put(struct snd_kcontrol *kcontrol, 1281 struct snd_ctl_elem_value *ucontrol) 1282 { 1283 unsigned long flags; 1284 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 1285 struct snd_emu10k1_pcm_mixer *mix = 1286 &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)]; 1287 int change = 0, idx, val; 1288 1289 spin_lock_irqsave(&emu->reg_lock, flags); 1290 for (idx = 0; idx < 3; idx++) { 1291 unsigned uval = ucontrol->value.integer.value[idx] & 0x1ffff; 1292 val = uval * 0x8000U / 0xffffU; 1293 if (mix->attn[idx] != val) { 1294 mix->attn[idx] = val; 1295 change = 1; 1296 } 1297 } 1298 if (change && mix->epcm) { 1299 if (mix->epcm->voices[0] && mix->epcm->voices[1]) { 1300 snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[0]->number, mix->attn[1]); 1301 snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[1]->number, mix->attn[2]); 1302 } else if (mix->epcm->voices[0]) { 1303 snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[0]->number, mix->attn[0]); 1304 } 1305 } 1306 spin_unlock_irqrestore(&emu->reg_lock, flags); 1307 return change; 1308 } 1309 1310 static const struct snd_kcontrol_new snd_emu10k1_attn_control = 1311 { 1312 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE, 1313 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 1314 .name = "EMU10K1 PCM Volume", 1315 .count = 32, 1316 .info = snd_emu10k1_attn_info, 1317 .get = snd_emu10k1_attn_get, 1318 .put = snd_emu10k1_attn_put 1319 }; 1320 1321 /* Mutichannel PCM stream controls */ 1322 1323 static int snd_emu10k1_efx_send_routing_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1324 { 1325 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 1326 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 1327 uinfo->count = emu->audigy ? 8 : 4; 1328 uinfo->value.integer.min = 0; 1329 uinfo->value.integer.max = emu->audigy ? 0x3f : 0x0f; 1330 return 0; 1331 } 1332 1333 static int snd_emu10k1_efx_send_routing_get(struct snd_kcontrol *kcontrol, 1334 struct snd_ctl_elem_value *ucontrol) 1335 { 1336 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 1337 struct snd_emu10k1_pcm_mixer *mix = 1338 &emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)]; 1339 int idx; 1340 int num_efx = emu->audigy ? 8 : 4; 1341 int mask = emu->audigy ? 0x3f : 0x0f; 1342 1343 for (idx = 0; idx < num_efx; idx++) 1344 ucontrol->value.integer.value[idx] = 1345 mix->send_routing[0][idx] & mask; 1346 return 0; 1347 } 1348 1349 static int snd_emu10k1_efx_send_routing_put(struct snd_kcontrol *kcontrol, 1350 struct snd_ctl_elem_value *ucontrol) 1351 { 1352 unsigned long flags; 1353 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 1354 int ch = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 1355 struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[ch]; 1356 int change = 0, idx, val; 1357 int num_efx = emu->audigy ? 8 : 4; 1358 int mask = emu->audigy ? 0x3f : 0x0f; 1359 1360 spin_lock_irqsave(&emu->reg_lock, flags); 1361 for (idx = 0; idx < num_efx; idx++) { 1362 val = ucontrol->value.integer.value[idx] & mask; 1363 if (mix->send_routing[0][idx] != val) { 1364 mix->send_routing[0][idx] = val; 1365 change = 1; 1366 } 1367 } 1368 1369 if (change && mix->epcm) { 1370 if (mix->epcm->voices[ch]) { 1371 update_emu10k1_fxrt(emu, mix->epcm->voices[ch]->number, 1372 &mix->send_routing[0][0]); 1373 } 1374 } 1375 spin_unlock_irqrestore(&emu->reg_lock, flags); 1376 return change; 1377 } 1378 1379 static const struct snd_kcontrol_new snd_emu10k1_efx_send_routing_control = 1380 { 1381 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE, 1382 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 1383 .name = "Multichannel PCM Send Routing", 1384 .count = 16, 1385 .info = snd_emu10k1_efx_send_routing_info, 1386 .get = snd_emu10k1_efx_send_routing_get, 1387 .put = snd_emu10k1_efx_send_routing_put 1388 }; 1389 1390 static int snd_emu10k1_efx_send_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1391 { 1392 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 1393 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 1394 uinfo->count = emu->audigy ? 8 : 4; 1395 uinfo->value.integer.min = 0; 1396 uinfo->value.integer.max = 255; 1397 return 0; 1398 } 1399 1400 static int snd_emu10k1_efx_send_volume_get(struct snd_kcontrol *kcontrol, 1401 struct snd_ctl_elem_value *ucontrol) 1402 { 1403 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 1404 struct snd_emu10k1_pcm_mixer *mix = 1405 &emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)]; 1406 int idx; 1407 int num_efx = emu->audigy ? 8 : 4; 1408 1409 for (idx = 0; idx < num_efx; idx++) 1410 ucontrol->value.integer.value[idx] = mix->send_volume[0][idx]; 1411 return 0; 1412 } 1413 1414 static int snd_emu10k1_efx_send_volume_put(struct snd_kcontrol *kcontrol, 1415 struct snd_ctl_elem_value *ucontrol) 1416 { 1417 unsigned long flags; 1418 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 1419 int ch = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 1420 struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[ch]; 1421 int change = 0, idx, val; 1422 int num_efx = emu->audigy ? 8 : 4; 1423 1424 spin_lock_irqsave(&emu->reg_lock, flags); 1425 for (idx = 0; idx < num_efx; idx++) { 1426 val = ucontrol->value.integer.value[idx] & 255; 1427 if (mix->send_volume[0][idx] != val) { 1428 mix->send_volume[0][idx] = val; 1429 change = 1; 1430 } 1431 } 1432 if (change && mix->epcm) { 1433 if (mix->epcm->voices[ch]) { 1434 update_emu10k1_send_volume(emu, mix->epcm->voices[ch]->number, 1435 &mix->send_volume[0][0]); 1436 } 1437 } 1438 spin_unlock_irqrestore(&emu->reg_lock, flags); 1439 return change; 1440 } 1441 1442 1443 static const struct snd_kcontrol_new snd_emu10k1_efx_send_volume_control = 1444 { 1445 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE, 1446 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 1447 .name = "Multichannel PCM Send Volume", 1448 .count = 16, 1449 .info = snd_emu10k1_efx_send_volume_info, 1450 .get = snd_emu10k1_efx_send_volume_get, 1451 .put = snd_emu10k1_efx_send_volume_put 1452 }; 1453 1454 static int snd_emu10k1_efx_attn_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1455 { 1456 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 1457 uinfo->count = 1; 1458 uinfo->value.integer.min = 0; 1459 uinfo->value.integer.max = 0x1fffd; 1460 return 0; 1461 } 1462 1463 static int snd_emu10k1_efx_attn_get(struct snd_kcontrol *kcontrol, 1464 struct snd_ctl_elem_value *ucontrol) 1465 { 1466 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 1467 struct snd_emu10k1_pcm_mixer *mix = 1468 &emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)]; 1469 1470 ucontrol->value.integer.value[0] = mix->attn[0] * 0xffffU / 0x8000U; 1471 return 0; 1472 } 1473 1474 static int snd_emu10k1_efx_attn_put(struct snd_kcontrol *kcontrol, 1475 struct snd_ctl_elem_value *ucontrol) 1476 { 1477 unsigned long flags; 1478 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 1479 int ch = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 1480 struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[ch]; 1481 int change = 0, val; 1482 unsigned uval; 1483 1484 spin_lock_irqsave(&emu->reg_lock, flags); 1485 uval = ucontrol->value.integer.value[0] & 0x1ffff; 1486 val = uval * 0x8000U / 0xffffU; 1487 if (mix->attn[0] != val) { 1488 mix->attn[0] = val; 1489 change = 1; 1490 } 1491 if (change && mix->epcm) { 1492 if (mix->epcm->voices[ch]) { 1493 snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[ch]->number, mix->attn[0]); 1494 } 1495 } 1496 spin_unlock_irqrestore(&emu->reg_lock, flags); 1497 return change; 1498 } 1499 1500 static const struct snd_kcontrol_new snd_emu10k1_efx_attn_control = 1501 { 1502 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE, 1503 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 1504 .name = "Multichannel PCM Volume", 1505 .count = 16, 1506 .info = snd_emu10k1_efx_attn_info, 1507 .get = snd_emu10k1_efx_attn_get, 1508 .put = snd_emu10k1_efx_attn_put 1509 }; 1510 1511 #define snd_emu10k1_shared_spdif_info snd_ctl_boolean_mono_info 1512 1513 static int snd_emu10k1_shared_spdif_get(struct snd_kcontrol *kcontrol, 1514 struct snd_ctl_elem_value *ucontrol) 1515 { 1516 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 1517 1518 if (emu->audigy) 1519 ucontrol->value.integer.value[0] = inw(emu->port + A_IOCFG) & A_IOCFG_GPOUT0 ? 1 : 0; 1520 else 1521 ucontrol->value.integer.value[0] = inl(emu->port + HCFG) & HCFG_GPOUT0 ? 1 : 0; 1522 if (emu->card_capabilities->invert_shared_spdif) 1523 ucontrol->value.integer.value[0] = 1524 !ucontrol->value.integer.value[0]; 1525 1526 return 0; 1527 } 1528 1529 static int snd_emu10k1_shared_spdif_put(struct snd_kcontrol *kcontrol, 1530 struct snd_ctl_elem_value *ucontrol) 1531 { 1532 unsigned long flags; 1533 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 1534 unsigned int reg, val, sw; 1535 int change = 0; 1536 1537 sw = ucontrol->value.integer.value[0]; 1538 if (emu->card_capabilities->invert_shared_spdif) 1539 sw = !sw; 1540 spin_lock_irqsave(&emu->emu_lock, flags); 1541 if ( emu->card_capabilities->i2c_adc) { 1542 /* Do nothing for Audigy 2 ZS Notebook */ 1543 } else if (emu->audigy) { 1544 reg = inw(emu->port + A_IOCFG); 1545 val = sw ? A_IOCFG_GPOUT0 : 0; 1546 change = (reg & A_IOCFG_GPOUT0) != val; 1547 if (change) { 1548 reg &= ~A_IOCFG_GPOUT0; 1549 reg |= val; 1550 outw(reg | val, emu->port + A_IOCFG); 1551 } 1552 } 1553 reg = inl(emu->port + HCFG); 1554 val = sw ? HCFG_GPOUT0 : 0; 1555 change |= (reg & HCFG_GPOUT0) != val; 1556 if (change) { 1557 reg &= ~HCFG_GPOUT0; 1558 reg |= val; 1559 outl(reg | val, emu->port + HCFG); 1560 } 1561 spin_unlock_irqrestore(&emu->emu_lock, flags); 1562 return change; 1563 } 1564 1565 static const struct snd_kcontrol_new snd_emu10k1_shared_spdif = 1566 { 1567 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1568 .name = "SB Live Analog/Digital Output Jack", 1569 .info = snd_emu10k1_shared_spdif_info, 1570 .get = snd_emu10k1_shared_spdif_get, 1571 .put = snd_emu10k1_shared_spdif_put 1572 }; 1573 1574 static const struct snd_kcontrol_new snd_audigy_shared_spdif = 1575 { 1576 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1577 .name = "Audigy Analog/Digital Output Jack", 1578 .info = snd_emu10k1_shared_spdif_info, 1579 .get = snd_emu10k1_shared_spdif_get, 1580 .put = snd_emu10k1_shared_spdif_put 1581 }; 1582 1583 /* workaround for too low volume on Audigy due to 16bit/24bit conversion */ 1584 1585 #define snd_audigy_capture_boost_info snd_ctl_boolean_mono_info 1586 1587 static int snd_audigy_capture_boost_get(struct snd_kcontrol *kcontrol, 1588 struct snd_ctl_elem_value *ucontrol) 1589 { 1590 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 1591 unsigned int val; 1592 1593 /* FIXME: better to use a cached version */ 1594 val = snd_ac97_read(emu->ac97, AC97_REC_GAIN); 1595 ucontrol->value.integer.value[0] = !!val; 1596 return 0; 1597 } 1598 1599 static int snd_audigy_capture_boost_put(struct snd_kcontrol *kcontrol, 1600 struct snd_ctl_elem_value *ucontrol) 1601 { 1602 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 1603 unsigned int val; 1604 1605 if (ucontrol->value.integer.value[0]) 1606 val = 0x0f0f; 1607 else 1608 val = 0; 1609 return snd_ac97_update(emu->ac97, AC97_REC_GAIN, val); 1610 } 1611 1612 static const struct snd_kcontrol_new snd_audigy_capture_boost = 1613 { 1614 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1615 .name = "Mic Extra Boost", 1616 .info = snd_audigy_capture_boost_info, 1617 .get = snd_audigy_capture_boost_get, 1618 .put = snd_audigy_capture_boost_put 1619 }; 1620 1621 1622 /* 1623 */ 1624 static void snd_emu10k1_mixer_free_ac97(struct snd_ac97 *ac97) 1625 { 1626 struct snd_emu10k1 *emu = ac97->private_data; 1627 emu->ac97 = NULL; 1628 } 1629 1630 /* 1631 */ 1632 static int remove_ctl(struct snd_card *card, const char *name) 1633 { 1634 struct snd_ctl_elem_id id; 1635 memset(&id, 0, sizeof(id)); 1636 strcpy(id.name, name); 1637 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 1638 return snd_ctl_remove_id(card, &id); 1639 } 1640 1641 static struct snd_kcontrol *ctl_find(struct snd_card *card, const char *name) 1642 { 1643 struct snd_ctl_elem_id sid; 1644 memset(&sid, 0, sizeof(sid)); 1645 strcpy(sid.name, name); 1646 sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 1647 return snd_ctl_find_id(card, &sid); 1648 } 1649 1650 static int rename_ctl(struct snd_card *card, const char *src, const char *dst) 1651 { 1652 struct snd_kcontrol *kctl = ctl_find(card, src); 1653 if (kctl) { 1654 snd_ctl_rename(card, kctl, dst); 1655 return 0; 1656 } 1657 return -ENOENT; 1658 } 1659 1660 int snd_emu10k1_mixer(struct snd_emu10k1 *emu, 1661 int pcm_device, int multi_device) 1662 { 1663 int err; 1664 struct snd_kcontrol *kctl; 1665 struct snd_card *card = emu->card; 1666 const char * const *c; 1667 static const char * const emu10k1_remove_ctls[] = { 1668 /* no AC97 mono, surround, center/lfe */ 1669 "Master Mono Playback Switch", 1670 "Master Mono Playback Volume", 1671 "PCM Out Path & Mute", 1672 "Mono Output Select", 1673 "Surround Playback Switch", 1674 "Surround Playback Volume", 1675 "Center Playback Switch", 1676 "Center Playback Volume", 1677 "LFE Playback Switch", 1678 "LFE Playback Volume", 1679 NULL 1680 }; 1681 static const char * const emu10k1_rename_ctls[] = { 1682 "Surround Digital Playback Volume", "Surround Playback Volume", 1683 "Center Digital Playback Volume", "Center Playback Volume", 1684 "LFE Digital Playback Volume", "LFE Playback Volume", 1685 NULL 1686 }; 1687 static const char * const audigy_remove_ctls[] = { 1688 /* Master/PCM controls on ac97 of Audigy has no effect */ 1689 /* On the Audigy2 the AC97 playback is piped into 1690 * the Philips ADC for 24bit capture */ 1691 "PCM Playback Switch", 1692 "PCM Playback Volume", 1693 "Master Playback Switch", 1694 "Master Playback Volume", 1695 "PCM Out Path & Mute", 1696 "Mono Output Select", 1697 /* remove unused AC97 capture controls */ 1698 "Capture Source", 1699 "Capture Switch", 1700 "Capture Volume", 1701 "Mic Select", 1702 "Headphone Playback Switch", 1703 "Headphone Playback Volume", 1704 "3D Control - Center", 1705 "3D Control - Depth", 1706 "3D Control - Switch", 1707 "Video Playback Switch", 1708 "Video Playback Volume", 1709 "Mic Playback Switch", 1710 "Mic Playback Volume", 1711 "External Amplifier", 1712 NULL 1713 }; 1714 static const char * const audigy_rename_ctls[] = { 1715 /* use conventional names */ 1716 "Wave Playback Volume", "PCM Playback Volume", 1717 /* "Wave Capture Volume", "PCM Capture Volume", */ 1718 "Wave Master Playback Volume", "Master Playback Volume", 1719 "AMic Playback Volume", "Mic Playback Volume", 1720 "Master Mono Playback Switch", "Phone Output Playback Switch", 1721 "Master Mono Playback Volume", "Phone Output Playback Volume", 1722 NULL 1723 }; 1724 static const char * const audigy_rename_ctls_i2c_adc[] = { 1725 //"Analog Mix Capture Volume","OLD Analog Mix Capture Volume", 1726 "Line Capture Volume", "Analog Mix Capture Volume", 1727 "Wave Playback Volume", "OLD PCM Playback Volume", 1728 "Wave Master Playback Volume", "Master Playback Volume", 1729 "AMic Playback Volume", "Old Mic Playback Volume", 1730 "CD Capture Volume", "IEC958 Optical Capture Volume", 1731 NULL 1732 }; 1733 static const char * const audigy_remove_ctls_i2c_adc[] = { 1734 /* On the Audigy2 ZS Notebook 1735 * Capture via WM8775 */ 1736 "Mic Capture Volume", 1737 "Analog Mix Capture Volume", 1738 "Aux Capture Volume", 1739 "IEC958 Optical Capture Volume", 1740 NULL 1741 }; 1742 static const char * const audigy_remove_ctls_1361t_adc[] = { 1743 /* On the Audigy2 the AC97 playback is piped into 1744 * the Philips ADC for 24bit capture */ 1745 "PCM Playback Switch", 1746 "PCM Playback Volume", 1747 "Capture Source", 1748 "Capture Switch", 1749 "Capture Volume", 1750 "Mic Capture Volume", 1751 "Headphone Playback Switch", 1752 "Headphone Playback Volume", 1753 "3D Control - Center", 1754 "3D Control - Depth", 1755 "3D Control - Switch", 1756 "Line2 Playback Volume", 1757 "Line2 Capture Volume", 1758 NULL 1759 }; 1760 static const char * const audigy_rename_ctls_1361t_adc[] = { 1761 "Master Playback Switch", "Master Capture Switch", 1762 "Master Playback Volume", "Master Capture Volume", 1763 "Wave Master Playback Volume", "Master Playback Volume", 1764 "Beep Playback Switch", "Beep Capture Switch", 1765 "Beep Playback Volume", "Beep Capture Volume", 1766 "Phone Playback Switch", "Phone Capture Switch", 1767 "Phone Playback Volume", "Phone Capture Volume", 1768 "Mic Playback Switch", "Mic Capture Switch", 1769 "Mic Playback Volume", "Mic Capture Volume", 1770 "Line Playback Switch", "Line Capture Switch", 1771 "Line Playback Volume", "Line Capture Volume", 1772 "CD Playback Switch", "CD Capture Switch", 1773 "CD Playback Volume", "CD Capture Volume", 1774 "Aux Playback Switch", "Aux Capture Switch", 1775 "Aux Playback Volume", "Aux Capture Volume", 1776 "Video Playback Switch", "Video Capture Switch", 1777 "Video Playback Volume", "Video Capture Volume", 1778 "Master Mono Playback Switch", "Phone Output Playback Switch", 1779 "Master Mono Playback Volume", "Phone Output Playback Volume", 1780 NULL 1781 }; 1782 1783 if (emu->card_capabilities->ac97_chip) { 1784 struct snd_ac97_bus *pbus; 1785 struct snd_ac97_template ac97; 1786 static const struct snd_ac97_bus_ops ops = { 1787 .write = snd_emu10k1_ac97_write, 1788 .read = snd_emu10k1_ac97_read, 1789 }; 1790 1791 err = snd_ac97_bus(emu->card, 0, &ops, NULL, &pbus); 1792 if (err < 0) 1793 return err; 1794 pbus->no_vra = 1; /* we don't need VRA */ 1795 1796 memset(&ac97, 0, sizeof(ac97)); 1797 ac97.private_data = emu; 1798 ac97.private_free = snd_emu10k1_mixer_free_ac97; 1799 ac97.scaps = AC97_SCAP_NO_SPDIF; 1800 err = snd_ac97_mixer(pbus, &ac97, &emu->ac97); 1801 if (err < 0) { 1802 if (emu->card_capabilities->ac97_chip == 1) 1803 return err; 1804 dev_info(emu->card->dev, 1805 "AC97 is optional on this board\n"); 1806 dev_info(emu->card->dev, 1807 "Proceeding without ac97 mixers...\n"); 1808 snd_device_free(emu->card, pbus); 1809 goto no_ac97; /* FIXME: get rid of ugly gotos.. */ 1810 } 1811 if (emu->audigy) { 1812 /* set master volume to 0 dB */ 1813 snd_ac97_write_cache(emu->ac97, AC97_MASTER, 0x0000); 1814 /* set capture source to mic */ 1815 snd_ac97_write_cache(emu->ac97, AC97_REC_SEL, 0x0000); 1816 /* set mono output (TAD) to mic */ 1817 snd_ac97_update_bits(emu->ac97, AC97_GENERAL_PURPOSE, 1818 0x0200, 0x0200); 1819 if (emu->card_capabilities->adc_1361t) 1820 c = audigy_remove_ctls_1361t_adc; 1821 else 1822 c = audigy_remove_ctls; 1823 } else { 1824 /* 1825 * Credits for cards based on STAC9758: 1826 * James Courtier-Dutton <James@superbug.demon.co.uk> 1827 * Voluspa <voluspa@comhem.se> 1828 */ 1829 if (emu->ac97->id == AC97_ID_STAC9758) { 1830 emu->rear_ac97 = 1; 1831 snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE|AC97SLOT_REAR_LEFT|AC97SLOT_REAR_RIGHT); 1832 snd_ac97_write_cache(emu->ac97, AC97_HEADPHONE, 0x0202); 1833 remove_ctl(card,"Front Playback Volume"); 1834 remove_ctl(card,"Front Playback Switch"); 1835 } 1836 /* remove unused AC97 controls */ 1837 snd_ac97_write_cache(emu->ac97, AC97_SURROUND_MASTER, 0x0202); 1838 snd_ac97_write_cache(emu->ac97, AC97_CENTER_LFE_MASTER, 0x0202); 1839 c = emu10k1_remove_ctls; 1840 } 1841 for (; *c; c++) 1842 remove_ctl(card, *c); 1843 } else if (emu->card_capabilities->i2c_adc) { 1844 c = audigy_remove_ctls_i2c_adc; 1845 for (; *c; c++) 1846 remove_ctl(card, *c); 1847 } else { 1848 no_ac97: 1849 if (emu->card_capabilities->ecard) 1850 strcpy(emu->card->mixername, "EMU APS"); 1851 else if (emu->audigy) 1852 strcpy(emu->card->mixername, "SB Audigy"); 1853 else 1854 strcpy(emu->card->mixername, "Emu10k1"); 1855 } 1856 1857 if (emu->audigy) 1858 if (emu->card_capabilities->adc_1361t) 1859 c = audigy_rename_ctls_1361t_adc; 1860 else if (emu->card_capabilities->i2c_adc) 1861 c = audigy_rename_ctls_i2c_adc; 1862 else 1863 c = audigy_rename_ctls; 1864 else 1865 c = emu10k1_rename_ctls; 1866 for (; *c; c += 2) 1867 rename_ctl(card, c[0], c[1]); 1868 1869 if (emu->card_capabilities->subsystem == 0x80401102) { /* SB Live! Platinum CT4760P */ 1870 remove_ctl(card, "Center Playback Volume"); 1871 remove_ctl(card, "LFE Playback Volume"); 1872 remove_ctl(card, "Wave Center Playback Volume"); 1873 remove_ctl(card, "Wave LFE Playback Volume"); 1874 } 1875 if (emu->card_capabilities->subsystem == 0x20071102) { /* Audigy 4 Pro */ 1876 rename_ctl(card, "Line2 Capture Volume", "Line1/Mic Capture Volume"); 1877 rename_ctl(card, "Analog Mix Capture Volume", "Line2 Capture Volume"); 1878 rename_ctl(card, "Aux2 Capture Volume", "Line3 Capture Volume"); 1879 rename_ctl(card, "Mic Capture Volume", "Unknown1 Capture Volume"); 1880 } 1881 kctl = emu->ctl_send_routing = snd_ctl_new1(&snd_emu10k1_send_routing_control, emu); 1882 if (!kctl) 1883 return -ENOMEM; 1884 kctl->id.device = pcm_device; 1885 err = snd_ctl_add(card, kctl); 1886 if (err) 1887 return err; 1888 kctl = emu->ctl_send_volume = snd_ctl_new1(&snd_emu10k1_send_volume_control, emu); 1889 if (!kctl) 1890 return -ENOMEM; 1891 kctl->id.device = pcm_device; 1892 err = snd_ctl_add(card, kctl); 1893 if (err) 1894 return err; 1895 kctl = emu->ctl_attn = snd_ctl_new1(&snd_emu10k1_attn_control, emu); 1896 if (!kctl) 1897 return -ENOMEM; 1898 kctl->id.device = pcm_device; 1899 err = snd_ctl_add(card, kctl); 1900 if (err) 1901 return err; 1902 1903 kctl = emu->ctl_efx_send_routing = snd_ctl_new1(&snd_emu10k1_efx_send_routing_control, emu); 1904 if (!kctl) 1905 return -ENOMEM; 1906 kctl->id.device = multi_device; 1907 err = snd_ctl_add(card, kctl); 1908 if (err) 1909 return err; 1910 1911 kctl = emu->ctl_efx_send_volume = snd_ctl_new1(&snd_emu10k1_efx_send_volume_control, emu); 1912 if (!kctl) 1913 return -ENOMEM; 1914 kctl->id.device = multi_device; 1915 err = snd_ctl_add(card, kctl); 1916 if (err) 1917 return err; 1918 1919 kctl = emu->ctl_efx_attn = snd_ctl_new1(&snd_emu10k1_efx_attn_control, emu); 1920 if (!kctl) 1921 return -ENOMEM; 1922 kctl->id.device = multi_device; 1923 err = snd_ctl_add(card, kctl); 1924 if (err) 1925 return err; 1926 1927 if (!emu->card_capabilities->ecard && !emu->card_capabilities->emu_model) { 1928 /* sb live! and audigy */ 1929 kctl = snd_ctl_new1(&snd_emu10k1_spdif_mask_control, emu); 1930 if (!kctl) 1931 return -ENOMEM; 1932 if (!emu->audigy) 1933 kctl->id.device = emu->pcm_efx->device; 1934 err = snd_ctl_add(card, kctl); 1935 if (err) 1936 return err; 1937 kctl = snd_ctl_new1(&snd_emu10k1_spdif_control, emu); 1938 if (!kctl) 1939 return -ENOMEM; 1940 if (!emu->audigy) 1941 kctl->id.device = emu->pcm_efx->device; 1942 err = snd_ctl_add(card, kctl); 1943 if (err) 1944 return err; 1945 } 1946 1947 if (emu->card_capabilities->emu_model) { 1948 ; /* Disable the snd_audigy_spdif_shared_spdif */ 1949 } else if (emu->audigy) { 1950 kctl = snd_ctl_new1(&snd_audigy_shared_spdif, emu); 1951 if (!kctl) 1952 return -ENOMEM; 1953 err = snd_ctl_add(card, kctl); 1954 if (err) 1955 return err; 1956 #if 0 1957 kctl = snd_ctl_new1(&snd_audigy_spdif_output_rate, emu); 1958 if (!kctl) 1959 return -ENOMEM; 1960 err = snd_ctl_add(card, kctl); 1961 if (err) 1962 return err; 1963 #endif 1964 } else if (! emu->card_capabilities->ecard) { 1965 /* sb live! */ 1966 kctl = snd_ctl_new1(&snd_emu10k1_shared_spdif, emu); 1967 if (!kctl) 1968 return -ENOMEM; 1969 err = snd_ctl_add(card, kctl); 1970 if (err) 1971 return err; 1972 } 1973 if (emu->card_capabilities->ca0151_chip) { /* P16V */ 1974 err = snd_p16v_mixer(emu); 1975 if (err) 1976 return err; 1977 } 1978 1979 if (emu->card_capabilities->emu_model == EMU_MODEL_EMU1616) { 1980 /* 1616(m) cardbus */ 1981 err = add_ctls(emu, &emu1010_output_source_ctl, 1982 snd_emu1616_output_texts, 1983 ARRAY_SIZE(snd_emu1616_output_texts)); 1984 if (err < 0) 1985 return err; 1986 err = add_ctls(emu, &emu1010_input_source_ctl, 1987 emu1010_input_texts, 1988 ARRAY_SIZE(emu1010_input_texts)); 1989 if (err < 0) 1990 return err; 1991 err = add_ctls(emu, &emu1010_adc_pads_ctl, 1992 snd_emu1010_adc_pads, 1993 ARRAY_SIZE(snd_emu1010_adc_pads) - 2); 1994 if (err < 0) 1995 return err; 1996 err = add_ctls(emu, &emu1010_dac_pads_ctl, 1997 snd_emu1010_dac_pads, 1998 ARRAY_SIZE(snd_emu1010_dac_pads) - 2); 1999 if (err < 0) 2000 return err; 2001 err = snd_ctl_add(card, 2002 snd_ctl_new1(&snd_emu1010_internal_clock, emu)); 2003 if (err < 0) 2004 return err; 2005 err = snd_ctl_add(card, 2006 snd_ctl_new1(&snd_emu1010_optical_out, emu)); 2007 if (err < 0) 2008 return err; 2009 err = snd_ctl_add(card, 2010 snd_ctl_new1(&snd_emu1010_optical_in, emu)); 2011 if (err < 0) 2012 return err; 2013 2014 } else if (emu->card_capabilities->emu_model) { 2015 /* all other e-mu cards for now */ 2016 err = add_ctls(emu, &emu1010_output_source_ctl, 2017 emu1010_output_texts, 2018 ARRAY_SIZE(emu1010_output_texts)); 2019 if (err < 0) 2020 return err; 2021 err = add_ctls(emu, &emu1010_input_source_ctl, 2022 emu1010_input_texts, 2023 ARRAY_SIZE(emu1010_input_texts)); 2024 if (err < 0) 2025 return err; 2026 err = add_ctls(emu, &emu1010_adc_pads_ctl, 2027 snd_emu1010_adc_pads, 2028 ARRAY_SIZE(snd_emu1010_adc_pads)); 2029 if (err < 0) 2030 return err; 2031 err = add_ctls(emu, &emu1010_dac_pads_ctl, 2032 snd_emu1010_dac_pads, 2033 ARRAY_SIZE(snd_emu1010_dac_pads)); 2034 if (err < 0) 2035 return err; 2036 err = snd_ctl_add(card, 2037 snd_ctl_new1(&snd_emu1010_internal_clock, emu)); 2038 if (err < 0) 2039 return err; 2040 err = snd_ctl_add(card, 2041 snd_ctl_new1(&snd_emu1010_optical_out, emu)); 2042 if (err < 0) 2043 return err; 2044 err = snd_ctl_add(card, 2045 snd_ctl_new1(&snd_emu1010_optical_in, emu)); 2046 if (err < 0) 2047 return err; 2048 } 2049 2050 if ( emu->card_capabilities->i2c_adc) { 2051 err = snd_ctl_add(card, snd_ctl_new1(&snd_audigy_i2c_capture_source, emu)); 2052 if (err < 0) 2053 return err; 2054 2055 err = add_ctls(emu, &i2c_volume_ctl, 2056 snd_audigy_i2c_volume_ctls, 2057 ARRAY_SIZE(snd_audigy_i2c_volume_ctls)); 2058 if (err < 0) 2059 return err; 2060 } 2061 2062 if (emu->card_capabilities->ac97_chip && emu->audigy) { 2063 err = snd_ctl_add(card, snd_ctl_new1(&snd_audigy_capture_boost, 2064 emu)); 2065 if (err < 0) 2066 return err; 2067 } 2068 2069 return 0; 2070 } 2071