Changeset 84 for GPL/trunk/alsa-kernel/pci/emu10k1/emupcm.c
- Timestamp:
- Oct 23, 2006, 11:07:11 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GPL/trunk/alsa-kernel/pci/emu10k1/emupcm.c
r34 r84 3 3 * Creative Labs, Inc. 4 4 * Routines for control of EMU10K1 chips / PCM routines 5 * Multichannel PCM support Copyright (c) Lee Revell <rlrevell@joe-job.com> 5 6 * 6 7 * BUGS: … … 26 27 */ 27 28 28 #define __NO_VERSION__29 29 #include <sound/driver.h> 30 #include <linux/pci.h> 31 #include <linux/delay.h> 30 32 #include <linux/slab.h> 31 33 #include <linux/time.h> 34 #include <linux/init.h> 32 35 #include <sound/core.h> 33 36 #include <sound/emu10k1.h> 34 37 35 static inline snd_ctl_elem_id_t *snd_ctl_build_ioff(snd_ctl_elem_id_t *dst_id, 36 snd_kcontrol_t *src_kctl, 37 unsigned int offset) 38 { 39 *dst_id = src_kctl->id; 40 dst_id->index += offset; 41 dst_id->numid += offset; 42 return dst_id; 43 } 44 45 static void snd_emu10k1_pcm_interrupt(struct snd_emu10k1 *emu, struct snd_emu10k1_voice *voice) 46 { 47 struct snd_emu10k1_pcm *epcm; 48 49 if ((epcm = voice->epcm) == NULL) 50 return; 51 if (epcm->substream == NULL) 52 return; 38 static void snd_emu10k1_pcm_interrupt(struct snd_emu10k1 *emu, 39 struct snd_emu10k1_voice *voice) 40 { 41 struct snd_emu10k1_pcm *epcm; 42 43 if ((epcm = voice->epcm) == NULL) 44 return; 45 if (epcm->substream == NULL) 46 return; 53 47 #if 0 54 55 56 57 48 printk("IRQ: position = 0x%x, period = 0x%x, size = 0x%x\n", 49 epcm->substream->runtime->hw->pointer(emu, epcm->substream), 50 snd_pcm_lib_period_bytes(epcm->substream), 51 snd_pcm_lib_buffer_bytes(epcm->substream)); 58 52 #endif 59 snd_pcm_period_elapsed(epcm->substream); 60 } 61 62 static void snd_emu10k1_pcm_ac97adc_interrupt(struct snd_emu10k1 *emu, unsigned int status) 53 snd_pcm_period_elapsed(epcm->substream); 54 } 55 56 static void snd_emu10k1_pcm_ac97adc_interrupt(struct snd_emu10k1 *emu, 57 unsigned int status) 63 58 { 64 59 #if 0 65 66 67 68 60 if (status & IPR_ADCBUFHALFFULL) { 61 if (emu->pcm_capture_substream->runtime->mode == SNDRV_PCM_MODE_FRAME) 62 return; 63 } 69 64 #endif 70 snd_pcm_period_elapsed(emu->pcm_capture_substream); 71 } 72 73 static void snd_emu10k1_pcm_ac97mic_interrupt(struct snd_emu10k1 *emu, unsigned int status) 65 snd_pcm_period_elapsed(emu->pcm_capture_substream); 66 } 67 68 static void snd_emu10k1_pcm_ac97mic_interrupt(struct snd_emu10k1 *emu, 69 unsigned int status) 74 70 { 75 71 #if 0 76 77 78 79 72 if (status & IPR_MICBUFHALFFULL) { 73 if (emu->pcm_capture_mic_substream->runtime->mode == SNDRV_PCM_MODE_FRAME) 74 return; 75 } 80 76 #endif 81 snd_pcm_period_elapsed(emu->pcm_capture_mic_substream); 82 } 83 84 static void snd_emu10k1_pcm_efx_interrupt(struct snd_emu10k1 *emu, unsigned int status) 77 snd_pcm_period_elapsed(emu->pcm_capture_mic_substream); 78 } 79 80 static void snd_emu10k1_pcm_efx_interrupt(struct snd_emu10k1 *emu, 81 unsigned int status) 85 82 { 86 83 #if 0 87 88 89 90 84 if (status & IPR_EFXBUFHALFFULL) { 85 if (emu->pcm_capture_efx_substream->runtime->mode == SNDRV_PCM_MODE_FRAME) 86 return; 87 } 91 88 #endif 92 93 } 94 95 static snd_pcm_uframes_t snd_emu10k1_efx_playback_pointer(s nd_pcm_substream_t *substream)96 { 97 98 snd_pcm_runtime_t*runtime = substream->runtime;99 100 101 102 103 104 105 106 107 108 109 89 snd_pcm_period_elapsed(emu->pcm_capture_efx_substream); 90 } 91 92 static snd_pcm_uframes_t snd_emu10k1_efx_playback_pointer(struct snd_pcm_substream *substream) 93 { 94 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 95 struct snd_pcm_runtime *runtime = substream->runtime; 96 struct snd_emu10k1_pcm *epcm = runtime->private_data; 97 unsigned int ptr; 98 99 if (!epcm->running) 100 return 0; 101 ptr = snd_emu10k1_ptr_read(emu, CCCA, epcm->voices[0]->number) & 0x00ffffff; 102 ptr += runtime->buffer_size; 103 ptr -= epcm->ccca_start_addr; 104 ptr %= runtime->buffer_size; 105 106 return ptr; 110 107 } 111 108 112 109 static int snd_emu10k1_pcm_channel_alloc(struct snd_emu10k1_pcm * epcm, int voices) 113 110 { 114 int err, i; 115 116 if (epcm->voices[1] != NULL && voices < 2) { 117 snd_emu10k1_voice_free(epcm->emu, epcm->voices[1]); 118 epcm->voices[1] = NULL; 119 } 120 for (i = 0; i < voices; i++) { 121 if (epcm->voices[i] == NULL) 122 break; 123 } 124 if (i == voices) 125 return 0; /* already allocated */ 126 for (i = 0; i < ARRAY_SIZE(epcm->voices); i++) { 127 if (epcm->voices[i]) { 128 snd_emu10k1_voice_free(epcm->emu, epcm->voices[i]); 129 epcm->voices[i] = NULL; 130 } 131 } 132 err = snd_emu10k1_voice_alloc(epcm->emu, 133 epcm->type == PLAYBACK_EMUVOICE ? EMU10K1_PCM : EMU10K1_EFX, 134 voices, 135 &epcm->voices[0]); 136 if (err < 0) 137 return err; 138 epcm->voices[0]->epcm = epcm; 139 if (voices > 1) { 140 for (i = 1; i < voices; i++) { 141 epcm->voices[i] = &epcm->emu->voices[epcm->voices[0]->number + i]; 142 epcm->voices[i]->epcm = epcm; 143 } 144 } 145 if (epcm->extra == NULL) { 146 err = snd_emu10k1_voice_alloc(epcm->emu, 147 epcm->type == PLAYBACK_EMUVOICE ? EMU10K1_PCM : EMU10K1_EFX, 148 1, 149 &epcm->extra); 150 if (err < 0) { 151 // printk("pcm_channel_alloc: failed extra: voices=%d, frame=%d\n", voices, frame); 152 for (i = 0; i < voices; i++) { 153 snd_emu10k1_voice_free(epcm->emu, epcm->voices[i]); 154 epcm->voices[i] = NULL; 155 } 156 return err; 157 } 158 epcm->extra->epcm = epcm; 159 epcm->extra->interrupt = snd_emu10k1_pcm_interrupt; 160 } 161 return 0; 111 int err, i; 112 113 if (epcm->voices[1] != NULL && voices < 2) { 114 snd_emu10k1_voice_free(epcm->emu, epcm->voices[1]); 115 epcm->voices[1] = NULL; 116 } 117 for (i = 0; i < voices; i++) { 118 if (epcm->voices[i] == NULL) 119 break; 120 } 121 if (i == voices) 122 return 0; /* already allocated */ 123 124 for (i = 0; i < ARRAY_SIZE(epcm->voices); i++) { 125 if (epcm->voices[i]) { 126 snd_emu10k1_voice_free(epcm->emu, epcm->voices[i]); 127 epcm->voices[i] = NULL; 128 } 129 } 130 err = snd_emu10k1_voice_alloc(epcm->emu, 131 epcm->type == PLAYBACK_EMUVOICE ? EMU10K1_PCM : EMU10K1_EFX, 132 voices, 133 &epcm->voices[0]); 134 135 if (err < 0) 136 return err; 137 epcm->voices[0]->epcm = epcm; 138 if (voices > 1) { 139 for (i = 1; i < voices; i++) { 140 epcm->voices[i] = &epcm->emu->voices[epcm->voices[0]->number + i]; 141 epcm->voices[i]->epcm = epcm; 142 } 143 } 144 if (epcm->extra == NULL) { 145 err = snd_emu10k1_voice_alloc(epcm->emu, 146 epcm->type == PLAYBACK_EMUVOICE ? EMU10K1_PCM : EMU10K1_EFX, 147 1, 148 &epcm->extra); 149 if (err < 0) { 150 /* printk("pcm_channel_alloc: failed extra: voices=%d, frame=%d\n", voices, frame); */ 151 for (i = 0; i < voices; i++) { 152 snd_emu10k1_voice_free(epcm->emu, epcm->voices[i]); 153 epcm->voices[i] = NULL; 154 } 155 return err; 156 } 157 epcm->extra->epcm = epcm; 158 epcm->extra->interrupt = snd_emu10k1_pcm_interrupt; 159 } 160 return 0; 162 161 } 163 162 164 163 static unsigned int capture_period_sizes[31] = { 165 166 167 168 169 170 171 172 164 384, 448, 512, 640, 165 384*2, 448*2, 512*2, 640*2, 166 384*4, 448*4, 512*4, 640*4, 167 384*8, 448*8, 512*8, 640*8, 168 384*16, 448*16, 512*16, 640*16, 169 384*32, 448*32, 512*32, 640*32, 170 384*64, 448*64, 512*64, 640*64, 171 384*128,448*128,512*128 173 172 }; 174 173 175 static s nd_pcm_hw_constraint_list_t hw_constraints_capture_period_sizes = {176 177 178 174 static struct snd_pcm_hw_constraint_list hw_constraints_capture_period_sizes = { 175 .count = 31, 176 .list = capture_period_sizes, 177 .mask = 0 179 178 }; 180 179 181 180 static unsigned int capture_rates[8] = { 182 181 8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000 183 182 }; 184 183 185 static s nd_pcm_hw_constraint_list_t hw_constraints_capture_rates = {186 187 188 184 static struct snd_pcm_hw_constraint_list hw_constraints_capture_rates = { 185 .count = 8, 186 .list = capture_rates, 187 .mask = 0 189 188 }; 190 189 191 190 static unsigned int snd_emu10k1_capture_rate_reg(unsigned int rate) 192 191 { 193 194 195 196 197 198 199 200 201 202 203 204 205 192 switch (rate) { 193 case 8000: return ADCCR_SAMPLERATE_8; 194 case 11025: return ADCCR_SAMPLERATE_11; 195 case 16000: return ADCCR_SAMPLERATE_16; 196 case 22050: return ADCCR_SAMPLERATE_22; 197 case 24000: return ADCCR_SAMPLERATE_24; 198 case 32000: return ADCCR_SAMPLERATE_32; 199 case 44100: return ADCCR_SAMPLERATE_44; 200 case 48000: return ADCCR_SAMPLERATE_48; 201 default: 202 snd_BUG(); 203 return ADCCR_SAMPLERATE_8; 204 } 206 205 } 207 206 208 207 static unsigned int snd_emu10k1_audigy_capture_rate_reg(unsigned int rate) 209 208 { 210 211 212 213 214 215 216 217 218 219 220 221 222 223 209 switch (rate) { 210 case 8000: return A_ADCCR_SAMPLERATE_8; 211 case 11025: return A_ADCCR_SAMPLERATE_11; 212 case 12000: return A_ADCCR_SAMPLERATE_12; /* really supported? */ 213 case 16000: return ADCCR_SAMPLERATE_16; 214 case 22050: return ADCCR_SAMPLERATE_22; 215 case 24000: return ADCCR_SAMPLERATE_24; 216 case 32000: return ADCCR_SAMPLERATE_32; 217 case 44100: return ADCCR_SAMPLERATE_44; 218 case 48000: return ADCCR_SAMPLERATE_48; 219 default: 220 snd_BUG(); 221 return A_ADCCR_SAMPLERATE_8; 222 } 224 223 } 225 224 226 225 static unsigned int emu10k1_calc_pitch_target(unsigned int rate) 227 226 { 228 229 230 231 232 227 unsigned int pitch_target; 228 229 pitch_target = (rate << 8) / 375; 230 pitch_target = (pitch_target >> 1) + (pitch_target & 1); 231 return pitch_target; 233 232 } 234 233 … … 242 241 static unsigned int emu10k1_select_interprom(unsigned int pitch_target) 243 242 { 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 else 259 243 if (pitch_target == PITCH_48000) 244 return CCCA_INTERPROM_0; 245 else if (pitch_target < PITCH_48000) 246 return CCCA_INTERPROM_1; 247 else if (pitch_target >= PITCH_96000) 248 return CCCA_INTERPROM_0; 249 else if (pitch_target >= PITCH_85000) 250 return CCCA_INTERPROM_6; 251 else if (pitch_target >= PITCH_80726) 252 return CCCA_INTERPROM_5; 253 else if (pitch_target >= PITCH_67882) 254 return CCCA_INTERPROM_4; 255 else if (pitch_target >= PITCH_57081) 256 return CCCA_INTERPROM_3; 257 else 258 return CCCA_INTERPROM_2; 260 259 } 261 260 262 261 /* 263 * calculate cache invalidate size 262 * calculate cache invalidate size 264 263 * 265 264 * stereo: channel is stereo … … 268 267 * returns: cache invalidate size in samples 269 268 */ 270 static in t inlineemu10k1_ccis(int stereo, int w_16)271 { 272 273 274 275 276 269 static inline int emu10k1_ccis(int stereo, int w_16) 270 { 271 if (w_16) { 272 return stereo ? 24 : 26; 273 } else { 274 return stereo ? 24*2 : 26*2; 275 } 277 276 } 278 277 279 278 static void snd_emu10k1_pcm_init_voice(struct snd_emu10k1 *emu, 280 int master, int extra, 281 struct snd_emu10k1_voice *evoice, 282 unsigned int start_addr, 283 unsigned int end_addr, 284 struct snd_emu10k1_pcm_mixer *mix) 285 { 286 snd_pcm_substream_t *substream = evoice->epcm->substream; 287 snd_pcm_runtime_t *runtime = substream->runtime; 288 unsigned int silent_page, tmp; 289 int voice, stereo, w_16; 290 unsigned char attn, send_amount[8]; 291 unsigned char send_routing[8]; 292 unsigned long flags; 293 unsigned int pitch_target; 294 unsigned int ccis; 295 296 voice = evoice->number; 297 stereo = runtime->channels == 2; 298 w_16 = snd_pcm_format_width(runtime->format) == 16; 299 300 if (!extra && stereo) { 301 start_addr >>= 1; 302 end_addr >>= 1; 303 } 304 if (w_16) { 305 start_addr >>= 1; 306 end_addr >>= 1; 307 } 308 309 spin_lock_irqsave(&emu->reg_lock, flags); 310 311 /* volume parameters */ 312 if (extra) { 313 attn = 0; 314 memset(send_routing, 0, sizeof(send_routing)); 315 send_routing[0] = 0; 316 send_routing[1] = 1; 317 send_routing[2] = 2; 318 send_routing[3] = 3; 319 memset(send_amount, 0, sizeof(send_amount)); 320 } else { 321 /* mono, left, right (master voice = left) */ 322 tmp = stereo ? (master ? 1 : 2) : 0; 323 memcpy(send_routing, &mix->send_routing[tmp][0], 8); 324 memcpy(send_amount, &mix->send_volume[tmp][0], 8); 325 } 326 327 ccis = emu10k1_ccis(stereo, w_16); 328 329 if (master) { 330 evoice->epcm->ccca_start_addr = start_addr + ccis; 331 if (extra) { 332 start_addr += ccis; 333 end_addr += ccis; 334 } 335 if (stereo && !extra) { 336 snd_emu10k1_ptr_write(emu, CPF, voice, CPF_STEREO_MASK); 337 snd_emu10k1_ptr_write(emu, CPF, (voice + 1), CPF_STEREO_MASK); 338 } else { 339 snd_emu10k1_ptr_write(emu, CPF, voice, 0); 340 } 341 } 342 343 // setup routing 344 if (emu->audigy) { 345 snd_emu10k1_ptr_write(emu, A_FXRT1, voice, 346 snd_emu10k1_compose_audigy_fxrt1(send_routing)); 347 snd_emu10k1_ptr_write(emu, A_FXRT2, voice, 348 snd_emu10k1_compose_audigy_fxrt2(send_routing)); 349 snd_emu10k1_ptr_write(emu, A_SENDAMOUNTS, voice, 350 ((unsigned int)send_amount[4] << 24) | 351 ((unsigned int)send_amount[5] << 16) | 352 ((unsigned int)send_amount[6] << 8) | 353 (unsigned int)send_amount[7]); 354 } else 355 snd_emu10k1_ptr_write(emu, FXRT, voice, 356 snd_emu10k1_compose_send_routing(send_routing)); 357 // Stop CA 358 // Assumption that PT is already 0 so no harm overwriting 359 snd_emu10k1_ptr_write(emu, PTRX, voice, (send_amount[0] << 8) | send_amount[1]); 360 snd_emu10k1_ptr_write(emu, DSL, voice, end_addr | (send_amount[3] << 24)); 361 snd_emu10k1_ptr_write(emu, PSST, voice, start_addr | (send_amount[2] << 24)); 362 pitch_target = emu10k1_calc_pitch_target(runtime->rate); 363 if (extra) 364 snd_emu10k1_ptr_write(emu, CCCA, voice, start_addr | 365 emu10k1_select_interprom(pitch_target) | 366 (w_16 ? 0 : CCCA_8BITSELECT)); 367 else 368 snd_emu10k1_ptr_write(emu, CCCA, voice, (start_addr + ccis) | 369 emu10k1_select_interprom(pitch_target) | 370 (w_16 ? 0 : CCCA_8BITSELECT)); 371 // Clear filter delay memory 372 snd_emu10k1_ptr_write(emu, Z1, voice, 0); 373 snd_emu10k1_ptr_write(emu, Z2, voice, 0); 374 // invalidate maps 375 silent_page = ((unsigned int)emu->silent_page.addr << 1) | MAP_PTI_MASK; 376 snd_emu10k1_ptr_write(emu, MAPA, voice, silent_page); 377 snd_emu10k1_ptr_write(emu, MAPB, voice, silent_page); 378 // modulation envelope 379 snd_emu10k1_ptr_write(emu, CVCF, voice, 0xffff); 380 snd_emu10k1_ptr_write(emu, VTFT, voice, 0xffff); 381 snd_emu10k1_ptr_write(emu, ATKHLDM, voice, 0); 382 snd_emu10k1_ptr_write(emu, DCYSUSM, voice, 0x007f); 383 snd_emu10k1_ptr_write(emu, LFOVAL1, voice, 0x8000); 384 snd_emu10k1_ptr_write(emu, LFOVAL2, voice, 0x8000); 385 snd_emu10k1_ptr_write(emu, FMMOD, voice, 0); 386 snd_emu10k1_ptr_write(emu, TREMFRQ, voice, 0); 387 snd_emu10k1_ptr_write(emu, FM2FRQ2, voice, 0); 388 snd_emu10k1_ptr_write(emu, ENVVAL, voice, 0x8000); 389 // volume envelope 390 snd_emu10k1_ptr_write(emu, ATKHLDV, voice, 0x7f7f); 391 snd_emu10k1_ptr_write(emu, ENVVOL, voice, 0x0000); 392 // filter envelope 393 snd_emu10k1_ptr_write(emu, PEFE_FILTERAMOUNT, voice, 0x7f); 394 // pitch envelope 395 snd_emu10k1_ptr_write(emu, PEFE_PITCHAMOUNT, voice, 0); 396 397 spin_unlock_irqrestore(&emu->reg_lock, flags); 398 } 399 400 static int snd_emu10k1_playback_hw_params(snd_pcm_substream_t * substream, 401 snd_pcm_hw_params_t * hw_params) 402 { 403 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 404 snd_pcm_runtime_t *runtime = substream->runtime; 405 struct snd_emu10k1_pcm *epcm = runtime->private_data; 406 int err; 407 408 if ((err = snd_emu10k1_pcm_channel_alloc(epcm, params_channels(hw_params))) < 0) 409 return err; 410 if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0) 411 return err; 412 if (err > 0) { /* change */ 413 snd_util_memblk_t *memblk; 414 if (epcm->memblk != NULL) 415 snd_emu10k1_free_pages(emu, epcm->memblk); 416 memblk = snd_emu10k1_alloc_pages(emu, substream); 417 if ((epcm->memblk = memblk) == NULL || ((struct snd_emu10k1_memblk *)memblk)->mapped_page < 0) { 418 epcm->start_addr = 0; 419 return -ENOMEM; 420 } 421 epcm->start_addr = ((struct snd_emu10k1_memblk *)memblk)->mapped_page << PAGE_SHIFT; 422 } 423 return 0; 424 } 425 426 static int snd_emu10k1_playback_hw_free(snd_pcm_substream_t * substream) 427 { 428 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 429 snd_pcm_runtime_t *runtime = substream->runtime; 430 struct snd_emu10k1_pcm *epcm; 431 432 if (runtime->private_data == NULL) 433 return 0; 434 epcm = runtime->private_data; 435 if (epcm->extra) { 436 snd_emu10k1_voice_free(epcm->emu, epcm->extra); 437 epcm->extra = NULL; 438 } 439 if (epcm->voices[1]) { 440 snd_emu10k1_voice_free(epcm->emu, epcm->voices[1]); 441 epcm->voices[1] = NULL; 442 } 443 if (epcm->voices[0]) { 444 snd_emu10k1_voice_free(epcm->emu, epcm->voices[0]); 445 epcm->voices[0] = NULL; 446 } 447 if (epcm->memblk) { 448 snd_emu10k1_free_pages(emu, epcm->memblk); 449 epcm->memblk = NULL; 450 epcm->start_addr = 0; 451 } 452 snd_pcm_lib_free_pages(substream); 453 return 0; 454 } 455 456 static int snd_emu10k1_efx_playback_hw_free(snd_pcm_substream_t * substream) 457 { 458 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 459 snd_pcm_runtime_t *runtime = substream->runtime; 460 struct snd_emu10k1_pcm *epcm; 461 int i; 462 463 if (runtime->private_data == NULL) 464 return 0; 465 epcm = runtime->private_data; 466 if (epcm->extra) { 467 snd_emu10k1_voice_free(epcm->emu, epcm->extra); 468 epcm->extra = NULL; 469 } 470 for (i=0; i < NUM_EFX_PLAYBACK; i++) { 471 if (epcm->voices[i]) { 472 snd_emu10k1_voice_free(epcm->emu, epcm->voices[i]); 473 epcm->voices[i] = NULL; 474 } 475 } 476 if (epcm->memblk) { 477 snd_emu10k1_free_pages(emu, epcm->memblk); 478 epcm->memblk = NULL; 479 epcm->start_addr = 0; 480 } 481 snd_pcm_lib_free_pages(substream); 482 return 0; 483 } 484 485 static int snd_emu10k1_playback_prepare(snd_pcm_substream_t * substream) 486 { 487 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 488 snd_pcm_runtime_t *runtime = substream->runtime; 489 struct snd_emu10k1_pcm *epcm = runtime->private_data; 490 unsigned int start_addr, end_addr; 491 492 start_addr = epcm->start_addr; 493 end_addr = snd_pcm_lib_period_bytes(substream); 494 if (runtime->channels == 2) { 495 start_addr >>= 1; 496 end_addr >>= 1; 497 } 498 end_addr += start_addr; 499 snd_emu10k1_pcm_init_voice(emu, 1, 1, epcm->extra, 500 start_addr, end_addr, NULL); 501 start_addr = epcm->start_addr; 502 end_addr = epcm->start_addr + snd_pcm_lib_buffer_bytes(substream); 503 snd_emu10k1_pcm_init_voice(emu, 1, 0, epcm->voices[0], 504 start_addr, end_addr, 505 &emu->pcm_mixer[substream->number]); 506 if (epcm->voices[1]) 507 snd_emu10k1_pcm_init_voice(emu, 0, 0, epcm->voices[1], 508 start_addr, end_addr, 509 &emu->pcm_mixer[substream->number]); 510 return 0; 511 } 512 513 static int snd_emu10k1_efx_playback_prepare(snd_pcm_substream_t * substream) 514 { 515 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 516 snd_pcm_runtime_t *runtime = substream->runtime; 517 struct snd_emu10k1_pcm *epcm = runtime->private_data; 518 unsigned int start_addr, end_addr; 519 unsigned int channel_size; 520 int i; 521 522 start_addr = epcm->start_addr; 523 end_addr = epcm->start_addr + snd_pcm_lib_buffer_bytes(substream); 524 525 /* 526 * the kX driver leaves some space between voices 527 */ 528 channel_size = ( end_addr - start_addr ) / NUM_EFX_PLAYBACK; 529 530 snd_emu10k1_pcm_init_voice(emu, 1, 1, epcm->extra, 531 start_addr, start_addr + (channel_size / 2), NULL); 532 533 /* only difference with the master voice is we use it for the pointer */ 534 snd_emu10k1_pcm_init_voice(emu, 1, 0, epcm->voices[0], 535 start_addr, start_addr + channel_size, 536 &emu->efx_pcm_mixer[0]); 537 538 start_addr += channel_size; 539 for (i = 1; i < NUM_EFX_PLAYBACK; i++) { 540 snd_emu10k1_pcm_init_voice(emu, 0, 0, epcm->voices[i], 541 start_addr, start_addr + channel_size, 542 &emu->efx_pcm_mixer[i]); 543 start_addr += channel_size; 544 } 545 546 return 0; 547 } 548 549 static snd_pcm_hardware_t snd_emu10k1_efx_playback = 550 { 551 /*.info = */ (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_NONINTERLEAVED | 552 SNDRV_PCM_INFO_BLOCK_TRANSFER | 553 SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_PAUSE), 554 /*.formats = */ SNDRV_PCM_FMTBIT_S16_LE, 555 /*.rates = */ SNDRV_PCM_RATE_48000, 556 /*.rate_min = */ 48000, 557 /*.rate_max = */ 48000, 558 /*.channels_min = */ NUM_EFX_PLAYBACK, 559 /*.channels_max = */ NUM_EFX_PLAYBACK, 560 /*.buffer_bytes_max = */ (64*1024), 561 /*.period_bytes_min = */ 64, 562 /*.period_bytes_max = */ (64*1024), 563 /*.periods_min = */ 2, 564 /*.periods_max = */ 2, 565 /*.fifo_size = */ 0 279 int master, int extra, 280 struct snd_emu10k1_voice *evoice, 281 unsigned int start_addr, 282 unsigned int end_addr, 283 struct snd_emu10k1_pcm_mixer *mix) 284 { 285 struct snd_pcm_substream *substream = evoice->epcm->substream; 286 struct snd_pcm_runtime *runtime = substream->runtime; 287 unsigned int silent_page, tmp; 288 int voice, stereo, w_16; 289 unsigned char attn, send_amount[8]; 290 unsigned char send_routing[8]; 291 unsigned long flags; 292 unsigned int pitch_target; 293 unsigned int ccis; 294 295 voice = evoice->number; 296 stereo = runtime->channels == 2; 297 w_16 = snd_pcm_format_width(runtime->format) == 16; 298 299 if (!extra && stereo) { 300 start_addr >>= 1; 301 end_addr >>= 1; 302 } 303 if (w_16) { 304 start_addr >>= 1; 305 end_addr >>= 1; 306 } 307 308 spin_lock_irqsave(&emu->reg_lock, flags); 309 310 /* volume parameters */ 311 if (extra) { 312 attn = 0; 313 memset(send_routing, 0, sizeof(send_routing)); 314 send_routing[0] = 0; 315 send_routing[1] = 1; 316 send_routing[2] = 2; 317 send_routing[3] = 3; 318 memset(send_amount, 0, sizeof(send_amount)); 319 } else { 320 /* mono, left, right (master voice = left) */ 321 tmp = stereo ? (master ? 1 : 2) : 0; 322 memcpy(send_routing, &mix->send_routing[tmp][0], 8); 323 memcpy(send_amount, &mix->send_volume[tmp][0], 8); 324 } 325 326 ccis = emu10k1_ccis(stereo, w_16); 327 328 if (master) { 329 evoice->epcm->ccca_start_addr = start_addr + ccis; 330 if (extra) { 331 start_addr += ccis; 332 end_addr += ccis; 333 } 334 if (stereo && !extra) { 335 snd_emu10k1_ptr_write(emu, CPF, voice, CPF_STEREO_MASK); 336 snd_emu10k1_ptr_write(emu, CPF, (voice + 1), CPF_STEREO_MASK); 337 } else { 338 snd_emu10k1_ptr_write(emu, CPF, voice, 0); 339 } 340 } 341 342 /* setup routing */ 343 if (emu->audigy) { 344 snd_emu10k1_ptr_write(emu, A_FXRT1, voice, 345 snd_emu10k1_compose_audigy_fxrt1(send_routing)); 346 snd_emu10k1_ptr_write(emu, A_FXRT2, voice, 347 snd_emu10k1_compose_audigy_fxrt2(send_routing)); 348 snd_emu10k1_ptr_write(emu, A_SENDAMOUNTS, voice, 349 ((unsigned int)send_amount[4] << 24) | 350 ((unsigned int)send_amount[5] << 16) | 351 ((unsigned int)send_amount[6] << 8) | 352 (unsigned int)send_amount[7]); 353 } else 354 snd_emu10k1_ptr_write(emu, FXRT, voice, 355 snd_emu10k1_compose_send_routing(send_routing)); 356 /* Stop CA */ 357 /* Assumption that PT is already 0 so no harm overwriting */ 358 snd_emu10k1_ptr_write(emu, PTRX, voice, (send_amount[0] << 8) | send_amount[1]); 359 snd_emu10k1_ptr_write(emu, DSL, voice, end_addr | (send_amount[3] << 24)); 360 snd_emu10k1_ptr_write(emu, PSST, voice, start_addr | (send_amount[2] << 24)); 361 if (emu->card_capabilities->emu1010) 362 pitch_target = PITCH_48000; /* Disable interpolators on emu1010 card */ 363 else 364 pitch_target = emu10k1_calc_pitch_target(runtime->rate); 365 if (extra) 366 snd_emu10k1_ptr_write(emu, CCCA, voice, start_addr | 367 emu10k1_select_interprom(pitch_target) | 368 (w_16 ? 0 : CCCA_8BITSELECT)); 369 else 370 snd_emu10k1_ptr_write(emu, CCCA, voice, (start_addr + ccis) | 371 emu10k1_select_interprom(pitch_target) | 372 (w_16 ? 0 : CCCA_8BITSELECT)); 373 /* Clear filter delay memory */ 374 snd_emu10k1_ptr_write(emu, Z1, voice, 0); 375 snd_emu10k1_ptr_write(emu, Z2, voice, 0); 376 /* invalidate maps */ 377 silent_page = ((unsigned int)emu->silent_page.addr << 1) | MAP_PTI_MASK; 378 snd_emu10k1_ptr_write(emu, MAPA, voice, silent_page); 379 snd_emu10k1_ptr_write(emu, MAPB, voice, silent_page); 380 /* modulation envelope */ 381 snd_emu10k1_ptr_write(emu, CVCF, voice, 0xffff); 382 snd_emu10k1_ptr_write(emu, VTFT, voice, 0xffff); 383 snd_emu10k1_ptr_write(emu, ATKHLDM, voice, 0); 384 snd_emu10k1_ptr_write(emu, DCYSUSM, voice, 0x007f); 385 snd_emu10k1_ptr_write(emu, LFOVAL1, voice, 0x8000); 386 snd_emu10k1_ptr_write(emu, LFOVAL2, voice, 0x8000); 387 snd_emu10k1_ptr_write(emu, FMMOD, voice, 0); 388 snd_emu10k1_ptr_write(emu, TREMFRQ, voice, 0); 389 snd_emu10k1_ptr_write(emu, FM2FRQ2, voice, 0); 390 snd_emu10k1_ptr_write(emu, ENVVAL, voice, 0x8000); 391 /* volume envelope */ 392 snd_emu10k1_ptr_write(emu, ATKHLDV, voice, 0x7f7f); 393 snd_emu10k1_ptr_write(emu, ENVVOL, voice, 0x0000); 394 /* filter envelope */ 395 snd_emu10k1_ptr_write(emu, PEFE_FILTERAMOUNT, voice, 0x7f); 396 /* pitch envelope */ 397 snd_emu10k1_ptr_write(emu, PEFE_PITCHAMOUNT, voice, 0); 398 399 spin_unlock_irqrestore(&emu->reg_lock, flags); 400 } 401 402 static int snd_emu10k1_playback_hw_params(struct snd_pcm_substream *substream, 403 struct snd_pcm_hw_params *hw_params) 404 { 405 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 406 struct snd_pcm_runtime *runtime = substream->runtime; 407 struct snd_emu10k1_pcm *epcm = runtime->private_data; 408 int err; 409 410 if ((err = snd_emu10k1_pcm_channel_alloc(epcm, params_channels(hw_params))) < 0) 411 return err; 412 if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0) 413 return err; 414 if (err > 0) { /* change */ 415 int mapped; 416 if (epcm->memblk != NULL) 417 snd_emu10k1_free_pages(emu, epcm->memblk); 418 epcm->memblk = snd_emu10k1_alloc_pages(emu, substream); 419 epcm->start_addr = 0; 420 if (! epcm->memblk) 421 return -ENOMEM; 422 mapped = ((struct snd_emu10k1_memblk *)epcm->memblk)->mapped_page; 423 if (mapped < 0) 424 return -ENOMEM; 425 epcm->start_addr = mapped << PAGE_SHIFT; 426 } 427 return 0; 428 } 429 430 static int snd_emu10k1_playback_hw_free(struct snd_pcm_substream *substream) 431 { 432 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 433 struct snd_pcm_runtime *runtime = substream->runtime; 434 struct snd_emu10k1_pcm *epcm; 435 436 if (runtime->private_data == NULL) 437 return 0; 438 epcm = runtime->private_data; 439 if (epcm->extra) { 440 snd_emu10k1_voice_free(epcm->emu, epcm->extra); 441 epcm->extra = NULL; 442 } 443 if (epcm->voices[1]) { 444 snd_emu10k1_voice_free(epcm->emu, epcm->voices[1]); 445 epcm->voices[1] = NULL; 446 } 447 if (epcm->voices[0]) { 448 snd_emu10k1_voice_free(epcm->emu, epcm->voices[0]); 449 epcm->voices[0] = NULL; 450 } 451 if (epcm->memblk) { 452 snd_emu10k1_free_pages(emu, epcm->memblk); 453 epcm->memblk = NULL; 454 epcm->start_addr = 0; 455 } 456 snd_pcm_lib_free_pages(substream); 457 return 0; 458 } 459 460 static int snd_emu10k1_efx_playback_hw_free(struct snd_pcm_substream *substream) 461 { 462 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 463 struct snd_pcm_runtime *runtime = substream->runtime; 464 struct snd_emu10k1_pcm *epcm; 465 int i; 466 467 if (runtime->private_data == NULL) 468 return 0; 469 epcm = runtime->private_data; 470 if (epcm->extra) { 471 snd_emu10k1_voice_free(epcm->emu, epcm->extra); 472 epcm->extra = NULL; 473 } 474 for (i = 0; i < NUM_EFX_PLAYBACK; i++) { 475 if (epcm->voices[i]) { 476 snd_emu10k1_voice_free(epcm->emu, epcm->voices[i]); 477 epcm->voices[i] = NULL; 478 } 479 } 480 if (epcm->memblk) { 481 snd_emu10k1_free_pages(emu, epcm->memblk); 482 epcm->memblk = NULL; 483 epcm->start_addr = 0; 484 } 485 snd_pcm_lib_free_pages(substream); 486 return 0; 487 } 488 489 static int snd_emu10k1_playback_prepare(struct snd_pcm_substream *substream) 490 { 491 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 492 struct snd_pcm_runtime *runtime = substream->runtime; 493 struct snd_emu10k1_pcm *epcm = runtime->private_data; 494 unsigned int start_addr, end_addr; 495 496 start_addr = epcm->start_addr; 497 end_addr = snd_pcm_lib_period_bytes(substream); 498 if (runtime->channels == 2) { 499 start_addr >>= 1; 500 end_addr >>= 1; 501 } 502 end_addr += start_addr; 503 snd_emu10k1_pcm_init_voice(emu, 1, 1, epcm->extra, 504 start_addr, end_addr, NULL); 505 start_addr = epcm->start_addr; 506 end_addr = epcm->start_addr + snd_pcm_lib_buffer_bytes(substream); 507 snd_emu10k1_pcm_init_voice(emu, 1, 0, epcm->voices[0], 508 start_addr, end_addr, 509 &emu->pcm_mixer[substream->number]); 510 if (epcm->voices[1]) 511 snd_emu10k1_pcm_init_voice(emu, 0, 0, epcm->voices[1], 512 start_addr, end_addr, 513 &emu->pcm_mixer[substream->number]); 514 return 0; 515 } 516 517 static int snd_emu10k1_efx_playback_prepare(struct snd_pcm_substream *substream) 518 { 519 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 520 struct snd_pcm_runtime *runtime = substream->runtime; 521 struct snd_emu10k1_pcm *epcm = runtime->private_data; 522 unsigned int start_addr, end_addr; 523 unsigned int channel_size; 524 int i; 525 526 start_addr = epcm->start_addr; 527 end_addr = epcm->start_addr + snd_pcm_lib_buffer_bytes(substream); 528 529 /* 530 * the kX driver leaves some space between voices 531 */ 532 channel_size = ( end_addr - start_addr ) / NUM_EFX_PLAYBACK; 533 534 snd_emu10k1_pcm_init_voice(emu, 1, 1, epcm->extra, 535 start_addr, start_addr + (channel_size / 2), NULL); 536 537 /* only difference with the master voice is we use it for the pointer */ 538 snd_emu10k1_pcm_init_voice(emu, 1, 0, epcm->voices[0], 539 start_addr, start_addr + channel_size, 540 &emu->efx_pcm_mixer[0]); 541 542 start_addr += channel_size; 543 for (i = 1; i < NUM_EFX_PLAYBACK; i++) { 544 snd_emu10k1_pcm_init_voice(emu, 0, 0, epcm->voices[i], 545 start_addr, start_addr + channel_size, 546 &emu->efx_pcm_mixer[i]); 547 start_addr += channel_size; 548 } 549 550 return 0; 551 } 552 553 static struct snd_pcm_hardware snd_emu10k1_efx_playback = 554 { 555 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_NONINTERLEAVED | 556 SNDRV_PCM_INFO_BLOCK_TRANSFER | 557 SNDRV_PCM_INFO_RESUME | 558 SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_PAUSE), 559 .formats = SNDRV_PCM_FMTBIT_S16_LE, 560 .rates = SNDRV_PCM_RATE_48000, 561 .rate_min = 48000, 562 .rate_max = 48000, 563 .channels_min = NUM_EFX_PLAYBACK, 564 .channels_max = NUM_EFX_PLAYBACK, 565 .buffer_bytes_max = (64*1024), 566 .period_bytes_min = 64, 567 .period_bytes_max = (64*1024), 568 .periods_min = 2, 569 .periods_max = 2, 570 .fifo_size = 0, 566 571 }; 567 572 568 static int snd_emu10k1_capture_hw_params(s nd_pcm_substream_t *substream,569 snd_pcm_hw_params_t *hw_params)570 { 571 572 } 573 574 static int snd_emu10k1_capture_hw_free(s nd_pcm_substream_t *substream)575 { 576 577 } 578 579 static int snd_emu10k1_capture_prepare(s nd_pcm_substream_t *substream)580 { 581 582 snd_pcm_runtime_t*runtime = substream->runtime;583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 } 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 573 static int snd_emu10k1_capture_hw_params(struct snd_pcm_substream *substream, 574 struct snd_pcm_hw_params *hw_params) 575 { 576 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); 577 } 578 579 static int snd_emu10k1_capture_hw_free(struct snd_pcm_substream *substream) 580 { 581 return snd_pcm_lib_free_pages(substream); 582 } 583 584 static int snd_emu10k1_capture_prepare(struct snd_pcm_substream *substream) 585 { 586 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 587 struct snd_pcm_runtime *runtime = substream->runtime; 588 struct snd_emu10k1_pcm *epcm = runtime->private_data; 589 int idx; 590 591 /* zeroing the buffer size will stop capture */ 592 snd_emu10k1_ptr_write(emu, epcm->capture_bs_reg, 0, 0); 593 switch (epcm->type) { 594 case CAPTURE_AC97ADC: 595 snd_emu10k1_ptr_write(emu, ADCCR, 0, 0); 596 break; 597 case CAPTURE_EFX: 598 if (emu->audigy) { 599 snd_emu10k1_ptr_write(emu, A_FXWC1, 0, 0); 600 snd_emu10k1_ptr_write(emu, A_FXWC2, 0, 0); 601 } else 602 snd_emu10k1_ptr_write(emu, FXWC, 0, 0); 603 break; 604 default: 605 break; 606 } 607 snd_emu10k1_ptr_write(emu, epcm->capture_ba_reg, 0, runtime->dma_addr); 608 epcm->capture_bufsize = snd_pcm_lib_buffer_bytes(substream); 609 epcm->capture_bs_val = 0; 610 for (idx = 0; idx < 31; idx++) { 611 if (capture_period_sizes[idx] == epcm->capture_bufsize) { 612 epcm->capture_bs_val = idx + 1; 613 break; 614 } 615 } 616 if (epcm->capture_bs_val == 0) { 617 snd_BUG(); 618 epcm->capture_bs_val++; 619 } 620 if (epcm->type == CAPTURE_AC97ADC) { 621 epcm->capture_cr_val = emu->audigy ? A_ADCCR_LCHANENABLE : ADCCR_LCHANENABLE; 622 if (runtime->channels > 1) 623 epcm->capture_cr_val |= emu->audigy ? A_ADCCR_RCHANENABLE : ADCCR_RCHANENABLE; 624 epcm->capture_cr_val |= emu->audigy ? 625 snd_emu10k1_audigy_capture_rate_reg(runtime->rate) : 626 snd_emu10k1_capture_rate_reg(runtime->rate); 627 } 628 return 0; 624 629 } 625 630 626 631 static void snd_emu10k1_playback_invalidate_cache(struct snd_emu10k1 *emu, int extra, struct snd_emu10k1_voice *evoice) 627 632 { 628 snd_pcm_runtime_t*runtime;629 630 631 632 633 634 635 636 637 638 // set cs to 2 * number of cache registers beside the invalidated 639 640 641 642 643 644 645 646 647 // reset cache 648 649 650 651 652 653 654 // fill cache 655 656 657 658 633 struct snd_pcm_runtime *runtime; 634 unsigned int voice, stereo, i, ccis, cra = 64, cs, sample; 635 636 if (evoice == NULL) 637 return; 638 runtime = evoice->epcm->substream->runtime; 639 voice = evoice->number; 640 stereo = (!extra && runtime->channels == 2); 641 sample = snd_pcm_format_width(runtime->format) == 16 ? 0 : 0x80808080; 642 ccis = emu10k1_ccis(stereo, sample == 0); 643 /* set cs to 2 * number of cache registers beside the invalidated */ 644 cs = (sample == 0) ? (32-ccis) : (64-ccis+1) >> 1; 645 if (cs > 16) cs = 16; 646 for (i = 0; i < cs; i++) { 647 snd_emu10k1_ptr_write(emu, CD0 + i, voice, sample); 648 if (stereo) { 649 snd_emu10k1_ptr_write(emu, CD0 + i, voice + 1, sample); 650 } 651 } 652 /* reset cache */ 653 snd_emu10k1_ptr_write(emu, CCR_CACHEINVALIDSIZE, voice, 0); 654 snd_emu10k1_ptr_write(emu, CCR_READADDRESS, voice, cra); 655 if (stereo) { 656 snd_emu10k1_ptr_write(emu, CCR_CACHEINVALIDSIZE, voice + 1, 0); 657 snd_emu10k1_ptr_write(emu, CCR_READADDRESS, voice + 1, cra); 658 } 659 /* fill cache */ 660 snd_emu10k1_ptr_write(emu, CCR_CACHEINVALIDSIZE, voice, ccis); 661 if (stereo) { 662 snd_emu10k1_ptr_write(emu, CCR_CACHEINVALIDSIZE, voice+1, ccis); 663 } 659 664 } 660 665 661 666 static void snd_emu10k1_playback_prepare_voice(struct snd_emu10k1 *emu, struct snd_emu10k1_voice *evoice, 662 int master, int extra, 663 struct snd_emu10k1_pcm_mixer *mix) 664 { 665 snd_pcm_substream_t *substream; 666 snd_pcm_runtime_t *runtime; 667 unsigned int attn, vattn; 668 unsigned int voice, tmp; 669 670 if (evoice == NULL) /* skip second voice for mono */ 671 return; 672 substream = evoice->epcm->substream; 673 runtime = substream->runtime; 674 voice = evoice->number; 675 attn = extra ? 0 : 0x00ff; 676 tmp = runtime->channels == 2 ? (master ? 1 : 2) : 0; 677 vattn = mix != NULL ? (mix->attn[tmp] << 16) : 0; 678 snd_emu10k1_ptr_write(emu, IFATN, voice, attn); 679 snd_emu10k1_ptr_write(emu, VTFT, voice, vattn | 0xffff); 680 snd_emu10k1_ptr_write(emu, CVCF, voice, vattn | 0xffff); 681 snd_emu10k1_ptr_write(emu, DCYSUSV, voice, 0x7f7f); 682 snd_emu10k1_voice_clear_loop_stop(emu, voice); 683 } 667 int master, int extra, 668 struct snd_emu10k1_pcm_mixer *mix) 669 { 670 struct snd_pcm_substream *substream; 671 struct snd_pcm_runtime *runtime; 672 unsigned int attn, vattn; 673 unsigned int voice, tmp; 674 675 if (evoice == NULL) /* skip second voice for mono */ 676 return; 677 substream = evoice->epcm->substream; 678 runtime = substream->runtime; 679 voice = evoice->number; 680 681 attn = extra ? 0 : 0x00ff; 682 tmp = runtime->channels == 2 ? (master ? 1 : 2) : 0; 683 vattn = mix != NULL ? (mix->attn[tmp] << 16) : 0; 684 snd_emu10k1_ptr_write(emu, IFATN, voice, attn); 685 snd_emu10k1_ptr_write(emu, VTFT, voice, vattn | 0xffff); 686 snd_emu10k1_ptr_write(emu, CVCF, voice, vattn | 0xffff); 687 snd_emu10k1_ptr_write(emu, DCYSUSV, voice, 0x7f7f); 688 snd_emu10k1_voice_clear_loop_stop(emu, voice); 689 } 684 690 685 691 static void snd_emu10k1_playback_trigger_voice(struct snd_emu10k1 *emu, struct snd_emu10k1_voice *evoice, int master, int extra) 686 692 { 687 snd_pcm_substream_t *substream; 688 snd_pcm_runtime_t *runtime; 689 unsigned int voice, pitch, pitch_target; 690 691 if (evoice == NULL) /* skip second voice for mono */ 692 return; 693 substream = evoice->epcm->substream; 694 runtime = substream->runtime; 695 voice = evoice->number; 696 697 pitch = snd_emu10k1_rate_to_pitch(runtime->rate) >> 8; 698 pitch_target = emu10k1_calc_pitch_target(runtime->rate); 699 snd_emu10k1_ptr_write(emu, PTRX_PITCHTARGET, voice, pitch_target); 700 if (master || evoice->epcm->type == PLAYBACK_EFX) 701 snd_emu10k1_ptr_write(emu, CPF_CURRENTPITCH, voice, pitch_target); 702 snd_emu10k1_ptr_write(emu, IP, voice, pitch); 703 if (extra) 704 snd_emu10k1_voice_intr_enable(emu, voice); 693 struct snd_pcm_substream *substream; 694 struct snd_pcm_runtime *runtime; 695 unsigned int voice, pitch, pitch_target; 696 697 if (evoice == NULL) /* skip second voice for mono */ 698 return; 699 substream = evoice->epcm->substream; 700 runtime = substream->runtime; 701 voice = evoice->number; 702 703 pitch = snd_emu10k1_rate_to_pitch(runtime->rate) >> 8; 704 if (emu->card_capabilities->emu1010) 705 pitch_target = PITCH_48000; /* Disable interpolators on emu1010 card */ 706 else 707 pitch_target = emu10k1_calc_pitch_target(runtime->rate); 708 snd_emu10k1_ptr_write(emu, PTRX_PITCHTARGET, voice, pitch_target); 709 if (master || evoice->epcm->type == PLAYBACK_EFX) 710 snd_emu10k1_ptr_write(emu, CPF_CURRENTPITCH, voice, pitch_target); 711 snd_emu10k1_ptr_write(emu, IP, voice, pitch); 712 if (extra) 713 snd_emu10k1_voice_intr_enable(emu, voice); 705 714 } 706 715 707 716 static void snd_emu10k1_playback_stop_voice(struct snd_emu10k1 *emu, struct snd_emu10k1_voice *evoice) 708 717 { 709 unsigned int voice; 710 711 if (evoice == NULL) 712 return; 713 voice = evoice->number; 714 snd_emu10k1_voice_intr_disable(emu, voice); 715 snd_emu10k1_ptr_write(emu, PTRX_PITCHTARGET, voice, 0); 716 snd_emu10k1_ptr_write(emu, CPF_CURRENTPITCH, voice, 0); 717 snd_emu10k1_ptr_write(emu, IFATN, voice, 0xffff); 718 snd_emu10k1_ptr_write(emu, VTFT, voice, 0xffff); 719 snd_emu10k1_ptr_write(emu, CVCF, voice, 0xffff); 720 snd_emu10k1_ptr_write(emu, IP, voice, 0); 721 } 722 723 static int snd_emu10k1_playback_trigger(snd_pcm_substream_t * substream, 724 int cmd) 725 { 726 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 727 snd_pcm_runtime_t *runtime = substream->runtime; 728 struct snd_emu10k1_pcm *epcm = runtime->private_data; 729 struct snd_emu10k1_pcm_mixer *mix; 730 int result = 0; 731 732 spin_lock(&emu->reg_lock); 733 switch (cmd) { 734 case SNDRV_PCM_TRIGGER_START: 735 // hmm this should cause full and half full interrupt to be raised? 736 snd_emu10k1_playback_invalidate_cache(emu, 1, epcm->extra); /* do we need this? */ 737 snd_emu10k1_playback_invalidate_cache(emu, 0, epcm->voices[0]); 738 /* follow thru */ 739 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 740 mix = &emu->pcm_mixer[substream->number]; 741 snd_emu10k1_playback_prepare_voice(emu, epcm->voices[0], 1, 0, mix); 742 snd_emu10k1_playback_prepare_voice(emu, epcm->voices[1], 0, 0, mix); 743 snd_emu10k1_playback_prepare_voice(emu, epcm->extra, 1, 1, NULL); 744 snd_emu10k1_playback_trigger_voice(emu, epcm->voices[0], 1, 0); 745 snd_emu10k1_playback_trigger_voice(emu, epcm->voices[1], 0, 0); 746 snd_emu10k1_playback_trigger_voice(emu, epcm->extra, 1, 1); 747 epcm->running = 1; 748 break; 749 case SNDRV_PCM_TRIGGER_STOP: 750 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 751 epcm->running = 0; 752 snd_emu10k1_playback_stop_voice(emu, epcm->voices[0]); 753 snd_emu10k1_playback_stop_voice(emu, epcm->voices[1]); 754 snd_emu10k1_playback_stop_voice(emu, epcm->extra); 755 break; 756 default: 757 result = -EINVAL; 758 break; 759 } 760 spin_unlock(&emu->reg_lock); 761 return result; 762 } 763 764 static int snd_emu10k1_capture_trigger(snd_pcm_substream_t * substream, 765 int cmd) 766 { 767 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 768 snd_pcm_runtime_t *runtime = substream->runtime; 769 struct snd_emu10k1_pcm *epcm = runtime->private_data; 770 int result = 0; 771 772 // printk("trigger - emu10k1 = %p, cmd = %i, pointer = %i\n", emu, cmd, substream->ops->pointer(substream)); 773 spin_lock(&emu->reg_lock); 774 switch (cmd) { 775 case SNDRV_PCM_TRIGGER_START: 776 outl(epcm->capture_ipr, emu->port + IPR); 777 snd_emu10k1_intr_enable(emu, epcm->capture_inte); 778 // printk("adccr = 0x%x, adcbs = 0x%x\n", epcm->adccr, epcm->adcbs); 779 switch (epcm->type) { 780 case CAPTURE_AC97ADC: 781 snd_emu10k1_ptr_write(emu, ADCCR, 0, epcm->capture_cr_val); 782 break; 783 case CAPTURE_EFX: 784 if (emu->audigy) { 785 snd_emu10k1_ptr_write(emu, A_FXWC1, 0, epcm->capture_cr_val); 786 snd_emu10k1_ptr_write(emu, A_FXWC2, 0, epcm->capture_cr_val2); 787 } else 788 snd_emu10k1_ptr_write(emu, FXWC, 0, epcm->capture_cr_val); 789 break; 790 default: 791 break; 792 } 793 snd_emu10k1_ptr_write(emu, epcm->capture_bs_reg, 0, epcm->capture_bs_val); 794 epcm->running = 1; 795 epcm->first_ptr = 1; 796 break; 797 case SNDRV_PCM_TRIGGER_STOP: 798 epcm->running = 0; 799 snd_emu10k1_intr_disable(emu, epcm->capture_inte); 800 outl(epcm->capture_ipr, emu->port + IPR); 801 snd_emu10k1_ptr_write(emu, epcm->capture_bs_reg, 0, 0); 802 switch (epcm->type) { 803 case CAPTURE_AC97ADC: 804 snd_emu10k1_ptr_write(emu, ADCCR, 0, 0); 805 break; 806 case CAPTURE_EFX: 807 if (emu->audigy) { 808 snd_emu10k1_ptr_write(emu, A_FXWC1, 0, 0); 809 snd_emu10k1_ptr_write(emu, A_FXWC2, 0, 0); 810 } else 811 snd_emu10k1_ptr_write(emu, FXWC, 0, 0); 812 break; 813 default: 814 break; 815 } 816 break; 817 default: 818 result = -EINVAL; 819 } 820 spin_unlock(&emu->reg_lock); 821 return result; 822 } 823 824 static snd_pcm_uframes_t snd_emu10k1_playback_pointer(snd_pcm_substream_t * substream) 825 { 826 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 827 snd_pcm_runtime_t *runtime = substream->runtime; 828 struct snd_emu10k1_pcm *epcm = runtime->private_data; 829 unsigned int ptr; 830 831 if (!epcm->running) 832 return 0; 833 ptr = snd_emu10k1_ptr_read(emu, CCCA, epcm->voices[0]->number) & 0x00ffffff; 718 unsigned int voice; 719 720 if (evoice == NULL) 721 return; 722 voice = evoice->number; 723 snd_emu10k1_voice_intr_disable(emu, voice); 724 snd_emu10k1_ptr_write(emu, PTRX_PITCHTARGET, voice, 0); 725 snd_emu10k1_ptr_write(emu, CPF_CURRENTPITCH, voice, 0); 726 snd_emu10k1_ptr_write(emu, IFATN, voice, 0xffff); 727 snd_emu10k1_ptr_write(emu, VTFT, voice, 0xffff); 728 snd_emu10k1_ptr_write(emu, CVCF, voice, 0xffff); 729 snd_emu10k1_ptr_write(emu, IP, voice, 0); 730 } 731 732 static int snd_emu10k1_playback_trigger(struct snd_pcm_substream *substream, 733 int cmd) 734 { 735 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 736 struct snd_pcm_runtime *runtime = substream->runtime; 737 struct snd_emu10k1_pcm *epcm = runtime->private_data; 738 struct snd_emu10k1_pcm_mixer *mix; 739 int result = 0; 740 741 /* printk("trigger - emu10k1 = 0x%x, cmd = %i, pointer = %i\n", (int)emu, cmd, substream->ops->pointer(substream)); */ 742 spin_lock(&emu->reg_lock); 743 switch (cmd) { 744 case SNDRV_PCM_TRIGGER_START: 745 snd_emu10k1_playback_invalidate_cache(emu, 1, epcm->extra); /* do we need this? */ 746 snd_emu10k1_playback_invalidate_cache(emu, 0, epcm->voices[0]); 747 /* follow thru */ 748 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 749 case SNDRV_PCM_TRIGGER_RESUME: 750 mix = &emu->pcm_mixer[substream->number]; 751 snd_emu10k1_playback_prepare_voice(emu, epcm->voices[0], 1, 0, mix); 752 snd_emu10k1_playback_prepare_voice(emu, epcm->voices[1], 0, 0, mix); 753 snd_emu10k1_playback_prepare_voice(emu, epcm->extra, 1, 1, NULL); 754 snd_emu10k1_playback_trigger_voice(emu, epcm->voices[0], 1, 0); 755 snd_emu10k1_playback_trigger_voice(emu, epcm->voices[1], 0, 0); 756 snd_emu10k1_playback_trigger_voice(emu, epcm->extra, 1, 1); 757 epcm->running = 1; 758 break; 759 case SNDRV_PCM_TRIGGER_STOP: 760 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 761 case SNDRV_PCM_TRIGGER_SUSPEND: 762 epcm->running = 0; 763 snd_emu10k1_playback_stop_voice(emu, epcm->voices[0]); 764 snd_emu10k1_playback_stop_voice(emu, epcm->voices[1]); 765 snd_emu10k1_playback_stop_voice(emu, epcm->extra); 766 break; 767 default: 768 result = -EINVAL; 769 break; 770 } 771 spin_unlock(&emu->reg_lock); 772 return result; 773 } 774 775 static int snd_emu10k1_capture_trigger(struct snd_pcm_substream *substream, 776 int cmd) 777 { 778 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 779 struct snd_pcm_runtime *runtime = substream->runtime; 780 struct snd_emu10k1_pcm *epcm = runtime->private_data; 781 int result = 0; 782 783 spin_lock(&emu->reg_lock); 784 switch (cmd) { 785 case SNDRV_PCM_TRIGGER_START: 786 case SNDRV_PCM_TRIGGER_RESUME: 787 /* hmm this should cause full and half full interrupt to be raised? */ 788 outl(epcm->capture_ipr, emu->port + IPR); 789 snd_emu10k1_intr_enable(emu, epcm->capture_inte); 790 /* printk("adccr = 0x%x, adcbs = 0x%x\n", epcm->adccr, epcm->adcbs); */ 791 switch (epcm->type) { 792 case CAPTURE_AC97ADC: 793 snd_emu10k1_ptr_write(emu, ADCCR, 0, epcm->capture_cr_val); 794 break; 795 case CAPTURE_EFX: 796 if (emu->audigy) { 797 snd_emu10k1_ptr_write(emu, A_FXWC1, 0, epcm->capture_cr_val); 798 snd_emu10k1_ptr_write(emu, A_FXWC2, 0, epcm->capture_cr_val2); 799 snd_printdd("cr_val=0x%x, cr_val2=0x%x\n", epcm->capture_cr_val, epcm->capture_cr_val2); 800 } else 801 snd_emu10k1_ptr_write(emu, FXWC, 0, epcm->capture_cr_val); 802 break; 803 default: 804 break; 805 } 806 snd_emu10k1_ptr_write(emu, epcm->capture_bs_reg, 0, epcm->capture_bs_val); 807 epcm->running = 1; 808 epcm->first_ptr = 1; 809 break; 810 case SNDRV_PCM_TRIGGER_STOP: 811 case SNDRV_PCM_TRIGGER_SUSPEND: 812 epcm->running = 0; 813 snd_emu10k1_intr_disable(emu, epcm->capture_inte); 814 outl(epcm->capture_ipr, emu->port + IPR); 815 snd_emu10k1_ptr_write(emu, epcm->capture_bs_reg, 0, 0); 816 switch (epcm->type) { 817 case CAPTURE_AC97ADC: 818 snd_emu10k1_ptr_write(emu, ADCCR, 0, 0); 819 break; 820 case CAPTURE_EFX: 821 if (emu->audigy) { 822 snd_emu10k1_ptr_write(emu, A_FXWC1, 0, 0); 823 snd_emu10k1_ptr_write(emu, A_FXWC2, 0, 0); 824 } else 825 snd_emu10k1_ptr_write(emu, FXWC, 0, 0); 826 break; 827 default: 828 break; 829 } 830 break; 831 default: 832 result = -EINVAL; 833 } 834 spin_unlock(&emu->reg_lock); 835 return result; 836 } 837 838 static snd_pcm_uframes_t snd_emu10k1_playback_pointer(struct snd_pcm_substream *substream) 839 { 840 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 841 struct snd_pcm_runtime *runtime = substream->runtime; 842 struct snd_emu10k1_pcm *epcm = runtime->private_data; 843 unsigned int ptr; 844 845 if (!epcm->running) 846 return 0; 847 ptr = snd_emu10k1_ptr_read(emu, CCCA, epcm->voices[0]->number) & 0x00ffffff; 834 848 #if 0 /* Perex's code */ 835 836 837 849 ptr += runtime->buffer_size; 850 ptr -= epcm->ccca_start_addr; 851 ptr %= runtime->buffer_size; 838 852 #else /* EMU10K1 Open Source code from Creative */ 839 840 841 842 843 844 845 853 if (ptr < epcm->ccca_start_addr) 854 ptr += runtime->buffer_size - epcm->ccca_start_addr; 855 else { 856 ptr -= epcm->ccca_start_addr; 857 if (ptr >= runtime->buffer_size) 858 ptr -= runtime->buffer_size; 859 } 846 860 #endif 847 // printk("ptr = 0x%x, buffer_size = 0x%x, period_size = 0x%x\n", ptr, runtime->buffer_size, runtime->period_size); 848 return ptr; 849 } 850 851 static int snd_emu10k1_efx_playback_trigger(snd_pcm_substream_t * substream, 852 int cmd) 853 { 854 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 855 snd_pcm_runtime_t *runtime = substream->runtime; 856 struct snd_emu10k1_pcm *epcm = runtime->private_data; 857 int i; 858 int result = 0; 859 860 spin_lock(&emu->reg_lock); 861 switch (cmd) { 862 case SNDRV_PCM_TRIGGER_START: 863 // prepare voices 864 for (i = 0; i < NUM_EFX_PLAYBACK; i++) { 865 snd_emu10k1_playback_invalidate_cache(emu, 0, epcm->voices[i]); 866 } 867 snd_emu10k1_playback_invalidate_cache(emu, 1, epcm->extra); 868 869 /* follow thru */ 870 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 871 snd_emu10k1_playback_prepare_voice(emu, epcm->extra, 1, 1, NULL); 872 snd_emu10k1_playback_prepare_voice(emu, epcm->voices[0], 0, 0, 873 &emu->efx_pcm_mixer[0]); 874 for (i = 1; i < NUM_EFX_PLAYBACK; i++) 875 snd_emu10k1_playback_prepare_voice(emu, epcm->voices[i], 0, 0, 876 &emu->efx_pcm_mixer[i]); 877 snd_emu10k1_playback_trigger_voice(emu, epcm->voices[0], 0, 0); 878 snd_emu10k1_playback_trigger_voice(emu, epcm->extra, 1, 1); 879 for (i = 1; i < NUM_EFX_PLAYBACK; i++) 880 snd_emu10k1_playback_trigger_voice(emu, epcm->voices[i], 0, 0); 881 epcm->running = 1; 882 break; 883 case SNDRV_PCM_TRIGGER_STOP: 884 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 885 epcm->running = 0; 886 for (i = 0; i < NUM_EFX_PLAYBACK; i++) { 887 snd_emu10k1_playback_stop_voice(emu, epcm->voices[i]); 888 } 889 snd_emu10k1_playback_stop_voice(emu, epcm->extra); 890 break; 891 default: 892 result = -EINVAL; 893 break; 894 } 895 spin_unlock(&emu->reg_lock); 896 return result; 897 } 898 899 static snd_pcm_uframes_t snd_emu10k1_capture_pointer(snd_pcm_substream_t * substream) 900 { 901 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 902 snd_pcm_runtime_t *runtime = substream->runtime; 903 struct snd_emu10k1_pcm *epcm = runtime->private_data; 904 unsigned int ptr; 905 906 if (!epcm->running) 907 return 0; 908 if (epcm->first_ptr) { 909 udelay(50); // hack, it takes awhile until capture is started 910 epcm->first_ptr = 0; 911 } 912 ptr = snd_emu10k1_ptr_read(emu, epcm->capture_idx_reg, 0) & 0x0000ffff; 913 return bytes_to_frames(runtime, ptr); 861 /* printk("ptr = 0x%x, buffer_size = 0x%x, period_size = 0x%x\n", ptr, runtime->buffer_size, runtime->period_size); */ 862 return ptr; 863 } 864 865 866 static int snd_emu10k1_efx_playback_trigger(struct snd_pcm_substream *substream, 867 int cmd) 868 { 869 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 870 struct snd_pcm_runtime *runtime = substream->runtime; 871 struct snd_emu10k1_pcm *epcm = runtime->private_data; 872 int i; 873 int result = 0; 874 875 spin_lock(&emu->reg_lock); 876 switch (cmd) { 877 case SNDRV_PCM_TRIGGER_START: 878 /* prepare voices */ 879 for (i = 0; i < NUM_EFX_PLAYBACK; i++) { 880 snd_emu10k1_playback_invalidate_cache(emu, 0, epcm->voices[i]); 881 } 882 snd_emu10k1_playback_invalidate_cache(emu, 1, epcm->extra); 883 884 /* follow thru */ 885 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 886 case SNDRV_PCM_TRIGGER_RESUME: 887 snd_emu10k1_playback_prepare_voice(emu, epcm->extra, 1, 1, NULL); 888 snd_emu10k1_playback_prepare_voice(emu, epcm->voices[0], 0, 0, 889 &emu->efx_pcm_mixer[0]); 890 for (i = 1; i < NUM_EFX_PLAYBACK; i++) 891 snd_emu10k1_playback_prepare_voice(emu, epcm->voices[i], 0, 0, 892 &emu->efx_pcm_mixer[i]); 893 snd_emu10k1_playback_trigger_voice(emu, epcm->voices[0], 0, 0); 894 snd_emu10k1_playback_trigger_voice(emu, epcm->extra, 1, 1); 895 for (i = 1; i < NUM_EFX_PLAYBACK; i++) 896 snd_emu10k1_playback_trigger_voice(emu, epcm->voices[i], 0, 0); 897 epcm->running = 1; 898 break; 899 case SNDRV_PCM_TRIGGER_SUSPEND: 900 case SNDRV_PCM_TRIGGER_STOP: 901 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 902 epcm->running = 0; 903 for (i = 0; i < NUM_EFX_PLAYBACK; i++) { 904 snd_emu10k1_playback_stop_voice(emu, epcm->voices[i]); 905 } 906 snd_emu10k1_playback_stop_voice(emu, epcm->extra); 907 break; 908 default: 909 result = -EINVAL; 910 break; 911 } 912 spin_unlock(&emu->reg_lock); 913 return result; 914 } 915 916 917 static snd_pcm_uframes_t snd_emu10k1_capture_pointer(struct snd_pcm_substream *substream) 918 { 919 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 920 struct snd_pcm_runtime *runtime = substream->runtime; 921 struct snd_emu10k1_pcm *epcm = runtime->private_data; 922 unsigned int ptr; 923 924 if (!epcm->running) 925 return 0; 926 if (epcm->first_ptr) { 927 udelay(50); /* hack, it takes awhile until capture is started */ 928 epcm->first_ptr = 0; 929 } 930 ptr = snd_emu10k1_ptr_read(emu, epcm->capture_idx_reg, 0) & 0x0000ffff; 931 return bytes_to_frames(runtime, ptr); 914 932 } 915 933 … … 918 936 */ 919 937 920 #if 0 921 int snd_emu10k1_playback_ioctl(snd_pcm_substream_t *substream, unsigned int cmd, void *arg) 922 { 923 switch(cmd) { 924 case SNDRV_PCM_IOCTL1_SETVOLUME: 925 { 926 struct snd_emu10k1_pcm_mixer *mix; 927 snd_pcm_volume_t *volume = (snd_pcm_volume_t *)arg; 928 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 929 snd_ctl_elem_value_t *ucontrol; 930 snd_ctl_elem_info_t *uinfo; 931 void *iwishihadmorestack; 932 int range; 933 934 935 iwishihadmorestack = kmalloc(sizeof(snd_ctl_elem_value_t) + sizeof(snd_ctl_elem_info_t), GFP_KERNEL); 936 if(iwishihadmorestack == NULL) { 937 kfree(iwishihadmorestack); 938 return -ENOMEM; 939 } 940 ucontrol = (snd_ctl_elem_value_t *)iwishihadmorestack; 941 uinfo = (snd_ctl_elem_info_t *)(ucontrol + 1); 942 943 mix = &emu->pcm_mixer[substream->number]; 944 mix->ctl_attn->info(mix->ctl_attn, uinfo); 945 range = uinfo->value.integer.max - uinfo->value.integer.min; 946 947 if (mix->epcm->voices[0] && mix->epcm->voices[1]) { 948 ucontrol->value.integer.value[1] = (volume->volume[SNDRV_PCM_VOL_FRONT_LEFT] * range)/SNDRV_PCM_VOL_MAX; 949 ucontrol->value.integer.value[2] = (volume->volume[SNDRV_PCM_VOL_FRONT_RIGHT] * range)/SNDRV_PCM_VOL_MAX; 950 } 951 else 952 if (mix->epcm->voices[0]) 953 ucontrol->value.integer.value[0] = (volume->volume[SNDRV_PCM_VOL_FRONT_LEFT] * range)/SNDRV_PCM_VOL_MAX; 954 955 mix->ctl_attn->put(mix->ctl_attn, ucontrol); 956 kfree(iwishihadmorestack); 957 return 0; 958 } 959 case SNDRV_PCM_IOCTL1_GETVOLUME: 960 { 961 struct snd_emu10k1_pcm_mixer *mix; 962 snd_pcm_volume_t *volume = (snd_pcm_volume_t *)arg; 963 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 964 int range; 965 snd_ctl_elem_value_t *ucontrol; 966 snd_ctl_elem_info_t *uinfo; 967 void *iwishihadmorestack; 968 969 iwishihadmorestack = kmalloc(sizeof(snd_ctl_elem_value_t) + sizeof(snd_ctl_elem_info_t), GFP_KERNEL); 970 if(iwishihadmorestack == NULL) { 971 return -ENOMEM; 972 } 973 ucontrol = (snd_ctl_elem_value_t *)iwishihadmorestack; 974 uinfo = (snd_ctl_elem_info_t *)(ucontrol + 1); 975 976 mix = &emu->pcm_mixer[substream->number]; 977 mix->ctl_attn->info(mix->ctl_attn, uinfo); 978 range = uinfo->value.integer.max - uinfo->value.integer.min; 979 if(range == 0) { 980 kfree(iwishihadmorestack); 981 return -EPERM; 982 } 983 mix->ctl_attn->get(mix->ctl_attn, ucontrol); 984 985 if (mix->epcm->voices[0] && mix->epcm->voices[1]) { 986 volume->nrchannels = 2; 987 volume->volume[SNDRV_PCM_VOL_FRONT_LEFT] = (ucontrol->value.integer.value[1] * SNDRV_PCM_VOL_MAX) / range; 988 volume->volume[SNDRV_PCM_VOL_FRONT_RIGHT] = (ucontrol->value.integer.value[2] * SNDRV_PCM_VOL_MAX) / range; 989 volume->volume[SNDRV_PCM_VOL_REAR_LEFT] = volume->volume[SNDRV_PCM_VOL_FRONT_LEFT]; 990 volume->volume[SNDRV_PCM_VOL_REAR_RIGHT] = volume->volume[SNDRV_PCM_VOL_FRONT_RIGHT]; 991 } 992 else 993 if (mix->epcm->voices[0]){ 994 volume->nrchannels = 1; 995 volume->volume[SNDRV_PCM_VOL_FRONT_LEFT] = (ucontrol->value.integer.value[0] * SNDRV_PCM_VOL_MAX) / range; 996 volume->volume[SNDRV_PCM_VOL_FRONT_RIGHT] = volume->volume[SNDRV_PCM_VOL_FRONT_LEFT]; 997 volume->volume[SNDRV_PCM_VOL_REAR_LEFT] = volume->volume[SNDRV_PCM_VOL_FRONT_LEFT]; 998 volume->volume[SNDRV_PCM_VOL_REAR_RIGHT] = volume->volume[SNDRV_PCM_VOL_FRONT_RIGHT]; 999 } 1000 kfree(iwishihadmorestack); 1001 return 0; 1002 } 1003 1004 } 1005 return snd_pcm_lib_ioctl(substream, cmd, arg); 1006 } 1007 #endif 1008 1009 static snd_pcm_hardware_t snd_emu10k1_playback = 1010 { 1011 /* info: */ (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 1012 SNDRV_PCM_INFO_BLOCK_TRANSFER | 1013 SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_PAUSE), 1014 /* formats: */ SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE, 1015 SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_96000, 1016 /* rate_min: */ 4000, 1017 /* rate_max: */ 96000, 1018 /* channels_min: */ 1, 1019 /* channels_max: */ 2, 1020 /* buffer_bytes_max: */ (128*1024), 1021 /* period_bytes_min: */ 64, 1022 /* period_bytes_max: */ (128*1024), 1023 /* periods_min: */ 1, 1024 /* periods_max: */ 1024, 1025 /* fifo_size: */ 0, 938 static struct snd_pcm_hardware snd_emu10k1_playback = 939 { 940 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 941 SNDRV_PCM_INFO_BLOCK_TRANSFER | 942 SNDRV_PCM_INFO_RESUME | 943 SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_PAUSE), 944 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE, 945 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_96000, 946 .rate_min = 4000, 947 .rate_max = 96000, 948 .channels_min = 1, 949 .channels_max = 2, 950 .buffer_bytes_max = (128*1024), 951 .period_bytes_min = 64, 952 .period_bytes_max = (128*1024), 953 .periods_min = 1, 954 .periods_max = 1024, 955 .fifo_size = 0, 1026 956 }; 1027 957 … … 1030 960 */ 1031 961 1032 static snd_pcm_hardware_t snd_emu10k1_capture = 1033 { 1034 /* info: */ (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 1035 SNDRV_PCM_INFO_BLOCK_TRANSFER | 1036 SNDRV_PCM_INFO_MMAP_VALID), 1037 /* formats: */ SNDRV_PCM_FMTBIT_S16_LE, 1038 /* rates: */ SNDRV_PCM_RATE_8000_48000, 1039 /* rate_min: */ 8000, 1040 /* rate_max: */ 48000, 1041 /* channels_min: */ 1, 1042 /* channels_max: */ 2, 1043 /* buffer_bytes_max: */ (64*1024), 1044 /* period_bytes_min: */ 384, 1045 /* period_bytes_max: */ (64*1024), 1046 /* periods_min: */ 2, 1047 /* periods_max: */ 2, 1048 /* fifo_size: */ 0, 962 static struct snd_pcm_hardware snd_emu10k1_capture = 963 { 964 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 965 SNDRV_PCM_INFO_BLOCK_TRANSFER | 966 SNDRV_PCM_INFO_RESUME | 967 SNDRV_PCM_INFO_MMAP_VALID), 968 .formats = SNDRV_PCM_FMTBIT_S16_LE, 969 .rates = SNDRV_PCM_RATE_8000_48000, 970 .rate_min = 8000, 971 .rate_max = 48000, 972 .channels_min = 1, 973 .channels_max = 2, 974 .buffer_bytes_max = (64*1024), 975 .period_bytes_min = 384, 976 .period_bytes_max = (64*1024), 977 .periods_min = 2, 978 .periods_max = 2, 979 .fifo_size = 0, 980 }; 981 982 static struct snd_pcm_hardware snd_emu10k1_capture_efx = 983 { 984 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 985 SNDRV_PCM_INFO_BLOCK_TRANSFER | 986 SNDRV_PCM_INFO_RESUME | 987 SNDRV_PCM_INFO_MMAP_VALID), 988 .formats = SNDRV_PCM_FMTBIT_S16_LE, 989 .rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | 990 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | 991 SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000, 992 .rate_min = 44100, 993 .rate_max = 192000, 994 .channels_min = 8, 995 .channels_max = 8, 996 .buffer_bytes_max = (64*1024), 997 .period_bytes_min = 384, 998 .period_bytes_max = (64*1024), 999 .periods_min = 2, 1000 .periods_max = 2, 1001 .fifo_size = 0, 1049 1002 }; 1050 1003 … … 1053 1006 */ 1054 1007 1055 static void snd_emu10k1_pcm_mixer_notify1(struct snd_emu10k1 *emu, s nd_kcontrol_t*kctl, int idx, int activate)1056 { 1057 snd_ctl_elem_id_tid;1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1008 static void snd_emu10k1_pcm_mixer_notify1(struct snd_emu10k1 *emu, struct snd_kcontrol *kctl, int idx, int activate) 1009 { 1010 struct snd_ctl_elem_id id; 1011 1012 if (! kctl) 1013 return; 1014 if (activate) 1015 kctl->vd[idx].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; 1016 else 1017 kctl->vd[idx].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE; 1018 snd_ctl_notify(emu->card, SNDRV_CTL_EVENT_MASK_VALUE | 1019 SNDRV_CTL_EVENT_MASK_INFO, 1020 snd_ctl_build_ioff(&id, kctl, idx)); 1068 1021 } 1069 1022 1070 1023 static void snd_emu10k1_pcm_mixer_notify(struct snd_emu10k1 *emu, int idx, int activate) 1071 1024 { 1072 1073 1074 1025 snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_send_routing, idx, activate); 1026 snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_send_volume, idx, activate); 1027 snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_attn, idx, activate); 1075 1028 } 1076 1029 1077 1030 static void snd_emu10k1_pcm_efx_mixer_notify(struct snd_emu10k1 *emu, int idx, int activate) 1078 1031 { 1079 snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_efx_send_routing, idx, activate); 1080 snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_efx_send_volume, idx, activate); 1081 snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_efx_attn, idx, activate); 1082 } 1083 1084 static void snd_emu10k1_pcm_free_substream(snd_pcm_runtime_t *runtime) 1085 { 1086 struct snd_emu10k1_pcm *epcm = runtime->private_data; 1087 if (epcm) 1088 kfree(epcm); 1089 } 1090 1091 static int snd_emu10k1_efx_playback_close(snd_pcm_substream_t * substream) 1092 { 1093 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 1094 struct snd_emu10k1_pcm_mixer *mix; 1095 int i; 1096 1097 for (i=0; i < NUM_EFX_PLAYBACK; i++) { 1098 mix = &emu->efx_pcm_mixer[i]; 1099 mix->epcm = NULL; 1100 snd_emu10k1_pcm_efx_mixer_notify(emu, i, 0); 1101 } 1102 return 0; 1103 } 1104 1105 static int snd_emu10k1_efx_playback_open(snd_pcm_substream_t * substream) 1106 { 1107 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 1108 struct snd_emu10k1_pcm *epcm; 1109 struct snd_emu10k1_pcm_mixer *mix; 1110 snd_pcm_runtime_t *runtime = substream->runtime; 1111 int i; 1112 1113 epcm = (struct snd_emu10k1_pcm *)kzalloc(sizeof(*epcm), GFP_KERNEL); 1114 if (epcm == NULL) 1115 return -ENOMEM; 1116 epcm->emu = emu; 1117 epcm->type = PLAYBACK_EFX; 1118 epcm->substream = substream; 1119 1120 emu->pcm_playback_efx_substream = substream; 1121 1122 runtime->private_data = epcm; 1123 runtime->private_free = snd_emu10k1_pcm_free_substream; 1124 runtime->hw = snd_emu10k1_efx_playback; 1125 1126 for (i=0; i < NUM_EFX_PLAYBACK; i++) { 1127 mix = &emu->efx_pcm_mixer[i]; 1128 mix->send_routing[0][0] = i; 1129 memset(&mix->send_volume, 0, sizeof(mix->send_volume)); 1130 mix->send_volume[0][0] = 255; 1131 mix->attn[0] = 0xffff; 1132 mix->epcm = epcm; 1133 snd_emu10k1_pcm_efx_mixer_notify(emu, i, 1); 1134 } 1135 return 0; 1136 } 1137 1138 static int snd_emu10k1_playback_open(snd_pcm_substream_t * substream) 1139 { 1140 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 1141 struct snd_emu10k1_pcm *epcm; 1142 struct snd_emu10k1_pcm_mixer *mix; 1143 snd_pcm_runtime_t *runtime = substream->runtime; 1144 int i, err; 1145 1146 epcm = (struct snd_emu10k1_pcm *)kzalloc(sizeof(*epcm), GFP_KERNEL); 1147 if (epcm == NULL) 1148 return -ENOMEM; 1149 epcm->emu = emu; 1150 epcm->type = PLAYBACK_EMUVOICE; 1151 epcm->substream = substream; 1152 runtime->private_data = epcm; 1153 runtime->private_free = snd_emu10k1_pcm_free_substream; 1154 runtime->hw = snd_emu10k1_playback; 1155 if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0) { 1156 kfree(epcm); 1157 return err; 1158 } 1159 if ((err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 256, UINT_MAX)) < 0) { 1160 kfree(epcm); 1161 return err; 1162 } 1163 mix = &emu->pcm_mixer[substream->number]; 1164 for (i = 0; i < 4; i++) 1165 mix->send_routing[0][i] = mix->send_routing[1][i] = mix->send_routing[2][i] = i; 1166 memset(&mix->send_volume, 0, sizeof(mix->send_volume)); 1167 mix->send_volume[0][0] = mix->send_volume[0][1] = 1168 mix->send_volume[1][0] = mix->send_volume[2][1] = 255; 1169 mix->attn[0] = mix->attn[1] = mix->attn[2] = 0xffff; 1170 mix->epcm = epcm; 1171 snd_emu10k1_pcm_mixer_notify(emu, substream->number, 1); 1172 return 0; 1173 } 1174 1175 static int snd_emu10k1_playback_close(snd_pcm_substream_t * substream) 1176 { 1177 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 1178 struct snd_emu10k1_pcm_mixer *mix = &emu->pcm_mixer[substream->number]; 1179 1180 mix->epcm = NULL; 1181 snd_emu10k1_pcm_mixer_notify(emu, substream->number, 0); 1182 return 0; 1183 } 1184 1185 static int snd_emu10k1_capture_open(snd_pcm_substream_t * substream) 1186 { 1187 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 1188 snd_pcm_runtime_t *runtime = substream->runtime; 1189 struct snd_emu10k1_pcm *epcm; 1190 1191 epcm = (struct snd_emu10k1_pcm *)kzalloc(sizeof(*epcm), GFP_KERNEL); 1192 if (epcm == NULL) 1193 return -ENOMEM; 1194 epcm->emu = emu; 1195 epcm->type = CAPTURE_AC97ADC; 1196 epcm->substream = substream; 1197 epcm->capture_ipr = IPR_ADCBUFFULL|IPR_ADCBUFHALFFULL; 1198 epcm->capture_inte = INTE_ADCBUFENABLE; 1199 epcm->capture_ba_reg = ADCBA; 1200 epcm->capture_bs_reg = ADCBS; 1201 epcm->capture_idx_reg = emu->audigy ? A_ADCIDX : ADCIDX; 1202 runtime->private_data = epcm; 1203 runtime->private_free = snd_emu10k1_pcm_free_substream; 1204 runtime->hw = snd_emu10k1_capture; 1205 emu->capture_interrupt = snd_emu10k1_pcm_ac97adc_interrupt; 1206 emu->pcm_capture_substream = substream; 1207 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, &hw_constraints_capture_period_sizes); 1208 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_capture_rates); 1209 return 0; 1210 } 1211 1212 static int snd_emu10k1_capture_close(snd_pcm_substream_t * substream) 1213 { 1214 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 1215 1216 emu->capture_interrupt = NULL; 1217 emu->pcm_capture_substream = NULL; 1218 return 0; 1219 } 1220 1221 static int snd_emu10k1_capture_mic_open(snd_pcm_substream_t * substream) 1222 { 1223 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 1224 struct snd_emu10k1_pcm *epcm; 1225 snd_pcm_runtime_t *runtime = substream->runtime; 1226 1227 epcm = (struct snd_emu10k1_pcm *)kzalloc(sizeof(*epcm), GFP_KERNEL); 1228 if (epcm == NULL) 1229 return -ENOMEM; 1230 epcm->emu = emu; 1231 epcm->type = CAPTURE_AC97MIC; 1232 epcm->substream = substream; 1233 epcm->capture_ipr = IPR_MICBUFFULL|IPR_MICBUFHALFFULL; 1234 epcm->capture_inte = INTE_MICBUFENABLE; 1235 epcm->capture_ba_reg = MICBA; 1236 epcm->capture_bs_reg = MICBS; 1237 epcm->capture_idx_reg = emu->audigy ? A_MICIDX : MICIDX; 1238 substream->runtime->private_data = epcm; 1239 substream->runtime->private_free = snd_emu10k1_pcm_free_substream; 1240 runtime->hw = snd_emu10k1_capture; 1241 runtime->hw.rates = SNDRV_PCM_RATE_8000; 1242 runtime->hw.rate_min = runtime->hw.rate_max = 8000; 1243 runtime->hw.channels_min = 1; 1244 emu->capture_mic_interrupt = snd_emu10k1_pcm_ac97mic_interrupt; 1245 emu->pcm_capture_mic_substream = substream; 1246 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, &hw_constraints_capture_period_sizes); 1247 return 0; 1248 } 1249 1250 static int snd_emu10k1_capture_mic_close(snd_pcm_substream_t * substream) 1251 { 1252 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 1253 1254 emu->capture_interrupt = NULL; 1255 emu->pcm_capture_mic_substream = NULL; 1256 return 0; 1257 } 1258 1259 static int snd_emu10k1_capture_efx_open(snd_pcm_substream_t * substream) 1260 { 1261 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 1262 struct snd_emu10k1_pcm *epcm; 1263 snd_pcm_runtime_t *runtime = substream->runtime; 1264 int nefx = emu->audigy ? 64 : 32; 1265 int idx; 1266 1267 epcm = (struct snd_emu10k1_pcm *)kzalloc(sizeof(*epcm), GFP_KERNEL); 1268 if (epcm == NULL) 1269 return -ENOMEM; 1270 epcm->emu = emu; 1271 epcm->type = CAPTURE_EFX; 1272 epcm->substream = substream; 1273 epcm->capture_ipr = IPR_EFXBUFFULL|IPR_EFXBUFHALFFULL; 1274 epcm->capture_inte = INTE_EFXBUFENABLE; 1275 epcm->capture_ba_reg = FXBA; 1276 epcm->capture_bs_reg = FXBS; 1277 epcm->capture_idx_reg = FXIDX; 1278 substream->runtime->private_data = epcm; 1279 substream->runtime->private_free = snd_emu10k1_pcm_free_substream; 1280 runtime->hw = snd_emu10k1_capture; 1281 runtime->hw.rates = SNDRV_PCM_RATE_48000; 1282 runtime->hw.rate_min = runtime->hw.rate_max = 48000; 1283 spin_lock_irq(&emu->reg_lock); 1284 runtime->hw.channels_min = runtime->hw.channels_max = 0; 1285 for (idx = 0; idx < nefx; idx++) { 1286 if (emu->efx_voices_mask[idx/32] & (1 << (idx%32))) { 1287 runtime->hw.channels_min++; 1288 runtime->hw.channels_max++; 1289 } 1290 } 1291 epcm->capture_cr_val = emu->efx_voices_mask[0]; 1292 epcm->capture_cr_val2 = emu->efx_voices_mask[1]; 1293 spin_unlock_irq(&emu->reg_lock); 1294 emu->capture_efx_interrupt = snd_emu10k1_pcm_efx_interrupt; 1295 emu->pcm_capture_efx_substream = substream; 1296 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, &hw_constraints_capture_period_sizes); 1297 return 0; 1298 } 1299 1300 static int snd_emu10k1_capture_efx_close(snd_pcm_substream_t * substream) 1301 { 1302 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 1303 1304 emu->capture_interrupt = NULL; 1305 emu->pcm_capture_efx_substream = NULL; 1306 return 0; 1307 } 1308 1309 static snd_pcm_ops_t snd_emu10k1_playback_ops = { 1310 snd_emu10k1_playback_open, 1311 snd_emu10k1_playback_close, 1312 snd_pcm_lib_ioctl, 1313 snd_emu10k1_playback_hw_params, 1314 snd_emu10k1_playback_hw_free, 1315 snd_emu10k1_playback_prepare, 1316 snd_emu10k1_playback_trigger, 1317 snd_emu10k1_playback_pointer,0,0, 1318 snd_pcm_sgbuf_ops_page,0 1032 snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_efx_send_routing, idx, activate); 1033 snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_efx_send_volume, idx, activate); 1034 snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_efx_attn, idx, activate); 1035 } 1036 1037 static void snd_emu10k1_pcm_free_substream(struct snd_pcm_runtime *runtime) 1038 { 1039 kfree(runtime->private_data); 1040 } 1041 1042 static int snd_emu10k1_efx_playback_close(struct snd_pcm_substream *substream) 1043 { 1044 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 1045 struct snd_emu10k1_pcm_mixer *mix; 1046 int i; 1047 1048 for (i = 0; i < NUM_EFX_PLAYBACK; i++) { 1049 mix = &emu->efx_pcm_mixer[i]; 1050 mix->epcm = NULL; 1051 snd_emu10k1_pcm_efx_mixer_notify(emu, i, 0); 1052 } 1053 return 0; 1054 } 1055 1056 static int snd_emu10k1_efx_playback_open(struct snd_pcm_substream *substream) 1057 { 1058 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 1059 struct snd_emu10k1_pcm *epcm; 1060 struct snd_emu10k1_pcm_mixer *mix; 1061 struct snd_pcm_runtime *runtime = substream->runtime; 1062 int i; 1063 1064 epcm = kzalloc(sizeof(*epcm), GFP_KERNEL); 1065 if (epcm == NULL) 1066 return -ENOMEM; 1067 epcm->emu = emu; 1068 epcm->type = PLAYBACK_EFX; 1069 epcm->substream = substream; 1070 1071 emu->pcm_playback_efx_substream = substream; 1072 1073 runtime->private_data = epcm; 1074 runtime->private_free = snd_emu10k1_pcm_free_substream; 1075 runtime->hw = snd_emu10k1_efx_playback; 1076 1077 for (i = 0; i < NUM_EFX_PLAYBACK; i++) { 1078 mix = &emu->efx_pcm_mixer[i]; 1079 mix->send_routing[0][0] = i; 1080 memset(&mix->send_volume, 0, sizeof(mix->send_volume)); 1081 mix->send_volume[0][0] = 255; 1082 mix->attn[0] = 0xffff; 1083 mix->epcm = epcm; 1084 snd_emu10k1_pcm_efx_mixer_notify(emu, i, 1); 1085 } 1086 return 0; 1087 } 1088 1089 static int snd_emu10k1_playback_open(struct snd_pcm_substream *substream) 1090 { 1091 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 1092 struct snd_emu10k1_pcm *epcm; 1093 struct snd_emu10k1_pcm_mixer *mix; 1094 struct snd_pcm_runtime *runtime = substream->runtime; 1095 int i, err; 1096 1097 epcm = kzalloc(sizeof(*epcm), GFP_KERNEL); 1098 if (epcm == NULL) 1099 return -ENOMEM; 1100 epcm->emu = emu; 1101 epcm->type = PLAYBACK_EMUVOICE; 1102 epcm->substream = substream; 1103 runtime->private_data = epcm; 1104 runtime->private_free = snd_emu10k1_pcm_free_substream; 1105 runtime->hw = snd_emu10k1_playback; 1106 if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0) { 1107 kfree(epcm); 1108 return err; 1109 } 1110 if ((err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 256, UINT_MAX)) < 0) { 1111 kfree(epcm); 1112 return err; 1113 } 1114 mix = &emu->pcm_mixer[substream->number]; 1115 for (i = 0; i < 4; i++) 1116 mix->send_routing[0][i] = mix->send_routing[1][i] = mix->send_routing[2][i] = i; 1117 memset(&mix->send_volume, 0, sizeof(mix->send_volume)); 1118 mix->send_volume[0][0] = mix->send_volume[0][1] = 1119 mix->send_volume[1][0] = mix->send_volume[2][1] = 255; 1120 mix->attn[0] = mix->attn[1] = mix->attn[2] = 0xffff; 1121 mix->epcm = epcm; 1122 snd_emu10k1_pcm_mixer_notify(emu, substream->number, 1); 1123 return 0; 1124 } 1125 1126 static int snd_emu10k1_playback_close(struct snd_pcm_substream *substream) 1127 { 1128 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 1129 struct snd_emu10k1_pcm_mixer *mix = &emu->pcm_mixer[substream->number]; 1130 1131 mix->epcm = NULL; 1132 snd_emu10k1_pcm_mixer_notify(emu, substream->number, 0); 1133 return 0; 1134 } 1135 1136 static int snd_emu10k1_capture_open(struct snd_pcm_substream *substream) 1137 { 1138 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 1139 struct snd_pcm_runtime *runtime = substream->runtime; 1140 struct snd_emu10k1_pcm *epcm; 1141 1142 epcm = kzalloc(sizeof(*epcm), GFP_KERNEL); 1143 if (epcm == NULL) 1144 return -ENOMEM; 1145 epcm->emu = emu; 1146 epcm->type = CAPTURE_AC97ADC; 1147 epcm->substream = substream; 1148 epcm->capture_ipr = IPR_ADCBUFFULL|IPR_ADCBUFHALFFULL; 1149 epcm->capture_inte = INTE_ADCBUFENABLE; 1150 epcm->capture_ba_reg = ADCBA; 1151 epcm->capture_bs_reg = ADCBS; 1152 epcm->capture_idx_reg = emu->audigy ? A_ADCIDX : ADCIDX; 1153 runtime->private_data = epcm; 1154 runtime->private_free = snd_emu10k1_pcm_free_substream; 1155 runtime->hw = snd_emu10k1_capture; 1156 emu->capture_interrupt = snd_emu10k1_pcm_ac97adc_interrupt; 1157 emu->pcm_capture_substream = substream; 1158 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, &hw_constraints_capture_period_sizes); 1159 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_capture_rates); 1160 return 0; 1161 } 1162 1163 static int snd_emu10k1_capture_close(struct snd_pcm_substream *substream) 1164 { 1165 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 1166 1167 emu->capture_interrupt = NULL; 1168 emu->pcm_capture_substream = NULL; 1169 return 0; 1170 } 1171 1172 static int snd_emu10k1_capture_mic_open(struct snd_pcm_substream *substream) 1173 { 1174 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 1175 struct snd_emu10k1_pcm *epcm; 1176 struct snd_pcm_runtime *runtime = substream->runtime; 1177 1178 epcm = kzalloc(sizeof(*epcm), GFP_KERNEL); 1179 if (epcm == NULL) 1180 return -ENOMEM; 1181 epcm->emu = emu; 1182 epcm->type = CAPTURE_AC97MIC; 1183 epcm->substream = substream; 1184 epcm->capture_ipr = IPR_MICBUFFULL|IPR_MICBUFHALFFULL; 1185 epcm->capture_inte = INTE_MICBUFENABLE; 1186 epcm->capture_ba_reg = MICBA; 1187 epcm->capture_bs_reg = MICBS; 1188 epcm->capture_idx_reg = emu->audigy ? A_MICIDX : MICIDX; 1189 substream->runtime->private_data = epcm; 1190 substream->runtime->private_free = snd_emu10k1_pcm_free_substream; 1191 runtime->hw = snd_emu10k1_capture; 1192 runtime->hw.rates = SNDRV_PCM_RATE_8000; 1193 runtime->hw.rate_min = runtime->hw.rate_max = 8000; 1194 runtime->hw.channels_min = 1; 1195 emu->capture_mic_interrupt = snd_emu10k1_pcm_ac97mic_interrupt; 1196 emu->pcm_capture_mic_substream = substream; 1197 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, &hw_constraints_capture_period_sizes); 1198 return 0; 1199 } 1200 1201 static int snd_emu10k1_capture_mic_close(struct snd_pcm_substream *substream) 1202 { 1203 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 1204 1205 emu->capture_interrupt = NULL; 1206 emu->pcm_capture_mic_substream = NULL; 1207 return 0; 1208 } 1209 1210 static int snd_emu10k1_capture_efx_open(struct snd_pcm_substream *substream) 1211 { 1212 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 1213 struct snd_emu10k1_pcm *epcm; 1214 struct snd_pcm_runtime *runtime = substream->runtime; 1215 int nefx = emu->audigy ? 64 : 32; 1216 int idx; 1217 1218 epcm = kzalloc(sizeof(*epcm), GFP_KERNEL); 1219 if (epcm == NULL) 1220 return -ENOMEM; 1221 epcm->emu = emu; 1222 epcm->type = CAPTURE_EFX; 1223 epcm->substream = substream; 1224 epcm->capture_ipr = IPR_EFXBUFFULL|IPR_EFXBUFHALFFULL; 1225 epcm->capture_inte = INTE_EFXBUFENABLE; 1226 epcm->capture_ba_reg = FXBA; 1227 epcm->capture_bs_reg = FXBS; 1228 epcm->capture_idx_reg = FXIDX; 1229 substream->runtime->private_data = epcm; 1230 substream->runtime->private_free = snd_emu10k1_pcm_free_substream; 1231 runtime->hw = snd_emu10k1_capture_efx; 1232 runtime->hw.rates = SNDRV_PCM_RATE_48000; 1233 runtime->hw.rate_min = runtime->hw.rate_max = 48000; 1234 spin_lock_irq(&emu->reg_lock); 1235 if (emu->card_capabilities->emu1010) { 1236 /* TODO 1237 * SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE 1238 * SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | 1239 * SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | 1240 * SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000 1241 * rate_min = 44100, 1242 * rate_max = 192000, 1243 * channels_min = 8, 1244 * channels_max = 8, 1245 * Need to add mixer control to fix sample rate 1246 * 1247 * There are 16 mono channels of 16bits each. 1248 * 24bit Audio uses 2x channels over 16bit 1249 * 96kHz uses 2x channels over 48kHz 1250 * 192kHz uses 4x channels over 48kHz 1251 * So, for 48kHz 24bit, one has 8 channels 1252 * for 96kHz 24bit, one has 4 channels 1253 * for 192kHz 24bit, one has 2 channels 1254 */ 1255 #if 1 1256 switch (emu->emu1010.internal_clock) { 1257 case 0: 1258 /* For 44.1kHz */ 1259 runtime->hw.rates = SNDRV_PCM_RATE_44100; 1260 runtime->hw.rate_min = runtime->hw.rate_max = 44100; 1261 runtime->hw.channels_min = runtime->hw.channels_max = 8; 1262 break; 1263 case 1: 1264 /* For 48kHz */ 1265 runtime->hw.rates = SNDRV_PCM_RATE_48000; 1266 runtime->hw.rate_min = runtime->hw.rate_max = 48000; 1267 runtime->hw.channels_min = runtime->hw.channels_max = 8; 1268 break; 1269 }; 1270 #endif 1271 #if 0 1272 /* For 96kHz */ 1273 runtime->hw.rates = SNDRV_PCM_RATE_96000; 1274 runtime->hw.rate_min = runtime->hw.rate_max = 96000; 1275 runtime->hw.channels_min = runtime->hw.channels_max = 4; 1276 #endif 1277 #if 0 1278 /* For 192kHz */ 1279 runtime->hw.rates = SNDRV_PCM_RATE_192000; 1280 runtime->hw.rate_min = runtime->hw.rate_max = 192000; 1281 runtime->hw.channels_min = runtime->hw.channels_max = 2; 1282 #endif 1283 runtime->hw.formats = SNDRV_PCM_FMTBIT_S32_LE; 1284 /* efx_voices_mask[0] is expected to be zero 1285 * efx_voices_mask[1] is expected to have 16bits set 1286 */ 1287 } else { 1288 runtime->hw.channels_min = runtime->hw.channels_max = 0; 1289 for (idx = 0; idx < nefx; idx++) { 1290 if (emu->efx_voices_mask[idx/32] & (1 << (idx%32))) { 1291 runtime->hw.channels_min++; 1292 runtime->hw.channels_max++; 1293 } 1294 } 1295 } 1296 epcm->capture_cr_val = emu->efx_voices_mask[0]; 1297 epcm->capture_cr_val2 = emu->efx_voices_mask[1]; 1298 spin_unlock_irq(&emu->reg_lock); 1299 emu->capture_efx_interrupt = snd_emu10k1_pcm_efx_interrupt; 1300 emu->pcm_capture_efx_substream = substream; 1301 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, &hw_constraints_capture_period_sizes); 1302 return 0; 1303 } 1304 1305 static int snd_emu10k1_capture_efx_close(struct snd_pcm_substream *substream) 1306 { 1307 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 1308 1309 emu->capture_interrupt = NULL; 1310 emu->pcm_capture_efx_substream = NULL; 1311 return 0; 1312 } 1313 1314 static struct snd_pcm_ops snd_emu10k1_playback_ops = { 1315 .open = snd_emu10k1_playback_open, 1316 .close = snd_emu10k1_playback_close, 1317 .ioctl = snd_pcm_lib_ioctl, 1318 .hw_params = snd_emu10k1_playback_hw_params, 1319 .hw_free = snd_emu10k1_playback_hw_free, 1320 .prepare = snd_emu10k1_playback_prepare, 1321 .trigger = snd_emu10k1_playback_trigger, 1322 .pointer = snd_emu10k1_playback_pointer, 1323 .page = snd_pcm_sgbuf_ops_page, 1319 1324 }; 1320 1325 1321 static s nd_pcm_ops_tsnd_emu10k1_capture_ops = {1322 1323 1324 1325 1326 1327 1328 1329 snd_emu10k1_capture_pointer,0,0,0,0 1326 static struct snd_pcm_ops snd_emu10k1_capture_ops = { 1327 .open = snd_emu10k1_capture_open, 1328 .close = snd_emu10k1_capture_close, 1329 .ioctl = snd_pcm_lib_ioctl, 1330 .hw_params = snd_emu10k1_capture_hw_params, 1331 .hw_free = snd_emu10k1_capture_hw_free, 1332 .prepare = snd_emu10k1_capture_prepare, 1333 .trigger = snd_emu10k1_capture_trigger, 1334 .pointer = snd_emu10k1_capture_pointer, 1330 1335 }; 1331 1336 1332 1337 /* EFX playback */ 1333 static snd_pcm_ops_t snd_emu10k1_efx_playback_ops = { 1334 /*.open = */ snd_emu10k1_efx_playback_open, 1335 /*.close = */ snd_emu10k1_efx_playback_close, 1336 /*.ioctl = */ snd_pcm_lib_ioctl, 1337 /*.hw_params = */ snd_emu10k1_playback_hw_params, 1338 /*.hw_free = */ snd_emu10k1_efx_playback_hw_free, 1339 /*.prepare = */ snd_emu10k1_efx_playback_prepare, 1340 /*.trigger = */ snd_emu10k1_efx_playback_trigger, 1341 /*.pointer = */ snd_emu10k1_efx_playback_pointer, 1342 0,0, 1343 /*.page = */ snd_pcm_sgbuf_ops_page, 1344 0 1338 static struct snd_pcm_ops snd_emu10k1_efx_playback_ops = { 1339 .open = snd_emu10k1_efx_playback_open, 1340 .close = snd_emu10k1_efx_playback_close, 1341 .ioctl = snd_pcm_lib_ioctl, 1342 .hw_params = snd_emu10k1_playback_hw_params, 1343 .hw_free = snd_emu10k1_efx_playback_hw_free, 1344 .prepare = snd_emu10k1_efx_playback_prepare, 1345 .trigger = snd_emu10k1_efx_playback_trigger, 1346 .pointer = snd_emu10k1_efx_playback_pointer, 1347 .page = snd_pcm_sgbuf_ops_page, 1345 1348 }; 1346 1349 1347 static void snd_emu10k1_pcm_free(snd_pcm_t *pcm) 1348 { 1349 struct snd_emu10k1 *emu = pcm->private_data; 1350 emu->pcm = NULL; 1351 snd_pcm_lib_preallocate_free_for_all(pcm); 1352 } 1353 1354 int __devinit snd_emu10k1_pcm(struct snd_emu10k1 * emu, int device, snd_pcm_t ** rpcm) 1355 { 1356 snd_pcm_t *pcm; 1357 snd_pcm_substream_t *substream; 1358 int err; 1359 1360 if (rpcm) 1361 *rpcm = NULL; 1362 1363 if ((err = snd_pcm_new(emu->card, "emu10k1", device, 32, 1, &pcm)) < 0) 1364 return err; 1365 1366 pcm->private_data = emu; 1367 pcm->private_free = snd_emu10k1_pcm_free; 1368 1369 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_emu10k1_playback_ops); 1370 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_emu10k1_capture_ops); 1371 1372 pcm->info_flags = 0; 1373 pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX; 1374 strcpy(pcm->name, "EMU10K1"); 1375 emu->pcm = pcm; 1376 1377 for (substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; substream; substream = substream->next) 1378 if ((err = snd_pcm_lib_preallocate_pages(substream, SNDRV_DMA_TYPE_DEV_SG, snd_dma_pci_data(emu->pci), 64*1024, 64*1024)) < 0) 1379 return err; 1380 1381 for (substream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream; substream; substream = substream->next) 1382 snd_pcm_lib_preallocate_pages(substream, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(emu->pci), 64*1024, 64*1024); 1383 1384 if (rpcm) 1385 *rpcm = pcm; 1386 1387 return 0; 1388 } 1389 1390 int __devinit snd_emu10k1_pcm_multi(struct snd_emu10k1 * emu, int device, snd_pcm_t ** rpcm) 1391 { 1392 snd_pcm_t *pcm; 1393 snd_pcm_substream_t *substream; 1394 int err; 1395 1396 if (rpcm) 1397 *rpcm = NULL; 1398 1399 if ((err = snd_pcm_new(emu->card, "emu10k1", device, 1, 0, &pcm)) < 0) 1400 return err; 1401 1402 pcm->private_data = emu; 1403 pcm->private_free = snd_emu10k1_pcm_free; 1404 1405 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_emu10k1_efx_playback_ops); 1406 1407 pcm->info_flags = 0; 1408 pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX; 1409 strcpy(pcm->name, "EMU10K1 multichannel EFX"); 1410 emu->pcm = pcm; 1411 1412 for (substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; substream; substream = substream->next) 1413 if ((err = snd_pcm_lib_preallocate_pages(substream, SNDRV_DMA_TYPE_DEV_SG, snd_dma_pci_data(emu->pci), 64*1024, 64*1024)) < 0) 1414 return err; 1415 1416 if (rpcm) 1417 *rpcm = pcm; 1418 1419 return 0; 1420 } 1421 1422 static snd_pcm_ops_t snd_emu10k1_capture_mic_ops = { 1423 snd_emu10k1_capture_mic_open, 1424 snd_emu10k1_capture_mic_close, 1425 snd_pcm_lib_ioctl, 1426 snd_emu10k1_capture_hw_params, 1427 snd_emu10k1_capture_hw_free, 1428 snd_emu10k1_capture_prepare, 1429 snd_emu10k1_capture_trigger, 1430 snd_emu10k1_capture_pointer,0,0,0,0 1350 int __devinit snd_emu10k1_pcm(struct snd_emu10k1 * emu, int device, struct snd_pcm ** rpcm) 1351 { 1352 struct snd_pcm *pcm; 1353 struct snd_pcm_substream *substream; 1354 int err; 1355 1356 if (rpcm) 1357 *rpcm = NULL; 1358 1359 if ((err = snd_pcm_new(emu->card, "emu10k1", device, 32, 1, &pcm)) < 0) 1360 return err; 1361 1362 pcm->private_data = emu; 1363 1364 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_emu10k1_playback_ops); 1365 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_emu10k1_capture_ops); 1366 1367 pcm->info_flags = 0; 1368 pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX; 1369 strcpy(pcm->name, "ADC Capture/Standard PCM Playback"); 1370 emu->pcm = pcm; 1371 1372 for (substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; substream; substream = substream->next) 1373 if ((err = snd_pcm_lib_preallocate_pages(substream, SNDRV_DMA_TYPE_DEV_SG, snd_dma_pci_data(emu->pci), 64*1024, 64*1024)) < 0) 1374 return err; 1375 1376 for (substream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream; substream; substream = substream->next) 1377 snd_pcm_lib_preallocate_pages(substream, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(emu->pci), 64*1024, 64*1024); 1378 1379 if (rpcm) 1380 *rpcm = pcm; 1381 1382 return 0; 1383 } 1384 1385 int __devinit snd_emu10k1_pcm_multi(struct snd_emu10k1 * emu, int device, struct snd_pcm ** rpcm) 1386 { 1387 struct snd_pcm *pcm; 1388 struct snd_pcm_substream *substream; 1389 int err; 1390 1391 if (rpcm) 1392 *rpcm = NULL; 1393 1394 if ((err = snd_pcm_new(emu->card, "emu10k1", device, 1, 0, &pcm)) < 0) 1395 return err; 1396 1397 pcm->private_data = emu; 1398 1399 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_emu10k1_efx_playback_ops); 1400 1401 pcm->info_flags = 0; 1402 pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX; 1403 strcpy(pcm->name, "Multichannel Playback"); 1404 emu->pcm_multi = pcm; 1405 1406 for (substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; substream; substream = substream->next) 1407 if ((err = snd_pcm_lib_preallocate_pages(substream, SNDRV_DMA_TYPE_DEV_SG, snd_dma_pci_data(emu->pci), 64*1024, 64*1024)) < 0) 1408 return err; 1409 1410 if (rpcm) 1411 *rpcm = pcm; 1412 1413 return 0; 1414 } 1415 1416 1417 static struct snd_pcm_ops snd_emu10k1_capture_mic_ops = { 1418 .open = snd_emu10k1_capture_mic_open, 1419 .close = snd_emu10k1_capture_mic_close, 1420 .ioctl = snd_pcm_lib_ioctl, 1421 .hw_params = snd_emu10k1_capture_hw_params, 1422 .hw_free = snd_emu10k1_capture_hw_free, 1423 .prepare = snd_emu10k1_capture_prepare, 1424 .trigger = snd_emu10k1_capture_trigger, 1425 .pointer = snd_emu10k1_capture_pointer, 1431 1426 }; 1432 1427 1433 static void snd_emu10k1_pcm_mic_free(snd_pcm_t *pcm) 1434 { 1435 struct snd_emu10k1 *emu = pcm->private_data; 1436 emu->pcm_mic = NULL; 1437 snd_pcm_lib_preallocate_free_for_all(pcm); 1438 } 1439 1440 int __devinit snd_emu10k1_pcm_mic(struct snd_emu10k1 * emu, int device, snd_pcm_t ** rpcm) 1441 { 1442 snd_pcm_t *pcm; 1443 int err; 1444 1445 if (rpcm) 1446 *rpcm = NULL; 1447 1448 if ((err = snd_pcm_new(emu->card, "emu10k1 mic", device, 0, 1, &pcm)) < 0) 1449 return err; 1450 1451 pcm->private_data = emu; 1452 pcm->private_free = snd_emu10k1_pcm_mic_free; 1453 1454 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_emu10k1_capture_mic_ops); 1455 1456 pcm->info_flags = 0; 1457 strcpy(pcm->name, "EMU10K1 MIC"); 1458 emu->pcm_mic = pcm; 1459 1460 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(emu->pci), 64*1024, 64*1024); 1461 1462 if (rpcm) 1463 *rpcm = pcm; 1464 return 0; 1465 } 1466 1467 1468 static int snd_emu10k1_pcm_efx_voices_mask_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) 1469 { 1470 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 1471 int nefx = emu->audigy ? 64 : 32; 1472 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 1473 uinfo->count = nefx; 1474 uinfo->value.integer.min = 0; 1475 uinfo->value.integer.max = 1; 1476 return 0; 1477 } 1478 1479 static int snd_emu10k1_pcm_efx_voices_mask_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) 1480 { 1481 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 1482 int nefx = emu->audigy ? 64 : 32; 1483 int idx; 1484 1485 spin_lock_irq(&emu->reg_lock); 1486 for (idx = 0; idx < nefx; idx++) 1487 ucontrol->value.integer.value[idx] = (emu->efx_voices_mask[idx / 32] & (1 << (idx % 32))) ? 1 : 0; 1488 spin_unlock_irq(&emu->reg_lock); 1489 return 0; 1490 } 1491 1492 static int snd_emu10k1_pcm_efx_voices_mask_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) 1493 { 1494 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 1495 unsigned int nval[2], bits; 1496 int nefx = emu->audigy ? 64 : 32; 1497 int nefxb = emu->audigy ? 7 : 6; 1498 int change, idx; 1499 1500 nval[0] = nval[1] = 0; 1501 for (idx = 0, bits = 0; idx < nefx; idx++) 1502 if (ucontrol->value.integer.value[idx]) { 1503 nval[idx / 32] |= 1 << (idx % 32); 1504 bits++; 1505 } 1506 for (idx = 0; idx < nefxb; idx++) 1507 if (1 << idx == bits) 1508 break; 1509 if (idx >= nefxb) 1510 return -EINVAL; 1511 spin_lock_irq(&emu->reg_lock); 1512 change = (nval[0] != emu->efx_voices_mask[0]) || 1513 (nval[1] != emu->efx_voices_mask[1]); 1514 emu->efx_voices_mask[0] = nval[0]; 1515 emu->efx_voices_mask[1] = nval[1]; 1516 spin_unlock_irq(&emu->reg_lock); 1517 return change; 1518 } 1519 1520 static snd_kcontrol_new_t snd_emu10k1_pcm_efx_voices_mask = { 1521 SNDRV_CTL_ELEM_IFACE_PCM,0,0, 1522 "Captured FX8010 Outputs",0,0, 0, 1523 snd_emu10k1_pcm_efx_voices_mask_info, 1524 snd_emu10k1_pcm_efx_voices_mask_get, 1525 snd_emu10k1_pcm_efx_voices_mask_put,0 1428 int __devinit snd_emu10k1_pcm_mic(struct snd_emu10k1 * emu, int device, struct snd_pcm ** rpcm) 1429 { 1430 struct snd_pcm *pcm; 1431 int err; 1432 1433 if (rpcm) 1434 *rpcm = NULL; 1435 1436 if ((err = snd_pcm_new(emu->card, "emu10k1 mic", device, 0, 1, &pcm)) < 0) 1437 return err; 1438 1439 pcm->private_data = emu; 1440 1441 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_emu10k1_capture_mic_ops); 1442 1443 pcm->info_flags = 0; 1444 strcpy(pcm->name, "Mic Capture"); 1445 emu->pcm_mic = pcm; 1446 1447 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(emu->pci), 64*1024, 64*1024); 1448 1449 if (rpcm) 1450 *rpcm = pcm; 1451 return 0; 1452 } 1453 1454 static int snd_emu10k1_pcm_efx_voices_mask_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1455 { 1456 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 1457 int nefx = emu->audigy ? 64 : 32; 1458 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 1459 uinfo->count = nefx; 1460 uinfo->value.integer.min = 0; 1461 uinfo->value.integer.max = 1; 1462 return 0; 1463 } 1464 1465 static int snd_emu10k1_pcm_efx_voices_mask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1466 { 1467 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 1468 int nefx = emu->audigy ? 64 : 32; 1469 int idx; 1470 1471 spin_lock_irq(&emu->reg_lock); 1472 for (idx = 0; idx < nefx; idx++) 1473 ucontrol->value.integer.value[idx] = (emu->efx_voices_mask[idx / 32] & (1 << (idx % 32))) ? 1 : 0; 1474 spin_unlock_irq(&emu->reg_lock); 1475 return 0; 1476 } 1477 1478 static int snd_emu10k1_pcm_efx_voices_mask_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1479 { 1480 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol); 1481 unsigned int nval[2], bits; 1482 int nefx = emu->audigy ? 64 : 32; 1483 int nefxb = emu->audigy ? 7 : 6; 1484 int change, idx; 1485 1486 nval[0] = nval[1] = 0; 1487 for (idx = 0, bits = 0; idx < nefx; idx++) 1488 if (ucontrol->value.integer.value[idx]) { 1489 nval[idx / 32] |= 1 << (idx % 32); 1490 bits++; 1491 } 1492 1493 for (idx = 0; idx < nefxb; idx++) 1494 if (1 << idx == bits) 1495 break; 1496 1497 if (idx >= nefxb) 1498 return -EINVAL; 1499 1500 spin_lock_irq(&emu->reg_lock); 1501 change = (nval[0] != emu->efx_voices_mask[0]) || 1502 (nval[1] != emu->efx_voices_mask[1]); 1503 emu->efx_voices_mask[0] = nval[0]; 1504 emu->efx_voices_mask[1] = nval[1]; 1505 spin_unlock_irq(&emu->reg_lock); 1506 return change; 1507 } 1508 1509 static struct snd_kcontrol_new snd_emu10k1_pcm_efx_voices_mask = { 1510 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 1511 .name = "Captured FX8010 Outputs", 1512 .info = snd_emu10k1_pcm_efx_voices_mask_info, 1513 .get = snd_emu10k1_pcm_efx_voices_mask_get, 1514 .put = snd_emu10k1_pcm_efx_voices_mask_put 1526 1515 }; 1527 1516 1528 static s nd_pcm_ops_tsnd_emu10k1_capture_efx_ops = {1529 1530 1531 1532 1533 1534 1535 1536 snd_emu10k1_capture_pointer,0,0,0,0 1517 static struct snd_pcm_ops snd_emu10k1_capture_efx_ops = { 1518 .open = snd_emu10k1_capture_efx_open, 1519 .close = snd_emu10k1_capture_efx_close, 1520 .ioctl = snd_pcm_lib_ioctl, 1521 .hw_params = snd_emu10k1_capture_hw_params, 1522 .hw_free = snd_emu10k1_capture_hw_free, 1523 .prepare = snd_emu10k1_capture_prepare, 1524 .trigger = snd_emu10k1_capture_trigger, 1525 .pointer = snd_emu10k1_capture_pointer, 1537 1526 }; 1538 1527 … … 1545 1534 static void snd_emu10k1_fx8010_playback_irq(struct snd_emu10k1 *emu, void *private_data) 1546 1535 { 1547 snd_pcm_substream_t*substream = private_data;1548 1536 struct snd_pcm_substream *substream = private_data; 1537 snd_pcm_period_elapsed(substream); 1549 1538 } 1550 1539 1551 1540 static void snd_emu10k1_fx8010_playback_tram_poke1(unsigned short *dst_left, 1552 1553 1554 1555 1556 { 1557 // printk("tram_poke1: dst_left = 0x%p, dst_right = 0x%p, src = 0x%p, count = 0x%x\n", dst_left, dst_right, src, count); 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 } 1570 1571 1572 static void fx8010_pb_trans_copy(snd_pcm_substream_t *substream, 1573 struct snd_pcm_indirect *rec, size_t bytes) 1574 { 1575 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);1576 struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];1577 unsigned int tram_size = pcm->buffer_size;1578 unsigned short *src = (unsigned short *)(substream->runtime->dma_area + rec->sw_data);1579 unsigned int frames = bytes >> 2, count;1580 unsigned int tram_pos = pcm->tram_pos;1581 unsigned int tram_shift = pcm->tram_shift; 1582 1583 while (frames > tram_pos) { 1584 count = tram_pos + 1; 1585 snd_emu10k1_fx8010_playback_tram_poke1((unsigned short *)emu->fx8010.etram_pages.area + tram_pos,1586 (unsigned short *)emu->fx8010.etram_pages.area + tram_pos + tram_size / 2, 1587 src, count, tram_shift);1588 src += count * 2;1589 frames -= count;1590 tram_pos = (tram_size / 2) - 1;1591 tram_shift++; 1592 } 1593 snd_emu10k1_fx8010_playback_tram_poke1((unsigned short *)emu->fx8010.etram_pages.area + tram_pos,1594 (unsigned short *)emu->fx8010.etram_pages.area + tram_pos + tram_size / 2, 1595 src, frames, tram_shift);1596 tram_pos -= frames;1597 pcm->tram_pos = tram_pos;1598 pcm->tram_shift = tram_shift; 1599 } 1600 1601 static int snd_emu10k1_fx8010_playback_transfer(snd_pcm_substream_t *substream) 1602 { 1603 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);1604 struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number]; 1605 1606 snd_pcm_indirect_playback_transfer(substream, &pcm->pcm_rec, fx8010_pb_trans_copy);1607 return 0; 1608 } 1609 1610 static int snd_emu10k1_fx8010_playback_hw_params(snd_pcm_substream_t * substream, 1611 snd_pcm_hw_params_t * hw_params) 1612 { 1613 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); 1614 } 1615 1616 static int snd_emu10k1_fx8010_playback_hw_free(snd_pcm_substream_t * substream) 1617 { 1618 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);1619 struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];1620 unsigned int i; 1621 1622 for (i = 0; i < pcm->channels; i++) 1623 snd_emu10k1_ptr_write(emu, TANKMEMADDRREGBASE + 0x80 + pcm->etram[i], 0, 0);1624 snd_pcm_lib_free_pages(substream);1625 return 0; 1626 } 1627 1628 static int snd_emu10k1_fx8010_playback_prepare(snd_pcm_substream_t * substream) 1629 { 1630 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);1631 snd_pcm_runtime_t *runtime = substream->runtime;1632 struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];1633 unsigned int i; 1634 1635 // printk("prepare: etram_pages = 0x%p, dma_area = 0x%x, buffer_size = 0x%x (0x%x)\n", emu->fx8010.etram_pages, runtime->dma_area, runtime->buffer_size, runtime->buffer_size << 2);1636 memset(&pcm->pcm_rec, 0, sizeof(pcm->pcm_rec)); 1637 pcm->pcm_rec.hw_buffer_size = pcm->buffer_size * 2; /* byte size */ 1638 pcm->pcm_rec.sw_buffer_size = snd_pcm_lib_buffer_bytes(substream);1639 pcm->tram_pos = INITIAL_TRAM_POS(pcm->buffer_size);1640 pcm->tram_shift = 0; 1641 snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_running, 0, 0);/* reset */1642 snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_trigger, 0, 0); /* reset */ 1643 snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_size, 0, runtime->buffer_size); 1644 snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_ptr, 0, 0); /* reset ptr number */ 1645 snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_count, 0, runtime->period_size);1646 snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_tmpcount, 0, runtime->period_size); 1647 for (i = 0; i < pcm->channels; i++) 1648 snd_emu10k1_ptr_write(emu, TANKMEMADDRREGBASE + 0x80 + pcm->etram[i], 0, (TANKMEMADDRREG_READ|TANKMEMADDRREG_ALIGN) + i * (runtime->buffer_size / pcm->channels));1649 return 0; 1650 } 1651 1652 static int snd_emu10k1_fx8010_playback_trigger(snd_pcm_substream_t * substream, int cmd) 1653 { 1654 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);1655 struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];1656 int result = 0; 1657 1658 spin_lock(&emu->reg_lock); 1659 switch (cmd) { 1660 case SNDRV_PCM_TRIGGER_START: 1661 /* follow thru */ 1662 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:1541 unsigned short *dst_right, 1542 unsigned short *src, 1543 unsigned int count, 1544 unsigned int tram_shift) 1545 { 1546 /* printk("tram_poke1: dst_left = 0x%p, dst_right = 0x%p, src = 0x%p, count = 0x%x\n", dst_left, dst_right, src, count); */ 1547 if ((tram_shift & 1) == 0) { 1548 while (count--) { 1549 *dst_left-- = *src++; 1550 *dst_right-- = *src++; 1551 } 1552 } else { 1553 while (count--) { 1554 *dst_right-- = *src++; 1555 *dst_left-- = *src++; 1556 } 1557 } 1558 } 1559 1560 static void fx8010_pb_trans_copy(struct snd_pcm_substream *substream, 1561 struct snd_pcm_indirect *rec, size_t bytes) 1562 { 1563 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 1564 struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number]; 1565 unsigned int tram_size = pcm->buffer_size; 1566 unsigned short *src = (unsigned short *)(substream->runtime->dma_area + rec->sw_data); 1567 unsigned int frames = bytes >> 2, count; 1568 unsigned int tram_pos = pcm->tram_pos; 1569 unsigned int tram_shift = pcm->tram_shift; 1570 1571 while (frames > tram_pos) { 1572 count = tram_pos + 1; 1573 snd_emu10k1_fx8010_playback_tram_poke1((unsigned short *)emu->fx8010.etram_pages.area + tram_pos, 1574 (unsigned short *)emu->fx8010.etram_pages.area + tram_pos + tram_size / 2, 1575 src, count, tram_shift); 1576 src += count * 2; 1577 frames -= count; 1578 tram_pos = (tram_size / 2) - 1; 1579 tram_shift++; 1580 } 1581 snd_emu10k1_fx8010_playback_tram_poke1((unsigned short *)emu->fx8010.etram_pages.area + tram_pos, 1582 (unsigned short *)emu->fx8010.etram_pages.area + tram_pos + tram_size / 2, 1583 src, frames, tram_shift); 1584 tram_pos -= frames; 1585 pcm->tram_pos = tram_pos; 1586 pcm->tram_shift = tram_shift; 1587 } 1588 1589 static int snd_emu10k1_fx8010_playback_transfer(struct snd_pcm_substream *substream) 1590 { 1591 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 1592 struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number]; 1593 1594 snd_pcm_indirect_playback_transfer(substream, &pcm->pcm_rec, fx8010_pb_trans_copy); 1595 return 0; 1596 } 1597 1598 static int snd_emu10k1_fx8010_playback_hw_params(struct snd_pcm_substream *substream, 1599 struct snd_pcm_hw_params *hw_params) 1600 { 1601 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); 1602 } 1603 1604 static int snd_emu10k1_fx8010_playback_hw_free(struct snd_pcm_substream *substream) 1605 { 1606 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 1607 struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number]; 1608 unsigned int i; 1609 1610 for (i = 0; i < pcm->channels; i++) 1611 snd_emu10k1_ptr_write(emu, TANKMEMADDRREGBASE + 0x80 + pcm->etram[i], 0, 0); 1612 snd_pcm_lib_free_pages(substream); 1613 return 0; 1614 } 1615 1616 static int snd_emu10k1_fx8010_playback_prepare(struct snd_pcm_substream *substream) 1617 { 1618 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 1619 struct snd_pcm_runtime *runtime = substream->runtime; 1620 struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number]; 1621 unsigned int i; 1622 1623 /* printk("prepare: etram_pages = 0x%p, dma_area = 0x%x, buffer_size = 0x%x (0x%x)\n", emu->fx8010.etram_pages, runtime->dma_area, runtime->buffer_size, runtime->buffer_size << 2); */ 1624 memset(&pcm->pcm_rec, 0, sizeof(pcm->pcm_rec)); 1625 pcm->pcm_rec.hw_buffer_size = pcm->buffer_size * 2; /* byte size */ 1626 pcm->pcm_rec.sw_buffer_size = snd_pcm_lib_buffer_bytes(substream); 1627 pcm->tram_pos = INITIAL_TRAM_POS(pcm->buffer_size); 1628 pcm->tram_shift = 0; 1629 snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_running, 0, 0); /* reset */ 1630 snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_trigger, 0, 0); /* reset */ 1631 snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_size, 0, runtime->buffer_size); 1632 snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_ptr, 0, 0); /* reset ptr number */ 1633 snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_count, 0, runtime->period_size); 1634 snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_tmpcount, 0, runtime->period_size); 1635 for (i = 0; i < pcm->channels; i++) 1636 snd_emu10k1_ptr_write(emu, TANKMEMADDRREGBASE + 0x80 + pcm->etram[i], 0, (TANKMEMADDRREG_READ|TANKMEMADDRREG_ALIGN) + i * (runtime->buffer_size / pcm->channels)); 1637 return 0; 1638 } 1639 1640 static int snd_emu10k1_fx8010_playback_trigger(struct snd_pcm_substream *substream, int cmd) 1641 { 1642 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 1643 struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number]; 1644 int result = 0; 1645 1646 spin_lock(&emu->reg_lock); 1647 switch (cmd) { 1648 case SNDRV_PCM_TRIGGER_START: 1649 /* follow thru */ 1650 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 1651 case SNDRV_PCM_TRIGGER_RESUME: 1663 1652 #ifdef EMU10K1_SET_AC3_IEC958 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1653 { 1654 int i; 1655 for (i = 0; i < 3; i++) { 1656 unsigned int bits; 1657 bits = SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 | 1658 SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | SPCS_GENERATIONSTATUS | 1659 0x00001200 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT | SPCS_NOTAUDIODATA; 1660 snd_emu10k1_ptr_write(emu, SPCS0 + i, 0, bits); 1661 } 1662 } 1674 1663 #endif 1675 result = snd_emu10k1_fx8010_register_irq_handler(emu, snd_emu10k1_fx8010_playback_irq, pcm->gpr_running, substream, &pcm->irq); 1676 if (result < 0) 1677 goto __err; 1678 snd_emu10k1_fx8010_playback_transfer(substream); /* roll the ball */ 1679 snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_trigger, 0, 1); 1680 break; 1681 case SNDRV_PCM_TRIGGER_STOP: 1682 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 1683 snd_emu10k1_fx8010_unregister_irq_handler(emu, pcm->irq); pcm->irq = NULL; 1684 snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_trigger, 0, 0); 1685 pcm->tram_pos = INITIAL_TRAM_POS(pcm->buffer_size); 1686 pcm->tram_shift = 0; 1687 break; 1688 default: 1689 result = -EINVAL; 1690 break; 1691 } 1692 __err: 1693 spin_unlock(&emu->reg_lock); 1694 return result; 1695 } 1696 1697 static snd_pcm_uframes_t snd_emu10k1_fx8010_playback_pointer(snd_pcm_substream_t * substream) 1698 { 1699 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 1700 struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number]; 1701 size_t ptr; /* byte pointer */ 1702 1703 if (!snd_emu10k1_ptr_read(emu, emu->gpr_base + pcm->gpr_trigger, 0)) 1704 return 0; 1705 ptr = snd_emu10k1_ptr_read(emu, emu->gpr_base + pcm->gpr_ptr, 0) << 2; 1706 return snd_pcm_indirect_playback_pointer(substream, &pcm->pcm_rec, ptr); 1664 result = snd_emu10k1_fx8010_register_irq_handler(emu, snd_emu10k1_fx8010_playback_irq, pcm->gpr_running, substream, &pcm->irq); 1665 if (result < 0) 1666 goto __err; 1667 snd_emu10k1_fx8010_playback_transfer(substream); /* roll the ball */ 1668 snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_trigger, 0, 1); 1669 break; 1670 case SNDRV_PCM_TRIGGER_STOP: 1671 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 1672 case SNDRV_PCM_TRIGGER_SUSPEND: 1673 snd_emu10k1_fx8010_unregister_irq_handler(emu, pcm->irq); pcm->irq = NULL; 1674 snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_trigger, 0, 0); 1675 pcm->tram_pos = INITIAL_TRAM_POS(pcm->buffer_size); 1676 pcm->tram_shift = 0; 1677 break; 1678 default: 1679 result = -EINVAL; 1680 break; 1681 } 1682 __err: 1683 spin_unlock(&emu->reg_lock); 1684 return result; 1685 } 1686 1687 static snd_pcm_uframes_t snd_emu10k1_fx8010_playback_pointer(struct snd_pcm_substream *substream) 1688 { 1689 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 1690 struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number]; 1691 size_t ptr; /* byte pointer */ 1692 1693 if (!snd_emu10k1_ptr_read(emu, emu->gpr_base + pcm->gpr_trigger, 0)) 1694 return 0; 1695 ptr = snd_emu10k1_ptr_read(emu, emu->gpr_base + pcm->gpr_ptr, 0) << 2; 1696 return snd_pcm_indirect_playback_pointer(substream, &pcm->pcm_rec, ptr); 1707 1697 } 1708 1698 1709 1699 static struct snd_pcm_hardware snd_emu10k1_fx8010_playback = 1710 1700 { 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1701 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 1702 SNDRV_PCM_INFO_RESUME | 1703 /* SNDRV_PCM_INFO_MMAP_VALID | */ SNDRV_PCM_INFO_PAUSE), 1704 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE, 1705 .rates = SNDRV_PCM_RATE_48000, 1706 .rate_min = 48000, 1707 .rate_max = 48000, 1708 .channels_min = 1, 1709 .channels_max = 1, 1710 .buffer_bytes_max = (128*1024), 1711 .period_bytes_min = 1024, 1712 .period_bytes_max = (128*1024), 1713 .periods_min = 1, 1714 .periods_max = 1024, 1715 .fifo_size = 0, 1726 1716 }; 1727 1717 1728 static int snd_emu10k1_fx8010_playback_open(s nd_pcm_substream_t *substream)1729 { 1730 1731 snd_pcm_runtime_t*runtime = substream->runtime;1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 } 1746 1747 static int snd_emu10k1_fx8010_playback_close(s nd_pcm_substream_t *substream)1748 { 1749 1750 1751 1752 1753 1754 1755 1718 static int snd_emu10k1_fx8010_playback_open(struct snd_pcm_substream *substream) 1719 { 1720 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 1721 struct snd_pcm_runtime *runtime = substream->runtime; 1722 struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number]; 1723 1724 runtime->hw = snd_emu10k1_fx8010_playback; 1725 runtime->hw.channels_min = runtime->hw.channels_max = pcm->channels; 1726 runtime->hw.period_bytes_max = (pcm->buffer_size * 2) / 2; 1727 spin_lock_irq(&emu->reg_lock); 1728 if (pcm->valid == 0) { 1729 spin_unlock_irq(&emu->reg_lock); 1730 return -ENODEV; 1731 } 1732 pcm->opened = 1; 1733 spin_unlock_irq(&emu->reg_lock); 1734 return 0; 1735 } 1736 1737 static int snd_emu10k1_fx8010_playback_close(struct snd_pcm_substream *substream) 1738 { 1739 struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); 1740 struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number]; 1741 1742 spin_lock_irq(&emu->reg_lock); 1743 pcm->opened = 0; 1744 spin_unlock_irq(&emu->reg_lock); 1745 return 0; 1756 1746 } 1757 1747 … … 1768 1758 }; 1769 1759 1770 static void snd_emu10k1_pcm_efx_free(snd_pcm_t *pcm) 1771 { 1772 struct snd_emu10k1 *emu = pcm->private_data; 1773 emu->pcm_efx = NULL; 1774 snd_pcm_lib_preallocate_free_for_all(pcm); 1775 } 1776 1777 int __devinit snd_emu10k1_pcm_efx(struct snd_emu10k1 * emu, int device, snd_pcm_t ** rpcm) 1778 { 1779 snd_pcm_t *pcm; 1780 snd_kcontrol_t *kctl; 1781 int err; 1782 1783 if (rpcm) 1784 *rpcm = NULL; 1785 1786 if ((err = snd_pcm_new(emu->card, "emu10k1 efx", device, 8, 1, &pcm)) < 0) 1787 return err; 1788 1789 pcm->private_data = emu; 1790 pcm->private_free = snd_emu10k1_pcm_efx_free; 1791 1792 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_emu10k1_fx8010_playback_ops); 1793 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_emu10k1_capture_efx_ops); 1794 1795 pcm->info_flags = 0; 1796 strcpy(pcm->name, "EMU10K1 EFX"); 1797 emu->pcm_efx = pcm; 1798 if (rpcm) 1799 *rpcm = pcm; 1800 1801 /* EFX capture - record the "FXBUS2" channels, by default we connect the EXTINs 1802 * to these 1803 */ 1804 1805 /* emu->efx_voices_mask[0] = FXWC_DEFAULTROUTE_C | FXWC_DEFAULTROUTE_A; */ 1806 if (emu->audigy) { 1807 emu->efx_voices_mask[0] = 0; 1808 emu->efx_voices_mask[1] = 0xffff; 1809 } else { 1810 emu->efx_voices_mask[0] = 0xffff0000; 1811 emu->efx_voices_mask[1] = 0; 1812 } 1813 1814 kctl = snd_ctl_new1(&snd_emu10k1_pcm_efx_voices_mask, emu); 1815 if (!kctl) 1816 return -ENOMEM; 1817 kctl->id.device = device; 1818 snd_ctl_add(emu->card, kctl); 1819 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(emu->pci), 64*1024, 64*1024); 1820 1821 return 0; 1822 } 1823 1760 int __devinit snd_emu10k1_pcm_efx(struct snd_emu10k1 * emu, int device, struct snd_pcm ** rpcm) 1761 { 1762 struct snd_pcm *pcm; 1763 struct snd_kcontrol *kctl; 1764 int err; 1765 1766 if (rpcm) 1767 *rpcm = NULL; 1768 1769 if ((err = snd_pcm_new(emu->card, "emu10k1 efx", device, 8, 1, &pcm)) < 0) 1770 return err; 1771 1772 pcm->private_data = emu; 1773 1774 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_emu10k1_fx8010_playback_ops); 1775 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_emu10k1_capture_efx_ops); 1776 1777 pcm->info_flags = 0; 1778 strcpy(pcm->name, "Multichannel Capture/PT Playback"); 1779 emu->pcm_efx = pcm; 1780 if (rpcm) 1781 *rpcm = pcm; 1782 1783 /* EFX capture - record the "FXBUS2" channels, by default we connect the EXTINs 1784 * to these 1785 */ 1786 1787 /* emu->efx_voices_mask[0] = FXWC_DEFAULTROUTE_C | FXWC_DEFAULTROUTE_A; */ 1788 if (emu->audigy) { 1789 emu->efx_voices_mask[0] = 0; 1790 emu->efx_voices_mask[1] = 0xffff; 1791 } else { 1792 emu->efx_voices_mask[0] = 0xffff0000; 1793 emu->efx_voices_mask[1] = 0; 1794 } 1795 kctl = snd_ctl_new1(&snd_emu10k1_pcm_efx_voices_mask, emu); 1796 if (!kctl) 1797 return -ENOMEM; 1798 kctl->id.device = device; 1799 snd_ctl_add(emu->card, kctl); 1800 1801 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(emu->pci), 64*1024, 64*1024); 1802 1803 return 0; 1804 }
Note:
See TracChangeset
for help on using the changeset viewer.