Lines Matching +full:hw +full:- +full:channels
1 // SPDX-License-Identifier: GPL-2.0-or-later
17 * define the following if you want to use this pcm with non-interleaved mode
21 /* NOTE: for using the non-interleaved mode with alsa-lib, you have to set
27 * type hw
34 * besides, for the time being, the non-interleaved mode doesn't work well on
35 * alsa-lib...
65 * open up channels for the simultaneous data transfer and playback
68 emu8k_open_dram_for_pcm(struct snd_emu8000 *emu, int channels) in emu8k_open_dram_for_pcm() argument
73 snd_emux_lock_voice(emu->emu, 0); in emu8k_open_dram_for_pcm()
74 if (channels > 1) in emu8k_open_dram_for_pcm()
75 snd_emux_lock_voice(emu->emu, 1); in emu8k_open_dram_for_pcm()
78 for (i = channels + 1; i < EMU8000_DRAM_VOICES; i++) { in emu8k_open_dram_for_pcm()
80 snd_emux_lock_voice(emu->emu, i); in emu8k_open_dram_for_pcm()
82 if (channels > 1 && (i & 1) != 0) in emu8k_open_dram_for_pcm()
116 * close all channels
124 snd_emux_unlock_voice(emu->emu, i); in emu8k_close_dram()
127 snd_emux_unlock_voice(emu->emu, i); in emu8k_close_dram()
173 int val = EMU8000_CCCA_READ(rec->emu, ch) & 0xfffffff; in emu8k_get_curpos()
174 val -= rec->loop_start[ch] - 1; in emu8k_get_curpos()
188 spin_lock(&rec->timer_lock); in emu8k_pcm_timer_func()
191 if (ptr < rec->last_ptr) in emu8k_pcm_timer_func()
192 delta = ptr + rec->buf_size - rec->last_ptr; in emu8k_pcm_timer_func()
194 delta = ptr - rec->last_ptr; in emu8k_pcm_timer_func()
195 rec->period_pos += delta; in emu8k_pcm_timer_func()
196 rec->last_ptr = ptr; in emu8k_pcm_timer_func()
199 mod_timer(&rec->timer, jiffies + 1); in emu8k_pcm_timer_func()
202 if (rec->period_pos >= (int)rec->period_size) { in emu8k_pcm_timer_func()
203 rec->period_pos %= rec->period_size; in emu8k_pcm_timer_func()
204 spin_unlock(&rec->timer_lock); in emu8k_pcm_timer_func()
205 snd_pcm_period_elapsed(rec->substream); in emu8k_pcm_timer_func()
208 spin_unlock(&rec->timer_lock); in emu8k_pcm_timer_func()
220 struct snd_pcm_runtime *runtime = subs->runtime; in emu8k_pcm_open()
224 return -ENOMEM; in emu8k_pcm_open()
226 rec->emu = emu; in emu8k_pcm_open()
227 rec->substream = subs; in emu8k_pcm_open()
228 runtime->private_data = rec; in emu8k_pcm_open()
230 spin_lock_init(&rec->timer_lock); in emu8k_pcm_open()
231 timer_setup(&rec->timer, emu8k_pcm_timer_func, 0); in emu8k_pcm_open()
233 runtime->hw = emu8k_pcm_hw; in emu8k_pcm_open()
234 runtime->hw.buffer_bytes_max = emu->mem_size - LOOP_BLANK_SIZE * 3; in emu8k_pcm_open()
235 runtime->hw.period_bytes_max = runtime->hw.buffer_bytes_max / 2; in emu8k_pcm_open()
246 struct snd_emu8k_pcm *rec = subs->runtime->private_data; in emu8k_pcm_close()
248 subs->runtime->private_data = NULL; in emu8k_pcm_close()
271 struct snd_emu8000 *hw = rec->emu; in setup_voice() local
275 EMU8000_DCYSUSV_WRITE(hw, ch, 0x0080); in setup_voice()
276 EMU8000_VTFT_WRITE(hw, ch, 0x0000FFFF); in setup_voice()
277 EMU8000_CVCF_WRITE(hw, ch, 0x0000FFFF); in setup_voice()
278 EMU8000_PTRX_WRITE(hw, ch, 0); in setup_voice()
279 EMU8000_CPF_WRITE(hw, ch, 0); in setup_voice()
282 EMU8000_IP_WRITE(hw, ch, rec->pitch); in setup_voice()
284 EMU8000_ENVVAL_WRITE(hw, ch, 0x8000); in setup_voice()
285 EMU8000_ATKHLD_WRITE(hw, ch, 0x7f7f); in setup_voice()
286 EMU8000_DCYSUS_WRITE(hw, ch, 0x7f7f); in setup_voice()
287 EMU8000_ENVVOL_WRITE(hw, ch, 0x8000); in setup_voice()
288 EMU8000_ATKHLDV_WRITE(hw, ch, 0x7f7f); in setup_voice()
292 EMU8000_PEFE_WRITE(hw, ch, 0x0); in setup_voice()
294 EMU8000_LFO1VAL_WRITE(hw, ch, 0x8000); in setup_voice()
295 EMU8000_LFO2VAL_WRITE(hw, ch, 0x8000); in setup_voice()
297 EMU8000_FMMOD_WRITE(hw, ch, 0); in setup_voice()
299 EMU8000_TREMFRQ_WRITE(hw, ch, 0); in setup_voice()
301 EMU8000_FM2FRQ2_WRITE(hw, ch, 0); in setup_voice()
303 temp = rec->panning[ch]; in setup_voice()
304 temp = (temp <<24) | ((unsigned int)rec->loop_start[ch] - 1); in setup_voice()
305 EMU8000_PSST_WRITE(hw, ch, temp); in setup_voice()
308 temp = (temp << 24) | ((unsigned int)rec->loop_start[ch] + rec->buf_size - 1); in setup_voice()
309 EMU8000_CSL_WRITE(hw, ch, temp); in setup_voice()
312 temp = (temp << 28) | ((unsigned int)rec->loop_start[ch] - 1); in setup_voice()
313 EMU8000_CCCA_WRITE(hw, ch, temp); in setup_voice()
315 EMU8000_00A0_WRITE(hw, ch, 0); in setup_voice()
316 EMU8000_0080_WRITE(hw, ch, 0); in setup_voice()
325 struct snd_emu8000 *hw = rec->emu; in start_voice() local
327 int pt = calc_pitch_target(rec->pitch); in start_voice()
330 EMU8000_IFATN_WRITE(hw, ch, 0xff00); in start_voice()
331 EMU8000_VTFT_WRITE(hw, ch, 0xffff); in start_voice()
332 EMU8000_CVCF_WRITE(hw, ch, 0xffff); in start_voice()
334 EMU8000_DCYSUSV_WRITE(hw, ch, 0x7f7f); in start_voice()
337 if (rec->panning[ch] == 0) in start_voice()
340 aux = (-rec->panning[ch]) & 0xff; in start_voice()
342 EMU8000_PTRX_WRITE(hw, ch, temp); in start_voice()
343 EMU8000_CPF_WRITE(hw, ch, pt << 16); in start_voice()
346 spin_lock_irqsave(&rec->timer_lock, flags); in start_voice()
347 if (! rec->timer_running) { in start_voice()
348 mod_timer(&rec->timer, jiffies + 1); in start_voice()
349 rec->timer_running = 1; in start_voice()
351 spin_unlock_irqrestore(&rec->timer_lock, flags); in start_voice()
360 struct snd_emu8000 *hw = rec->emu; in stop_voice() local
362 EMU8000_DCYSUSV_WRITE(hw, ch, 0x807F); in stop_voice()
365 spin_lock_irqsave(&rec->timer_lock, flags); in stop_voice()
366 if (rec->timer_running) { in stop_voice()
367 del_timer(&rec->timer); in stop_voice()
368 rec->timer_running = 0; in stop_voice()
370 spin_unlock_irqrestore(&rec->timer_lock, flags); in stop_voice()
375 struct snd_emu8k_pcm *rec = subs->runtime->private_data; in emu8k_pcm_trigger()
380 for (ch = 0; ch < rec->voices; ch++) in emu8k_pcm_trigger()
382 rec->running = 1; in emu8k_pcm_trigger()
385 rec->running = 0; in emu8k_pcm_trigger()
386 for (ch = 0; ch < rec->voices; ch++) in emu8k_pcm_trigger()
390 return -EINVAL; in emu8k_pcm_trigger()
409 return -EAGAIN;\
417 return -EFAULT; \
424 struct snd_emu8000 *emu = (rec)->emu; \
432 count--; \
441 struct snd_emu8k_pcm *rec = subs->runtime->private_data; in emu8k_pcm_copy()
444 pos = (pos << 1) + rec->loop_start[voice]; in emu8k_pcm_copy()
454 struct snd_emu8k_pcm *rec = subs->runtime->private_data; in emu8k_pcm_silence()
457 pos = (pos << 1) + rec->loop_start[voice]; in emu8k_pcm_silence()
467 struct snd_emu8000 *emu = rec->emu; \
469 EMU8000_SMALW_WRITE(emu, pos + rec->loop_start[0]); \
470 if (rec->voices > 1) \
471 EMU8000_SMARW_WRITE(emu, pos + rec->loop_start[1]); \
477 if (rec->voices > 1) { \
482 count--; \
489 * DMA "left" and "right" channels on emu8k engine.
495 struct snd_emu8k_pcm *rec = subs->runtime->private_data; in emu8k_pcm_copy()
498 pos = bytes_to_frames(subs->runtime, pos); in emu8k_pcm_copy()
499 count = bytes_to_frames(subs->runtime, count); in emu8k_pcm_copy()
507 struct snd_emu8k_pcm *rec = subs->runtime->private_data; in emu8k_pcm_silence()
510 pos = bytes_to_frames(subs->runtime, pos); in emu8k_pcm_silence()
511 count = bytes_to_frames(subs->runtime, count); in emu8k_pcm_silence()
524 struct snd_emu8k_pcm *rec = subs->runtime->private_data; in emu8k_pcm_hw_params()
526 if (rec->block) { in emu8k_pcm_hw_params()
527 /* reallocation - release the old block */ in emu8k_pcm_hw_params()
528 snd_util_mem_free(rec->emu->memhdr, rec->block); in emu8k_pcm_hw_params()
529 rec->block = NULL; in emu8k_pcm_hw_params()
532 rec->allocated_bytes = params_buffer_bytes(hw_params) + LOOP_BLANK_SIZE * 4; in emu8k_pcm_hw_params()
533 rec->block = snd_util_mem_alloc(rec->emu->memhdr, rec->allocated_bytes); in emu8k_pcm_hw_params()
534 if (! rec->block) in emu8k_pcm_hw_params()
535 return -ENOMEM; in emu8k_pcm_hw_params()
536 rec->offset = EMU8000_DRAM_OFFSET + (rec->block->offset >> 1); /* in word */ in emu8k_pcm_hw_params()
537 /* at least dma_bytes must be set for non-interleaved mode */ in emu8k_pcm_hw_params()
538 subs->dma_buffer.bytes = params_buffer_bytes(hw_params); in emu8k_pcm_hw_params()
548 struct snd_emu8k_pcm *rec = subs->runtime->private_data; in emu8k_pcm_hw_free()
550 if (rec->block) { in emu8k_pcm_hw_free()
552 for (ch = 0; ch < rec->voices; ch++) in emu8k_pcm_hw_free()
554 if (rec->dram_opened) in emu8k_pcm_hw_free()
555 emu8k_close_dram(rec->emu); in emu8k_pcm_hw_free()
556 snd_util_mem_free(rec->emu->memhdr, rec->block); in emu8k_pcm_hw_free()
557 rec->block = NULL; in emu8k_pcm_hw_free()
566 struct snd_emu8k_pcm *rec = subs->runtime->private_data; in emu8k_pcm_prepare()
568 rec->pitch = 0xe000 + calc_rate_offset(subs->runtime->rate); in emu8k_pcm_prepare()
569 rec->last_ptr = 0; in emu8k_pcm_prepare()
570 rec->period_pos = 0; in emu8k_pcm_prepare()
572 rec->buf_size = subs->runtime->buffer_size; in emu8k_pcm_prepare()
573 rec->period_size = subs->runtime->period_size; in emu8k_pcm_prepare()
574 rec->voices = subs->runtime->channels; in emu8k_pcm_prepare()
575 rec->loop_start[0] = rec->offset + LOOP_BLANK_SIZE; in emu8k_pcm_prepare()
576 if (rec->voices > 1) in emu8k_pcm_prepare()
577 rec->loop_start[1] = rec->loop_start[0] + rec->buf_size + LOOP_BLANK_SIZE; in emu8k_pcm_prepare()
578 if (rec->voices > 1) { in emu8k_pcm_prepare()
579 rec->panning[0] = 0xff; in emu8k_pcm_prepare()
580 rec->panning[1] = 0x00; in emu8k_pcm_prepare()
582 rec->panning[0] = 0x80; in emu8k_pcm_prepare()
584 if (! rec->dram_opened) { in emu8k_pcm_prepare()
587 snd_emux_terminate_all(rec->emu->emu); in emu8k_pcm_prepare()
588 err = emu8k_open_dram_for_pcm(rec->emu, rec->voices); in emu8k_pcm_prepare()
591 rec->dram_opened = 1; in emu8k_pcm_prepare()
594 snd_emu8000_write_wait(rec->emu, 0); in emu8k_pcm_prepare()
595 EMU8000_SMALW_WRITE(rec->emu, rec->offset); in emu8k_pcm_prepare()
597 EMU8000_SMLD_WRITE(rec->emu, 0); in emu8k_pcm_prepare()
598 for (ch = 0; ch < rec->voices; ch++) { in emu8k_pcm_prepare()
599 EMU8000_SMALW_WRITE(rec->emu, rec->loop_start[ch] + rec->buf_size); in emu8k_pcm_prepare()
601 EMU8000_SMLD_WRITE(rec->emu, 0); in emu8k_pcm_prepare()
606 if (rec->voices > 1) in emu8k_pcm_prepare()
613 struct snd_emu8k_pcm *rec = subs->runtime->private_data; in emu8k_pcm_pointer()
614 if (rec->running) in emu8k_pcm_pointer()
635 struct snd_emu8000 *emu = pcm->private_data; in snd_emu8000_pcm_free()
636 emu->pcm = NULL; in snd_emu8000_pcm_free()
647 pcm->private_data = emu; in snd_emu8000_pcm_new()
648 pcm->private_free = snd_emu8000_pcm_free; in snd_emu8000_pcm_new()
650 emu->pcm = pcm; in snd_emu8000_pcm_new()