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