repo_name
string
dataset
string
owner
string
lang
string
func_name
string
code
string
docstring
string
url
string
sha
string
SBEMU
github_2023
crazii
c
ct_alsa_pcm_create
int ct_alsa_pcm_create(struct ct_atc *atc, enum CTALSADEVS device, const char *device_name) { struct snd_pcm *pcm; const struct snd_pcm_chmap_elem *map; int chs; int err; int playback_count, capture_count; playback_count = (IEC958 == device) ? 1 : 256; capture_count = (FRONT == device) ? 1 : 0; err = snd_pcm_new(atc->card, "ctxfi", device, playback_count, capture_count, &pcm); if (err < 0) { dev_err(atc->card->dev, "snd_pcm_new failed!! Err=%d\n", err); return err; } pcm->private_data = atc; pcm->info_flags = 0; pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX; strlcpy(pcm->name, device_name, sizeof(pcm->name)); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &ct_pcm_playback_ops); if (FRONT == device) snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &ct_pcm_capture_ops); #if 0 // XXX snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV_SG, &atc->pci->dev, 128*1024, 128*1024); #endif chs = 2; switch (device) { case FRONT: chs = 8; map = snd_pcm_std_chmaps; break; case SURROUND: map = surround_map; break; case CLFE: map = clfe_map; break; case SIDE: map = side_map; break; default: map = snd_pcm_std_chmaps; break; } err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK, map, chs, 0, NULL); if (err < 0) return err; #ifdef CONFIG_PM_SLEEP atc->pcms[device] = pcm; #endif return 0; }
/* Create ALSA pcm device */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/ctxfi/ctpcm.c#L423-L488
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
get_resource
static int get_resource(u8 *rscs, unsigned int amount, unsigned int multi, unsigned int *ridx) { int i, j, k, n; /* Check whether there are sufficient resources to meet request. */ for (i = 0, n = multi; i < amount; i++) { j = i / 8; k = i % 8; if (rscs[j] & ((u8)1 << k)) { n = multi; continue; } if (!(--n)) break; /* found sufficient contiguous resources */ } if (i >= amount) { /* Can not find sufficient contiguous resources */ return -ENOENT; } /* Mark the contiguous bits in resource bit-map as used */ for (n = multi; n > 0; n--) { j = i / 8; k = i % 8; rscs[j] |= ((u8)1 << k); i--; } *ridx = i + 1; return 0; }
/* Resource allocation based on bit-map management mechanism */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/ctxfi/ctresource.c#L22-L56
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
srcimp_master
static void srcimp_master(struct rsc *rsc) { rsc->conj = 0; rsc->idx = container_of(rsc, struct srcimp, rsc)->idx[0]; }
/* SRCIMP resource manager operations */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/ctxfi/ctsrc.c#L593-L597
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
ct_systimer_callback
static void ct_systimer_callback(struct timer_list *t) { struct ct_timer_instance *ti = from_timer(ti, t, timer); struct snd_pcm_substream *substream = ti->substream; struct snd_pcm_runtime *runtime = substream->runtime; struct ct_atc_pcm *apcm = ti->apcm; unsigned int period_size = runtime->period_size; unsigned int buffer_size = runtime->buffer_size; unsigned long flags; unsigned int position, dist, interval; position = substream->ops->pointer(substream); dist = (position + buffer_size - ti->position) % buffer_size; if (dist >= period_size || position / period_size != ti->position / period_size) { apcm->interrupt(apcm); ti->position = position; } /* Add extra HZ*5/1000 to avoid overrun issue when recording * at 8kHz in 8-bit format or at 88kHz in 24-bit format. */ interval = ((period_size - (position % period_size)) * HZ + (runtime->rate - 1)) / runtime->rate + HZ * 5 / 1000; spin_lock_irqsave(&ti->lock, flags); if (ti->running) mod_timer(&ti->timer, jiffies + interval); spin_unlock_irqrestore(&ti->lock, flags); }
/* * system-timer-based updates */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/ctxfi/cttimer.c#L63-L89
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
ct_xfitimer_reprogram
static int ct_xfitimer_reprogram(struct ct_timer *atimer, int can_update) { struct ct_timer_instance *ti; unsigned int min_intr = (unsigned int)-1; int updates = 0; unsigned int wc, diff; if (list_empty(&atimer->running_head)) { ct_xfitimer_irq_stop(atimer); atimer->reprogram = 0; /* clear flag */ return 0; } wc = ct_xfitimer_get_wc(atimer); diff = wc - atimer->wc; atimer->wc = wc; list_for_each_entry(ti, &atimer->running_head, running_list) { if (ti->frag_count > diff) ti->frag_count -= diff; else { unsigned int pos; unsigned int period_size, rate; //printk("ti->substream: %8.8X\n", ti->substream); //printk("ti->substream->runtime: %8.8X\n", ti->substream->runtime); //printk("ti->substream->runtime->period_size: %u\n", ti->substream->runtime->period_size); period_size = ti->substream->runtime->period_size; rate = ti->substream->runtime->rate; //printk("ti->substream->runtime->rate: %u\n", rate); //printk("ops: %8.8X\n", ti->substream->ops); //printk("ops->pointer: %8.8X\n", ti->substream->ops->pointer); pos = ti->substream->ops->pointer(ti->substream); if (pos / period_size != ti->position / period_size) { ti->need_update = 1; ti->position = pos; updates++; } pos %= period_size; pos = period_size - pos; ti->frag_count = div_u64((u64)pos * CT_TIMER_FREQ + rate - 1, rate); } if (ti->need_update && !can_update) min_intr = 0; /* pending to the next irq */ if (ti->frag_count < min_intr) min_intr = ti->frag_count; } if (min_intr < MIN_TICKS) min_intr = MIN_TICKS; // Prevent artifacts in Doom min_intr /= 5; if (min_intr <= 0) min_intr = 1; ct_xfitimer_irq_rearm(atimer, min_intr); atimer->reprogram = 0; /* clear flag */ return updates; }
/* * reprogram the timer interval; * checks the running instance list and determines the next timer interval. * also updates the each stream position, returns the number of streams * to call snd_pcm_period_elapsed() appropriately * * call this inside the lock and irq disabled */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/ctxfi/cttimer.c#L179-L235
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
ct_xfitimer_check_period
static void ct_xfitimer_check_period(struct ct_timer *atimer) { struct ct_timer_instance *ti; unsigned long flags; spin_lock_irqsave(&atimer->list_lock, flags); list_for_each_entry(ti, &atimer->instance_head, instance_list) { if (ti->running && ti->need_update) { ti->need_update = 0; ti->apcm->interrupt(ti->apcm); } } spin_unlock_irqrestore(&atimer->list_lock, flags); }
/* look through the instance list and call period_elapsed if needed */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/ctxfi/cttimer.c#L238-L251
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
ct_xfitimer_callback
static void ct_xfitimer_callback(struct ct_timer *atimer) { int update; unsigned long flags; spin_lock_irqsave(&atimer->lock, flags); atimer->irq_handling = 1; do { update = ct_xfitimer_reprogram(atimer, 1); spin_unlock(&atimer->lock); if (update) ct_xfitimer_check_period(atimer); spin_lock(&atimer->lock); } while (atimer->reprogram); atimer->irq_handling = 0; spin_unlock_irqrestore(&atimer->lock, flags); }
/* Handle timer-interrupt */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/ctxfi/cttimer.c#L254-L270
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
ct_xfitimer_update
static void ct_xfitimer_update(struct ct_timer *atimer) { unsigned long flags; spin_lock_irqsave(&atimer->lock, flags); if (atimer->irq_handling) { /* reached from IRQ handler; let it handle later */ atimer->reprogram = 1; spin_unlock_irqrestore(&atimer->lock, flags); return; } ct_xfitimer_irq_stop(atimer); ct_xfitimer_reprogram(atimer, 0); spin_unlock_irqrestore(&atimer->lock, flags); }
/* start/stop the timer */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/ctxfi/cttimer.c#L281-L296
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
ct_timer_interrupt
static void ct_timer_interrupt(void *data, unsigned int status) { struct ct_timer *timer = data; /* Interval timer interrupt */ if ((status & IT_INT) && timer->ops->interrupt) timer->ops->interrupt(timer); }
/* * timer manager */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/ctxfi/cttimer.c#L405-L412
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
ct_get_ptp_phys
static dma_addr_t ct_get_ptp_phys(struct ct_vm *vm, int index) { return (index >= CT_PTP_NUM) ? ~0UL : vm->ptp[index].addr; }
/* * * return the host physical addr of the @index-th device * page table page on success, or ~0UL on failure. * The first returned ~0UL indicates the termination. * */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/ctxfi/ctvmem.c#L166-L170
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
ct_vm_destroy
void ct_vm_destroy(struct ct_vm *vm) { int i; struct list_head *pos; struct ct_vm_block *entry; /* free used and unused list nodes */ while (!list_empty(&vm->used)) { pos = vm->used.next; list_del(pos); entry = list_entry(pos, struct ct_vm_block, list); kfree(entry); } while (!list_empty(&vm->unused)) { pos = vm->unused.next; list_del(pos); entry = list_entry(pos, struct ct_vm_block, list); kfree(entry); } /* free allocated page table pages */ for (i = 0; i < CT_PTP_NUM; i++) snd_dma_free_pages(&vm->ptp[i]); vm->size = 0; kfree(vm); }
/* The caller must ensure no mapping pages are being used * by hardware before calling this function */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/ctxfi/ctvmem.c#L218-L245
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_emu10k1x_playback_open
int snd_emu10k1x_playback_open(struct snd_pcm_substream *substream) { struct emu10k1x *chip = snd_pcm_substream_chip(substream); struct emu10k1x_pcm *epcm; struct snd_pcm_runtime *runtime = substream->runtime; int err; #if 0 err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS); if (err < 0) return err; err = snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 64); if (err < 0) return err; #endif epcm = kzalloc(sizeof(*epcm), GFP_KERNEL); if (epcm == NULL) return -ENOMEM; epcm->emu = chip; epcm->substream = substream; runtime->private_data = epcm; runtime->private_free = snd_emu10k1x_pcm_free_substream; runtime->hw = snd_emu10k1x_playback_hw; return 0; }
/* open callback */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/emu10k1/emu10k1x.c#L368-L396
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_emu10k1x_playback_close
static int snd_emu10k1x_playback_close(struct snd_pcm_substream *substream) { return 0; }
/* close callback */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/emu10k1/emu10k1x.c#L399-L402
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_emu10k1x_pcm_hw_params
int snd_emu10k1x_pcm_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params) { struct snd_pcm_runtime *runtime = substream->runtime; struct emu10k1x_pcm *epcm = runtime->private_data; if (! epcm->voice) { epcm->voice = &epcm->emu->voices[substream->pcm->device]; epcm->voice->use = 1; epcm->voice->epcm = epcm; } return 0; }
/* hw_params callback */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/emu10k1/emu10k1x.c#L405-L418
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_emu10k1x_pcm_hw_free
static int snd_emu10k1x_pcm_hw_free(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; struct emu10k1x_pcm *epcm; if (runtime->private_data == NULL) return 0; epcm = runtime->private_data; if (epcm->voice) { epcm->voice->use = 0; epcm->voice->epcm = NULL; epcm->voice = NULL; } return 0; }
/* hw_free callback */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/emu10k1/emu10k1x.c#L421-L438
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_emu10k1x_pcm_prepare
int snd_emu10k1x_pcm_prepare(struct snd_pcm_substream *substream) { struct emu10k1x *emu = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct emu10k1x_pcm *epcm = runtime->private_data; int voice = epcm->voice->number; u32 *table_base = (u32 *)(emu->dma_buffer->area+1024*voice); u32 period_size_bytes = frames_to_bytes(runtime, runtime->period_size); int i; for(i = 0; i < runtime->periods; i++) { *table_base++=runtime->dma_addr+(i*period_size_bytes); *table_base++=period_size_bytes<<16; } snd_emu10k1x_ptr_write(emu, PLAYBACK_LIST_ADDR, voice, emu->dma_buffer->addr+1024*voice); snd_emu10k1x_ptr_write(emu, PLAYBACK_LIST_SIZE, voice, (runtime->periods - 1) << 19); snd_emu10k1x_ptr_write(emu, PLAYBACK_LIST_PTR, voice, 0); snd_emu10k1x_ptr_write(emu, PLAYBACK_POINTER, voice, 0); snd_emu10k1x_ptr_write(emu, PLAYBACK_UNKNOWN1, voice, 0); snd_emu10k1x_ptr_write(emu, PLAYBACK_UNKNOWN2, voice, 0); snd_emu10k1x_ptr_write(emu, PLAYBACK_DMA_ADDR, voice, runtime->dma_addr); snd_emu10k1x_ptr_write(emu, PLAYBACK_PERIOD_SIZE, voice, frames_to_bytes(runtime, runtime->period_size)<<16); return 0; }
/* prepare callback */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/emu10k1/emu10k1x.c#L441-L467
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_emu10k1x_pcm_trigger
int snd_emu10k1x_pcm_trigger(struct snd_pcm_substream *substream, int cmd) { struct emu10k1x *emu = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct emu10k1x_pcm *epcm = runtime->private_data; int channel = epcm->voice->number; int result = 0; /* dev_dbg(emu->card->dev, "trigger - emu10k1x = 0x%x, cmd = %i, pointer = %d\n", (int)emu, cmd, (int)substream->ops->pointer(substream)); */ switch (cmd) { case SNDRV_PCM_TRIGGER_START: if(runtime->periods == 2) snd_emu10k1x_intr_enable(emu, (INTE_CH_0_LOOP | INTE_CH_0_HALF_LOOP) << channel); else snd_emu10k1x_intr_enable(emu, INTE_CH_0_LOOP << channel); epcm->running = 1; snd_emu10k1x_ptr_write(emu, TRIGGER_CHANNEL, 0, snd_emu10k1x_ptr_read(emu, TRIGGER_CHANNEL, 0)|(TRIGGER_CHANNEL_0<<channel)); break; case SNDRV_PCM_TRIGGER_STOP: epcm->running = 0; snd_emu10k1x_intr_disable(emu, (INTE_CH_0_LOOP | INTE_CH_0_HALF_LOOP) << channel); snd_emu10k1x_ptr_write(emu, TRIGGER_CHANNEL, 0, snd_emu10k1x_ptr_read(emu, TRIGGER_CHANNEL, 0) & ~(TRIGGER_CHANNEL_0<<channel)); break; default: result = -EINVAL; break; } return result; }
/* trigger callback */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/emu10k1/emu10k1x.c#L470-L504
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_emu10k1x_pcm_pointer
snd_pcm_uframes_t snd_emu10k1x_pcm_pointer(struct snd_pcm_substream *substream) { struct emu10k1x *emu = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct emu10k1x_pcm *epcm = runtime->private_data; int channel = epcm->voice->number; snd_pcm_uframes_t ptr = 0, ptr1 = 0, ptr2= 0,ptr3 = 0,ptr4 = 0; if (!epcm->running) return 0; ptr3 = snd_emu10k1x_ptr_read(emu, PLAYBACK_LIST_PTR, channel); ptr1 = snd_emu10k1x_ptr_read(emu, PLAYBACK_POINTER, channel); ptr4 = snd_emu10k1x_ptr_read(emu, PLAYBACK_LIST_PTR, channel); if(ptr4 == 0 && ptr1 == frames_to_bytes(runtime, runtime->buffer_size)) return 0; if (ptr3 != ptr4) ptr1 = snd_emu10k1x_ptr_read(emu, PLAYBACK_POINTER, channel); ptr2 = bytes_to_frames(runtime, ptr1); ptr2 += (ptr4 >> 3) * runtime->period_size; ptr = ptr2; if (ptr >= runtime->buffer_size) ptr -= runtime->buffer_size; return ptr; }
/* pointer callback */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/emu10k1/emu10k1x.c#L507-L536
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_emu10k1x_pcm_open_capture
static int snd_emu10k1x_pcm_open_capture(struct snd_pcm_substream *substream) { struct emu10k1x *chip = snd_pcm_substream_chip(substream); struct emu10k1x_pcm *epcm; struct snd_pcm_runtime *runtime = substream->runtime; int err; #if 0 err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS); if (err < 0) return err; err = snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 64); if (err < 0) return err; #endif epcm = kzalloc(sizeof(*epcm), GFP_KERNEL); if (epcm == NULL) return -ENOMEM; epcm->emu = chip; epcm->substream = substream; runtime->private_data = epcm; runtime->private_free = snd_emu10k1x_pcm_free_substream; runtime->hw = snd_emu10k1x_capture_hw; return 0; }
/* open_capture callback */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/emu10k1/emu10k1x.c#L550-L579
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_emu10k1x_pcm_close_capture
static int snd_emu10k1x_pcm_close_capture(struct snd_pcm_substream *substream) { return 0; }
/* close callback */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/emu10k1/emu10k1x.c#L582-L585
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_emu10k1x_pcm_hw_params_capture
static int snd_emu10k1x_pcm_hw_params_capture(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params) { struct snd_pcm_runtime *runtime = substream->runtime; struct emu10k1x_pcm *epcm = runtime->private_data; if (! epcm->voice) { if (epcm->emu->capture_voice.use) return -EBUSY; epcm->voice = &epcm->emu->capture_voice; epcm->voice->epcm = epcm; epcm->voice->use = 1; } return 0; }
/* hw_params callback */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/emu10k1/emu10k1x.c#L588-L603
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_emu10k1x_pcm_hw_free_capture
static int snd_emu10k1x_pcm_hw_free_capture(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; struct emu10k1x_pcm *epcm; if (runtime->private_data == NULL) return 0; epcm = runtime->private_data; if (epcm->voice) { epcm->voice->use = 0; epcm->voice->epcm = NULL; epcm->voice = NULL; } return 0; }
/* hw_free callback */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/emu10k1/emu10k1x.c#L606-L623
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_emu10k1x_pcm_prepare_capture
static int snd_emu10k1x_pcm_prepare_capture(struct snd_pcm_substream *substream) { struct emu10k1x *emu = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; snd_emu10k1x_ptr_write(emu, CAPTURE_DMA_ADDR, 0, runtime->dma_addr); snd_emu10k1x_ptr_write(emu, CAPTURE_BUFFER_SIZE, 0, frames_to_bytes(runtime, runtime->buffer_size)<<16); // buffer size in bytes snd_emu10k1x_ptr_write(emu, CAPTURE_POINTER, 0, 0); snd_emu10k1x_ptr_write(emu, CAPTURE_UNKNOWN, 0, 0); return 0; }
/* prepare capture callback */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/emu10k1/emu10k1x.c#L626-L637
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_emu10k1x_pcm_trigger_capture
static int snd_emu10k1x_pcm_trigger_capture(struct snd_pcm_substream *substream, int cmd) { struct emu10k1x *emu = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct emu10k1x_pcm *epcm = runtime->private_data; int result = 0; switch (cmd) { case SNDRV_PCM_TRIGGER_START: snd_emu10k1x_intr_enable(emu, INTE_CAP_0_LOOP | INTE_CAP_0_HALF_LOOP); snd_emu10k1x_ptr_write(emu, TRIGGER_CHANNEL, 0, snd_emu10k1x_ptr_read(emu, TRIGGER_CHANNEL, 0)|TRIGGER_CAPTURE); epcm->running = 1; break; case SNDRV_PCM_TRIGGER_STOP: epcm->running = 0; snd_emu10k1x_intr_disable(emu, INTE_CAP_0_LOOP | INTE_CAP_0_HALF_LOOP); snd_emu10k1x_ptr_write(emu, TRIGGER_CHANNEL, 0, snd_emu10k1x_ptr_read(emu, TRIGGER_CHANNEL, 0) & ~(TRIGGER_CAPTURE)); break; default: result = -EINVAL; break; } return result; }
/* trigger_capture callback */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/emu10k1/emu10k1x.c#L640-L666
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_emu10k1x_pcm_pointer_capture
static snd_pcm_uframes_t snd_emu10k1x_pcm_pointer_capture(struct snd_pcm_substream *substream) { struct emu10k1x *emu = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct emu10k1x_pcm *epcm = runtime->private_data; snd_pcm_uframes_t ptr; if (!epcm->running) return 0; ptr = bytes_to_frames(runtime, snd_emu10k1x_ptr_read(emu, CAPTURE_POINTER, 0)); if (ptr >= runtime->buffer_size) ptr -= runtime->buffer_size; return ptr; }
/* pointer_capture callback */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/emu10k1/emu10k1x.c#L669-L685
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
do_emu10k1x_midi_interrupt
static void do_emu10k1x_midi_interrupt(struct emu10k1x *emu, struct emu10k1x_midi *midi, unsigned int status) { unsigned char byte; if (midi->rmidi == NULL) { snd_emu10k1x_intr_disable(emu, midi->tx_enable | midi->rx_enable); return; } spin_lock(&midi->input_lock); if ((status & midi->ipr_rx) && mpu401_input_avail(emu, midi)) { if (!(midi->midi_mode & EMU10K1X_MIDI_MODE_INPUT)) { mpu401_clear_rx(emu, midi); } else { byte = mpu401_read_data(emu, midi); if (midi->substream_input) snd_rawmidi_receive(midi->substream_input, &byte, 1); } } spin_unlock(&midi->input_lock); spin_lock(&midi->output_lock); if ((status & midi->ipr_tx) && mpu401_output_ready(emu, midi)) { if (midi->substream_output && snd_rawmidi_transmit(midi->substream_output, &byte, 1) == 1) { mpu401_write_data(emu, midi, byte); } else { snd_emu10k1x_intr_disable(emu, midi->tx_enable); } } spin_unlock(&midi->output_lock); }
/* */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/emu10k1/emu10k1x.c#L1235-L1267
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_m3_outw
static inline void snd_m3_outw(struct snd_m3 *chip, u16 value, unsigned long reg) { outw(value, chip->iobase + reg); }
/* * lowlevel functions */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/maestro3/maestro3.c#L202-L205
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_m3_assp_read
static u16 snd_m3_assp_read(struct snd_m3 *chip, u16 region, u16 index) { snd_m3_outw(chip, region & MEMTYPE_MASK, DSP_PORT_MEMORY_TYPE); snd_m3_outw(chip, index, DSP_PORT_MEMORY_INDEX); return snd_m3_inw(chip, DSP_PORT_MEMORY_DATA); }
/* * access 16bit words to the code or data regions of the dsp's memory. * index addresses 16bit words. */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/maestro3/maestro3.c#L226-L231
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_m3_add_list
static int snd_m3_add_list(struct snd_m3 *chip, struct m3_list *list, u16 val) { snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, list->mem_addr + list->curlen, val); return list->curlen++; }
/* * This makes me sad. the maestro3 has lists * internally that must be packed.. 0 terminates, * apparently, or maybe all unused entries have * to be 0, the lists have static lengths set * by the binary code images. */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/maestro3/maestro3.c#L261-L267
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_m3_pcm_start
static int snd_m3_pcm_start(struct snd_m3 *chip, struct m3_dma *s, struct snd_pcm_substream *subs) { if (! s || ! subs) return -EINVAL; snd_m3_inc_timer_users(chip); switch (subs->stream) { case SNDRV_PCM_STREAM_PLAYBACK: chip->dacs_active++; snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, s->inst.data + CDATA_INSTANCE_READY, 1); snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, KDATA_MIXER_TASK_NUMBER, chip->dacs_active); break; case SNDRV_PCM_STREAM_CAPTURE: snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, KDATA_ADC1_REQUEST, 1); snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, s->inst.data + CDATA_INSTANCE_READY, 1); break; } return 0; }
/* * start/stop */ /* spinlock held! */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/maestro3/maestro3.c#L334-L358
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_m3_pcm_stop
static int snd_m3_pcm_stop(struct snd_m3 *chip, struct m3_dma *s, struct snd_pcm_substream *subs) { if (! s || ! subs) return -EINVAL; snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, s->inst.data + CDATA_INSTANCE_READY, 0); snd_m3_dec_timer_users(chip); switch (subs->stream) { case SNDRV_PCM_STREAM_PLAYBACK: chip->dacs_active--; snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, KDATA_MIXER_TASK_NUMBER, chip->dacs_active); break; case SNDRV_PCM_STREAM_CAPTURE: snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, KDATA_ADC1_REQUEST, 0); break; } return 0; }
/* spinlock held! */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/maestro3/maestro3.c#L361-L383
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_m3_pcm_setup1
static void snd_m3_pcm_setup1(struct snd_m3 *chip, struct m3_dma *s, struct snd_pcm_substream *subs) { int dsp_in_size, dsp_out_size, dsp_in_buffer, dsp_out_buffer; struct snd_pcm_runtime *runtime = subs->runtime; if (subs->stream == SNDRV_PCM_STREAM_PLAYBACK) { dsp_in_size = MINISRC_IN_BUFFER_SIZE - (0x20 * 2); dsp_out_size = MINISRC_OUT_BUFFER_SIZE - (0x20 * 2); } else { dsp_in_size = MINISRC_IN_BUFFER_SIZE - (0x10 * 2); dsp_out_size = MINISRC_OUT_BUFFER_SIZE - (0x10 * 2); } dsp_in_buffer = s->inst.data + (MINISRC_TMP_BUFFER_SIZE / 2); dsp_out_buffer = dsp_in_buffer + (dsp_in_size / 2) + 1; s->dma_size = frames_to_bytes(runtime, runtime->buffer_size); s->period_size = frames_to_bytes(runtime, runtime->period_size); s->hwptr = 0; s->count = 0; #define LO(x) ((x) & 0xffff) #define HI(x) LO((x) >> 16) /* host dma buffer pointers */ snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, s->inst.data + CDATA_HOST_SRC_ADDRL, LO(s->buffer_addr)); snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, s->inst.data + CDATA_HOST_SRC_ADDRH, HI(s->buffer_addr)); snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, s->inst.data + CDATA_HOST_SRC_END_PLUS_1L, LO(s->buffer_addr + s->dma_size)); snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, s->inst.data + CDATA_HOST_SRC_END_PLUS_1H, HI(s->buffer_addr + s->dma_size)); snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, s->inst.data + CDATA_HOST_SRC_CURRENTL, LO(s->buffer_addr)); snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, s->inst.data + CDATA_HOST_SRC_CURRENTH, HI(s->buffer_addr)); #undef LO #undef HI /* dsp buffers */ snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, s->inst.data + CDATA_IN_BUF_BEGIN, dsp_in_buffer); snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, s->inst.data + CDATA_IN_BUF_END_PLUS_1, dsp_in_buffer + (dsp_in_size / 2)); snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, s->inst.data + CDATA_IN_BUF_HEAD, dsp_in_buffer); snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, s->inst.data + CDATA_IN_BUF_TAIL, dsp_in_buffer); snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, s->inst.data + CDATA_OUT_BUF_BEGIN, dsp_out_buffer); snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, s->inst.data + CDATA_OUT_BUF_END_PLUS_1, dsp_out_buffer + (dsp_out_size / 2)); snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, s->inst.data + CDATA_OUT_BUF_HEAD, dsp_out_buffer); snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, s->inst.data + CDATA_OUT_BUF_TAIL, dsp_out_buffer); }
/* * setup */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/maestro3/maestro3.c#L423-L506
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_m3_playback_setup
static void snd_m3_playback_setup(struct snd_m3 *chip, struct m3_dma *s, struct snd_pcm_substream *subs) { unsigned int i; /* * some per client initializers */ snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, s->inst.data + SRC3_DIRECTION_OFFSET + 12, s->inst.data + 40 + 8); snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, s->inst.data + SRC3_DIRECTION_OFFSET + 19, s->inst.code + MINISRC_COEF_LOC); /* enable or disable low pass filter? */ snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, s->inst.data + SRC3_DIRECTION_OFFSET + 22, subs->runtime->rate > 45000 ? 0xff : 0); /* tell it which way dma is going? */ snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, s->inst.data + CDATA_DMA_CONTROL, DMACONTROL_AUTOREPEAT + DMAC_PAGE3_SELECTOR + DMAC_BLOCKF_SELECTOR); /* * set an armload of static initializers */ for (i = 0; i < ARRAY_SIZE(pv); i++) snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, s->inst.data + pv[i].addr, pv[i].val); }
/* the mode passed should be already shifted and masked */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/maestro3/maestro3.c#L575-L609
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_m3_get_pointer
static unsigned int snd_m3_get_pointer(struct snd_m3 *chip, struct m3_dma *s, struct snd_pcm_substream *subs) { u16 hi = 0, lo = 0; int retry = 10; u32 addr; /* * try and get a valid answer */ while (retry--) { hi = snd_m3_assp_read(chip, MEMTYPE_INTERNAL_DATA, s->inst.data + CDATA_HOST_SRC_CURRENTH); lo = snd_m3_assp_read(chip, MEMTYPE_INTERNAL_DATA, s->inst.data + CDATA_HOST_SRC_CURRENTL); if (hi == snd_m3_assp_read(chip, MEMTYPE_INTERNAL_DATA, s->inst.data + CDATA_HOST_SRC_CURRENTH)) break; } addr = lo | ((u32)hi<<16); return (unsigned int)(addr - s->buffer_addr); }
/* * get current pointer */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/maestro3/maestro3.c#L730-L753
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_m3_update_ptr
static void snd_m3_update_ptr(struct snd_m3 *chip, struct m3_dma *s) { struct snd_pcm_substream *subs = s->substream; unsigned int hwptr; int diff; if (! s->running) return; hwptr = snd_m3_get_pointer(chip, s, subs); /* try to avoid expensive modulo divisions */ if (hwptr >= s->dma_size) hwptr %= s->dma_size; diff = s->dma_size + hwptr - s->hwptr; if (diff >= s->dma_size) diff %= s->dma_size; s->hwptr = hwptr; s->count += diff; if (s->count >= (signed)s->period_size) { if (s->count < 2 * (signed)s->period_size) s->count -= (signed)s->period_size; else s->count %= s->period_size; #if 0 spin_unlock(&chip->reg_lock); snd_pcm_period_elapsed(subs); spin_lock(&chip->reg_lock); #endif } }
/* update pointer */ /* spinlock held! */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/maestro3/maestro3.c#L774-L808
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_m3_update_hw_volume
static void snd_m3_update_hw_volume (struct snd_m3 *chip) // (struct work_struct *work) { //struct snd_m3 *chip = container_of(work, struct snd_m3, hwvol_work); int x, val; /* Figure out which volume control button was pushed, based on differences from the default register values. */ x = inb(chip->iobase + SHADOW_MIX_REG_VOICE) & 0xee; /* Reset the volume counters to 4. Tests on the allegro integrated into a Compaq N600C laptop, have revealed that: 1) Writing any value will result in the 2 counters being reset to 4 so writing 0x88 is not strictly necessary 2) Writing to any of the 4 involved registers will reset all 4 of them (and reading them always returns the same value for all of them) It could be that a maestro deviates from this, so leave the code as is. */ outb(0x88, chip->iobase + SHADOW_MIX_REG_VOICE); outb(0x88, chip->iobase + HW_VOL_COUNTER_VOICE); outb(0x88, chip->iobase + SHADOW_MIX_REG_MASTER); outb(0x88, chip->iobase + HW_VOL_COUNTER_MASTER); /* Ignore spurious HV interrupts during suspend / resume, this avoids mistaking them for a mute button press. */ if (chip->in_suspend) return; #ifndef CONFIG_SND_MAESTRO3_INPUT if (!chip->master_switch || !chip->master_volume) return; val = snd_m3_ac97_read(chip->ac97, AC97_MASTER); switch (x) { case 0x88: /* The counters have not changed, yet we've received a HV interrupt. According to tests run by various people this happens when pressing the mute button. */ val ^= 0x8000; break; case 0xaa: /* counters increased by 1 -> volume up */ if ((val & 0x7f) > 0) val--; if ((val & 0x7f00) > 0) val -= 0x0100; break; case 0x66: /* counters decreased by 1 -> volume down */ if ((val & 0x7f) < 0x1f) val++; if ((val & 0x7f00) < 0x1f00) val += 0x0100; break; } #if 0 if (snd_ac97_update(chip->ac97, AC97_MASTER, val)) snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->master_switch->id); #endif snd_m3_ac97_write(chip->ac97, AC97_MASTER, val); #else if (!chip->input_dev) return; val = 0; switch (x) { case 0x88: /* The counters have not changed, yet we've received a HV interrupt. According to tests run by various people this happens when pressing the mute button. */ val = KEY_MUTE; break; case 0xaa: /* counters increased by 1 -> volume up */ val = KEY_VOLUMEUP; break; case 0x66: /* counters decreased by 1 -> volume down */ val = KEY_VOLUMEDOWN; break; } if (val) { input_report_key(chip->input_dev, val, 1); input_sync(chip->input_dev); input_report_key(chip->input_dev, val, 0); input_sync(chip->input_dev); } #endif }
/* The m3's hardware volume works by incrementing / decrementing 2 counters (without wrap around) in response to volume button presses and then generating an interrupt. The pair of counters is stored in bits 1-3 and 5-7 of a byte wide register. The meaning of bits 0 and 4 is unknown. */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/maestro3/maestro3.c#L818-L909
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_m3_substream_open
static int snd_m3_substream_open(struct snd_m3 *chip, struct snd_pcm_substream *subs) { int i; struct m3_dma *s; spin_lock_irq(&chip->reg_lock); for (i = 0; i < chip->num_substreams; i++) { s = &chip->substreams[i]; if (! s->opened) goto __found; } spin_unlock_irq(&chip->reg_lock); return -ENOMEM; __found: s->opened = 1; s->running = 0; spin_unlock_irq(&chip->reg_lock); subs->runtime->private_data = s; s->substream = subs; /* set list owners */ if (subs->stream == SNDRV_PCM_STREAM_PLAYBACK) { s->index_list[0] = &chip->mixer_list; } else s->index_list[0] = &chip->adc1_list; s->index_list[1] = &chip->msrc_list; s->index_list[2] = &chip->dma_list; return 0; }
/* */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/maestro3/maestro3.c#L1020-L1051
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_m3_ac97_wait
static int snd_m3_ac97_wait(struct snd_m3 *chip) { int i = 10000; do { if (! (snd_m3_inb(chip, 0x30) & 1)) return 0; cpu_relax(); } while (i-- > 0); dev_err(chip->card->dev, "ac97 serial bus busy\n"); return 1; }
/* * ac97 interface */ /* * Wait for the ac97 serial bus to be free. * return nonzero if the bus is still busy. */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/maestro3/maestro3.c#L1185-L1197
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_m3_try_read_vendor
static int snd_m3_try_read_vendor(struct snd_m3 *chip) { u16 ret; if (snd_m3_ac97_wait(chip)) return 1; //printk("wait ok\n"); snd_m3_outb(chip, 0x80 | (AC97_VENDOR_ID1 & 0x7f), 0x30); if (snd_m3_ac97_wait(chip)) return 1; ret = snd_m3_inw(chip, 0x32); //printk("ac97 vendor: %4.4X\n", ret); return (ret == 0) || (ret == 0xffff); }
/* * hack, returns non zero on err */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/maestro3/maestro3.c#L1304-L1321
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_m3_amp_enable
static void snd_m3_amp_enable(struct snd_m3 *chip, int enable) { int io = chip->iobase; u16 gpo, polarity; if (! chip->external_amp) return; polarity = enable ? 0 : 1; polarity = polarity << chip->amp_gpio; gpo = 1 << chip->amp_gpio; outw(~gpo, io + GPIO_MASK); outw(inw(io + GPIO_DIRECTION) | gpo, io + GPIO_DIRECTION); outw((GPO_SECONDARY_AC97 | GPO_PRIMARY_AC97 | polarity), io + GPIO_DATA); outw(0xffff, io + GPIO_MASK); }
/* * this works for the reference board, have to find * out about others * * this needs more magic for 4 speaker, but.. */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/maestro3/maestro3.c#L1599-L1621
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_m3_free
static void snd_m3_free(struct snd_card *card) { struct snd_m3 *chip = card->private_data; struct m3_dma *s; int i; #if 0 cancel_work_sync(&chip->hwvol_work); #endif if (chip->substreams) { spin_lock_irq(&chip->reg_lock); for (i = 0; i < chip->num_substreams; i++) { s = &chip->substreams[i]; /* check surviving pcms; this should not happen though.. */ if (s->substream && s->running) snd_m3_pcm_stop(chip, s, s->substream); } spin_unlock_irq(&chip->reg_lock); } if (chip->iobase) { outw(0, chip->iobase + HOST_INT_CTRL); /* disable ints */ } #ifdef CONFIG_PM_SLEEP vfree(chip->suspend_mem); #endif #if 0 release_firmware(chip->assp_kernel_image); release_firmware(chip->assp_minisrc_image); #endif if (chip->ac97) kfree(chip->ac97); }
/* */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/maestro3/maestro3.c#L1751-L1783
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_m3_probe
int snd_m3_probe (struct snd_card *card, struct pci_dev *pci, int probe_only, int spdif, int enable_amp, int amp_gpio) { struct snd_m3 *chip; int i, err; u32 iobase; const struct snd_pci_quirk *quirk; if (pcim_enable_device(pci)) return -EIO; /* check, if we can restrict PCI DMA transfers to 28 bits */ if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(28))) { dev_err(card->dev, "architecture does not support 28bit PCI busmaster DMA\n"); return -ENXIO; } iobase = pci_resource_start(pci, 0); if (!iobase) return -EIO; chip = kzalloc(sizeof(*chip), GFP_KERNEL); if (!chip) { err = -ENOMEM; goto err; } //chip->probe_only = probe_only ? 1 : 0; card->private_data = chip; spin_lock_init(&chip->reg_lock); switch (pci->device) { case PCI_DEVICE_ID_ESS_ALLEGRO: case PCI_DEVICE_ID_ESS_ALLEGRO_1: case PCI_DEVICE_ID_ESS_CANYON3D_2LE: case PCI_DEVICE_ID_ESS_CANYON3D_2: chip->allegro_flag = 1; break; } //printk("allegro_flag: %d\n", chip->allegro_flag); chip->card = card; chip->pci = pci; chip->irq = -1; #if 0 INIT_WORK(&chip->hwvol_work, snd_m3_update_hw_volume); #endif //snd_m3_update_hw_volume(chip); card->private_free = snd_m3_free; chip->external_amp = enable_amp; if (amp_gpio >= 0 && amp_gpio <= 0x0f) chip->amp_gpio = amp_gpio; else { quirk = snd_pci_quirk_lookup(pci, m3_amp_quirk_list); if (quirk) { dev_info(card->dev, "set amp-gpio for '%s'\n", snd_pci_quirk_name(quirk)); chip->amp_gpio = quirk->value; } else if (chip->allegro_flag) chip->amp_gpio = GPO_EXT_AMP_ALLEGRO; else /* presumably this is for all 'maestro3's.. */ chip->amp_gpio = GPO_EXT_AMP_M3; } quirk = snd_pci_quirk_lookup(pci, m3_irda_quirk_list); if (quirk) { dev_info(card->dev, "enabled irda workaround for '%s'\n", snd_pci_quirk_name(quirk)); chip->irda_workaround = 1; } quirk = snd_pci_quirk_lookup(pci, m3_hv_quirk_list); if (quirk) chip->hv_config = quirk->value; if (snd_pci_quirk_lookup(pci, m3_omnibook_quirk_list)) chip->is_omnibook = 1; chip->num_substreams = NR_DSPS; chip->substreams = devm_kcalloc(&pci->dev, chip->num_substreams, sizeof(struct m3_dma), GFP_KERNEL); if (!chip->substreams) { err = -ENOMEM; goto err; } #if 0 err = request_firmware(&chip->assp_kernel_image, "ess/maestro3_assp_kernel.fw", &pci->dev); if (err < 0) return err; err = request_firmware(&chip->assp_minisrc_image, "ess/maestro3_assp_minisrc.fw", &pci->dev); if (err < 0) return err; #endif err = pci_request_regions(pci, card->driver); if (err < 0) goto err; chip->iobase = iobase; /* just to be sure */ pci_set_master(pci); snd_m3_chip_init(chip, spdif); snd_m3_assp_halt(chip); if (!probe_only) snd_m3_ac97_reset(chip); snd_m3_amp_enable(chip, 1); snd_m3_hv_init(chip); #if 0 if (devm_request_irq(&pci->dev, pci->irq, snd_m3_interrupt, IRQF_SHARED, KBUILD_MODNAME, chip)) { dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq); return -ENOMEM; } #endif chip->irq = pci->irq; card->sync_irq = chip->irq; #ifdef CONFIG_PM_SLEEP chip->suspend_mem = vmalloc(array_size(sizeof(u16), REV_B_CODE_MEMORY_LENGTH + REV_B_DATA_MEMORY_LENGTH)); if (chip->suspend_mem == NULL) dev_warn(card->dev, "can't allocate apm buffer\n"); #endif err = snd_m3_mixer(chip); if (err < 0) goto err; for (i = 0; i < chip->num_substreams; i++) { struct m3_dma *s = &chip->substreams[i]; err = snd_m3_assp_client_init(chip, s, i); if (err < 0) goto err; } #if 0 err = snd_m3_pcm(chip, 0); if (err < 0) goto err; #ifdef CONFIG_SND_MAESTRO3_INPUT if (chip->hv_config & HV_CTRL_ENABLE) { err = snd_m3_input_register(chip); if (err) dev_warn(card->dev, "Input device registration failed with error %i", err); } #endif #endif snd_m3_enable_ints(chip); snd_m3_assp_continue(chip); return 0; err: if (chip) { if (chip->substreams) devm_kfree(dev, chip->substreams); devm_kfree(dev, chip); card->private_data = NULL; } return err; }
/* CONFIG_INPUT */ /* */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/maestro3/maestro3.c#L1906-L2082
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
__snd_m3_probe
static int __snd_m3_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) { static int dev; struct snd_card *card; struct snd_m3 *chip; int err; /* don't pick up modems */ if (((pci->class >> 8) & 0xffff) != PCI_CLASS_MULTIMEDIA_AUDIO) return -ENODEV; if (dev >= SNDRV_CARDS) return -ENODEV; if (!enable[dev]) { dev++; return -ENOENT; } err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, sizeof(*chip), &card); if (err < 0) return err; chip = card->private_data; switch (pci->device) { case PCI_DEVICE_ID_ESS_ALLEGRO: case PCI_DEVICE_ID_ESS_ALLEGRO_1: strcpy(card->driver, "Allegro"); break; case PCI_DEVICE_ID_ESS_CANYON3D_2LE: case PCI_DEVICE_ID_ESS_CANYON3D_2: strcpy(card->driver, "Canyon3D-2"); break; default: strcpy(card->driver, "Maestro3"); break; } err = snd_m3_create(card, pci, external_amp[dev], amp_gpio[dev]); if (err < 0) return err; sprintf(card->shortname, "ESS %s PCI", card->driver); sprintf(card->longname, "%s at 0x%lx, irq %d", card->shortname, chip->iobase, chip->irq); err = snd_card_register(card); if (err < 0) return err; #if 0 /* TODO: not supported yet */ /* TODO enable MIDI IRQ and I/O */ err = snd_mpu401_uart_new(chip->card, 0, MPU401_HW_MPU401, chip->iobase + MPU401_DATA_PORT, MPU401_INFO_INTEGRATED | MPU401_INFO_IRQ_HOOK, -1, &chip->rmidi); if (err < 0) dev_warn(card->dev, "no MIDI support.\n"); #endif pci_set_drvdata(pci, card); dev++; return 0; }
/* */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/maestro3/maestro3.c#L2087-L2151
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
oxygen_write_ac97
void oxygen_write_ac97(struct oxygen *chip, unsigned int codec, unsigned int index, u16 data) { unsigned int count, succeeded; u32 reg; reg = data; reg |= index << OXYGEN_AC97_REG_ADDR_SHIFT; reg |= OXYGEN_AC97_REG_DIR_WRITE; reg |= codec << OXYGEN_AC97_REG_CODEC_SHIFT; succeeded = 0; for (count = 5; count > 0; --count) { udelay(5); oxygen_write32(chip, OXYGEN_AC97_REGS, reg); /* require two "completed" writes, just to be sure */ if (oxygen_ac97_wait(chip, OXYGEN_AC97_INT_WRITE_DONE) >= 0 && ++succeeded >= 2) { chip->saved_ac97_registers[codec][index / 2] = data; return; } } dev_err(chip->card->dev, "AC'97 write timeout\n"); }
/* * About 10% of AC'97 register reads or writes fail to complete, but even those * where the controller indicates completion aren't guaranteed to have actually * happened. * * It's hard to assign blame to either the controller or the codec because both * were made by C-Media ... */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/oxygen/oxygen_io.c#L124-L146
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
oxygen_pci_shutdown
void oxygen_pci_shutdown(struct pci_dev *pci) { struct snd_card *card = pci_get_drvdata(pci); struct oxygen *chip = card->private_data; oxygen_shutdown(chip); chip->model.cleanup(chip); }
/* CONFIG_PM_SLEEP */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/oxygen/oxygen_lib.c#L838-L845
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
output_select_apply
static int output_select_apply(struct oxygen *chip) { struct dg *data = chip->model_data; data->cs4245_shadow[CS4245_SIGNAL_SEL] &= ~CS4245_A_OUT_SEL_MASK; if (data->output_sel == PLAYBACK_DST_HP) { /* mute FP (aux output) amplifier, switch rear jack to CS4245 */ oxygen_set_bits8(chip, OXYGEN_GPIO_DATA, GPIO_HP_REAR); } else if (data->output_sel == PLAYBACK_DST_HP_FP) { /* * Unmute FP amplifier, switch rear jack to CS4361; * I2S channels 2,3,4 should be inactive. */ oxygen_clear_bits8(chip, OXYGEN_GPIO_DATA, GPIO_HP_REAR); data->cs4245_shadow[CS4245_SIGNAL_SEL] |= CS4245_A_OUT_SEL_DAC; } else { /* * 2.0, 4.0, 5.1: switch to CS4361, mute FP amp., * and change playback routing. */ oxygen_clear_bits8(chip, OXYGEN_GPIO_DATA, GPIO_HP_REAR); } return cs4245_write_spi(chip, CS4245_SIGNAL_SEL); }
/* analog output select */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/oxygen/xonar_dg_mixer.c#L22-L45
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
hp_stereo_volume_info
static int hp_stereo_volume_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info) { info->type = SNDRV_CTL_ELEM_TYPE_INTEGER; info->count = 2; info->value.integer.min = 0; info->value.integer.max = 255; return 0; }
/* CS4245 Headphone Channels A&B Volume Control */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/oxygen/xonar_dg_mixer.c#L94-L102
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
hp_mute_get
static int hp_mute_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *val) { struct oxygen *chip = ctl->private_data; struct dg *data = chip->model_data; mutex_lock(&chip->mutex); val->value.integer.value[0] = !(data->cs4245_shadow[CS4245_DAC_CTRL_1] & CS4245_MUTE_DAC); mutex_unlock(&chip->mutex); return 0; }
/* Headphone Mute */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/oxygen/xonar_dg_mixer.c#L194-L205
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
input_volume_apply
static int input_volume_apply(struct oxygen *chip, char left, char right) { struct dg *data = chip->model_data; int ret; data->cs4245_shadow[CS4245_PGA_A_CTRL] = left; data->cs4245_shadow[CS4245_PGA_B_CTRL] = right; ret = cs4245_write_spi(chip, CS4245_PGA_A_CTRL); if (ret < 0) return ret; return cs4245_write_spi(chip, CS4245_PGA_B_CTRL); }
/* capture volume for all sources */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/oxygen/xonar_dg_mixer.c#L229-L240
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
input_source_apply
static int input_source_apply(struct oxygen *chip) { struct dg *data = chip->model_data; data->cs4245_shadow[CS4245_ANALOG_IN] &= ~CS4245_SEL_MASK; if (data->input_sel == CAPTURE_SRC_FP_MIC) data->cs4245_shadow[CS4245_ANALOG_IN] |= CS4245_SEL_INPUT_2; else if (data->input_sel == CAPTURE_SRC_LINE) data->cs4245_shadow[CS4245_ANALOG_IN] |= CS4245_SEL_INPUT_4; else if (data->input_sel != CAPTURE_SRC_MIC) data->cs4245_shadow[CS4245_ANALOG_IN] |= CS4245_SEL_INPUT_1; return cs4245_write_spi(chip, CS4245_ANALOG_IN); }
/* Capture Source */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/oxygen/xonar_dg_mixer.c#L299-L311
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
hpf_info
static int hpf_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info) { static const char *const names[2] = { "Active", "Frozen" }; return snd_ctl_enum_info(info, 1, 2, names); }
/* ADC high-pass filter */
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/oxygen/xonar_dg_mixer.c#L364-L369
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_codec_read
static unsigned short snd_trident_codec_read(struct snd_ac97 *ac97, unsigned short reg) { unsigned int data = 0, treg; unsigned short count = 0xffff; unsigned long flags; struct snd_trident *trident = ac97->private_data; spin_lock_irqsave(&trident->reg_lock, flags); if (trident->device == TRIDENT_DEVICE_ID_DX) { data = (DX_AC97_BUSY_READ | (reg & 0x000000ff)); outl(data, TRID_REG(trident, DX_ACR1_AC97_R)); do { data = inl(TRID_REG(trident, DX_ACR1_AC97_R)); if ((data & DX_AC97_BUSY_READ) == 0) break; } while (--count); } else if (trident->device == TRIDENT_DEVICE_ID_NX) { data = (NX_AC97_BUSY_READ | (reg & 0x000000ff)); treg = ac97->num == 0 ? NX_ACR2_AC97_R_PRIMARY : NX_ACR3_AC97_R_SECONDARY; outl(data, TRID_REG(trident, treg)); do { data = inl(TRID_REG(trident, treg)); if ((data & 0x00000C00) == 0) break; } while (--count); } else if (trident->device == TRIDENT_DEVICE_ID_SI7018) { data = SI_AC97_BUSY_READ | SI_AC97_AUDIO_BUSY | (reg & 0x000000ff); if (ac97->num == 1) data |= SI_AC97_SECONDARY; outl(data, TRID_REG(trident, SI_AC97_READ)); do { data = inl(TRID_REG(trident, SI_AC97_READ)); if ((data & (SI_AC97_BUSY_READ)) == 0) break; } while (--count); } if (count == 0 && !trident->ac97_detect) { dev_err(trident->card->dev, "ac97 codec read TIMEOUT [0x%x/0x%x]!!!\n", reg, data); data = 0; } spin_unlock_irqrestore(&trident->reg_lock, flags); return ((unsigned short) (data >> 16)); }
/*--------------------------------------------------------------------------- unsigned short snd_trident_codec_read(struct snd_ac97 *ac97, unsigned short reg) Description: This routine will do all of the reading from the external CODEC (AC97). Parameters: ac97 - ac97 codec structure reg - CODEC register index, from AC97 Hal. returns: 16 bit value read from the AC97. ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L124-L170
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_codec_write
static void snd_trident_codec_write(struct snd_ac97 *ac97, unsigned short reg, unsigned short wdata) { unsigned int address, data; unsigned short count = 0xffff; unsigned long flags; struct snd_trident *trident = ac97->private_data; data = ((unsigned long) wdata) << 16; spin_lock_irqsave(&trident->reg_lock, flags); if (trident->device == TRIDENT_DEVICE_ID_DX) { address = DX_ACR0_AC97_W; /* read AC-97 write register status */ do { if ((inw(TRID_REG(trident, address)) & DX_AC97_BUSY_WRITE) == 0) break; } while (--count); data |= (DX_AC97_BUSY_WRITE | (reg & 0x000000ff)); } else if (trident->device == TRIDENT_DEVICE_ID_NX) { address = NX_ACR1_AC97_W; /* read AC-97 write register status */ do { if ((inw(TRID_REG(trident, address)) & NX_AC97_BUSY_WRITE) == 0) break; } while (--count); data |= (NX_AC97_BUSY_WRITE | (ac97->num << 8) | (reg & 0x000000ff)); } else if (trident->device == TRIDENT_DEVICE_ID_SI7018) { address = SI_AC97_WRITE; /* read AC-97 write register status */ do { if ((inw(TRID_REG(trident, address)) & (SI_AC97_BUSY_WRITE)) == 0) break; } while (--count); data |= SI_AC97_BUSY_WRITE | SI_AC97_AUDIO_BUSY | (reg & 0x000000ff); if (ac97->num == 1) data |= SI_AC97_SECONDARY; } else { address = 0; /* keep GCC happy */ count = 0; /* return */ } if (count == 0) { spin_unlock_irqrestore(&trident->reg_lock, flags); return; } outl(data, TRID_REG(trident, address)); spin_unlock_irqrestore(&trident->reg_lock, flags); }
/*--------------------------------------------------------------------------- void snd_trident_codec_write(struct snd_ac97 *ac97, unsigned short reg, unsigned short wdata) Description: This routine will do all of the writing to the external CODEC (AC97). Parameters: ac97 - ac97 codec structure reg - CODEC register index, from AC97 Hal. data - Lower 16 bits are the data to write to CODEC. returns: TRUE if everything went ok, else FALSE. ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L186-L240
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_enable_eso
static void snd_trident_enable_eso(struct snd_trident * trident) { unsigned int val; val = inl(TRID_REG(trident, T4D_LFO_GC_CIR)); val |= ENDLP_IE; val |= MIDLP_IE; if (trident->device == TRIDENT_DEVICE_ID_SI7018) val |= BANK_B_EN; outl(val, TRID_REG(trident, T4D_LFO_GC_CIR)); }
/*--------------------------------------------------------------------------- void snd_trident_enable_eso(struct snd_trident *trident) Description: This routine will enable end of loop interrupts. End of loop interrupts will occur when a running channel reaches ESO. Also enables middle of loop interrupts. Parameters: trident - pointer to target device class for 4DWave. ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L307-L317
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_disable_eso
static void snd_trident_disable_eso(struct snd_trident * trident) { unsigned int tmp; tmp = inl(TRID_REG(trident, T4D_LFO_GC_CIR)); tmp &= ~ENDLP_IE; tmp &= ~MIDLP_IE; outl(tmp, TRID_REG(trident, T4D_LFO_GC_CIR)); }
/*--------------------------------------------------------------------------- void snd_trident_disable_eso(struct snd_trident *trident) Description: This routine will disable end of loop interrupts. End of loop interrupts will occur when a running channel reaches ESO. Also disables middle of loop interrupts. Parameters: trident - pointer to target device class for 4DWave. returns: TRUE if everything went ok, else FALSE. ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L334-L342
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_start_voice
void snd_trident_start_voice(struct snd_trident * trident, unsigned int voice) { unsigned int mask = 1 << (voice & 0x1f); unsigned int reg = (voice & 0x20) ? T4D_START_B : T4D_START_A; outl(mask, TRID_REG(trident, reg)); }
/*--------------------------------------------------------------------------- void snd_trident_start_voice(struct snd_trident * trident, unsigned int voice) Description: Start a voice, any channel 0 thru 63. This routine automatically handles the fact that there are more than 32 channels available. Parameters : voice - Voice number 0 thru n. trident - pointer to target device class for 4DWave. Return Value: None. ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L358-L364
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_stop_voice
void snd_trident_stop_voice(struct snd_trident * trident, unsigned int voice) { unsigned int mask = 1 << (voice & 0x1f); unsigned int reg = (voice & 0x20) ? T4D_STOP_B : T4D_STOP_A; outl(mask, TRID_REG(trident, reg)); }
/*--------------------------------------------------------------------------- void snd_trident_stop_voice(struct snd_trident * trident, unsigned int voice) Description: Stop a voice, any channel 0 thru 63. This routine automatically handles the fact that there are more than 32 channels available. Parameters : voice - Voice number 0 thru n. trident - pointer to target device class for 4DWave. Return Value: None. ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L382-L388
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_allocate_pcm_channel
static int snd_trident_allocate_pcm_channel(struct snd_trident * trident) { int idx; if (trident->ChanPCMcnt >= trident->ChanPCM) return -1; for (idx = 31; idx >= 0; idx--) { if (!(trident->ChanMap[T4D_BANK_B] & (1 << idx))) { trident->ChanMap[T4D_BANK_B] |= 1 << idx; trident->ChanPCMcnt++; return idx + 32; } } return -1; }
/*--------------------------------------------------------------------------- int snd_trident_allocate_pcm_channel(struct snd_trident *trident) Description: Allocate hardware channel in Bank B (32-63). Parameters : trident - pointer to target device class for 4DWave. Return Value: hardware channel - 32-63 or -1 when no channel is available ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L403-L417
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_free_pcm_channel
static void snd_trident_free_pcm_channel(struct snd_trident *trident, int channel) { if (channel < 32 || channel > 63) return; channel &= 0x1f; if (trident->ChanMap[T4D_BANK_B] & (1 << channel)) { trident->ChanMap[T4D_BANK_B] &= ~(1 << channel); trident->ChanPCMcnt--; } }
/*--------------------------------------------------------------------------- void snd_trident_free_pcm_channel(int channel) Description: Free hardware channel in Bank B (32-63) Parameters : trident - pointer to target device class for 4DWave. channel - hardware channel number 0-63 Return Value: none ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L431-L440
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_allocate_synth_channel
static int snd_trident_allocate_synth_channel(struct snd_trident * trident) { int idx; for (idx = 31; idx >= 0; idx--) { if (!(trident->ChanMap[T4D_BANK_A] & (1 << idx))) { trident->ChanMap[T4D_BANK_A] |= 1 << idx; trident->synth.ChanSynthCount++; return idx; } } return -1; }
/*--------------------------------------------------------------------------- unsigned int snd_trident_allocate_synth_channel(void) Description: Allocate hardware channel in Bank A (0-31). Parameters : trident - pointer to target device class for 4DWave. Return Value: hardware channel - 0-31 or -1 when no channel is available ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L453-L465
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_free_synth_channel
static void snd_trident_free_synth_channel(struct snd_trident *trident, int channel) { if (channel < 0 || channel > 31) return; channel &= 0x1f; if (trident->ChanMap[T4D_BANK_A] & (1 << channel)) { trident->ChanMap[T4D_BANK_A] &= ~(1 << channel); trident->synth.ChanSynthCount--; } }
/*--------------------------------------------------------------------------- void snd_trident_free_synth_channel( int channel ) Description: Free hardware channel in Bank B (0-31). Parameters : trident - pointer to target device class for 4DWave. channel - hardware channel number 0-63 Return Value: none ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L479-L488
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_write_voice_regs
void snd_trident_write_voice_regs(struct snd_trident * trident, struct snd_trident_voice * voice) { unsigned int FmcRvolCvol; unsigned int regs[5]; regs[1] = voice->LBA; regs[4] = (voice->GVSel << 31) | ((voice->Pan & 0x0000007f) << 24) | ((voice->CTRL & 0x0000000f) << 12); FmcRvolCvol = ((voice->FMC & 3) << 14) | ((voice->RVol & 0x7f) << 7) | (voice->CVol & 0x7f); switch (trident->device) { case TRIDENT_DEVICE_ID_SI7018: regs[4] |= voice->number > 31 ? (voice->Vol & 0x000003ff) : ((voice->Vol & 0x00003fc) << (16-2)) | (voice->EC & 0x00000fff); regs[0] = (voice->CSO << 16) | ((voice->Alpha & 0x00000fff) << 4) | (voice->FMS & 0x0000000f); regs[2] = (voice->ESO << 16) | (voice->Delta & 0x0ffff); regs[3] = (voice->Attribute << 16) | FmcRvolCvol; break; case TRIDENT_DEVICE_ID_DX: regs[4] |= ((voice->Vol & 0x000003fc) << (16-2)) | (voice->EC & 0x00000fff); regs[0] = (voice->CSO << 16) | ((voice->Alpha & 0x00000fff) << 4) | (voice->FMS & 0x0000000f); regs[2] = (voice->ESO << 16) | (voice->Delta & 0x0ffff); regs[3] = FmcRvolCvol; break; case TRIDENT_DEVICE_ID_NX: regs[4] |= ((voice->Vol & 0x000003fc) << (16-2)) | (voice->EC & 0x00000fff); regs[0] = (voice->Delta << 24) | (voice->CSO & 0x00ffffff); regs[2] = ((voice->Delta << 16) & 0xff000000) | (voice->ESO & 0x00ffffff); regs[3] = (voice->Alpha << 20) | ((voice->FMS & 0x0000000f) << 16) | FmcRvolCvol; break; default: snd_BUG(); return; } outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR)); outl(regs[0], TRID_REG(trident, CH_START + 0)); outl(regs[1], TRID_REG(trident, CH_START + 4)); outl(regs[2], TRID_REG(trident, CH_START + 8)); outl(regs[3], TRID_REG(trident, CH_START + 12)); outl(regs[4], TRID_REG(trident, CH_START + 16)); #if 0 dev_dbg(trident->card->dev, "written %i channel:\n", voice->number); dev_dbg(trident->card->dev, " regs[0] = 0x%x/0x%x\n", regs[0], inl(TRID_REG(trident, CH_START + 0))); dev_dbg(trident->card->dev, " regs[1] = 0x%x/0x%x\n", regs[1], inl(TRID_REG(trident, CH_START + 4))); dev_dbg(trident->card->dev, " regs[2] = 0x%x/0x%x\n", regs[2], inl(TRID_REG(trident, CH_START + 8))); dev_dbg(trident->card->dev, " regs[3] = 0x%x/0x%x\n", regs[3], inl(TRID_REG(trident, CH_START + 12))); dev_dbg(trident->card->dev, " regs[4] = 0x%x/0x%x\n", regs[4], inl(TRID_REG(trident, CH_START + 16))); #endif }
/*--------------------------------------------------------------------------- snd_trident_write_voice_regs Description: This routine will complete and write the 5 hardware channel registers to hardware. Parameters: trident - pointer to target device class for 4DWave. voice - synthesizer voice structure Each register field. ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L502-L569
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_write_cso_reg
static void snd_trident_write_cso_reg(struct snd_trident * trident, struct snd_trident_voice * voice, unsigned int CSO) { voice->CSO = CSO; outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR)); if (trident->device != TRIDENT_DEVICE_ID_NX) { outw(voice->CSO, TRID_REG(trident, CH_DX_CSO_ALPHA_FMS) + 2); } else { outl((voice->Delta << 24) | (voice->CSO & 0x00ffffff), TRID_REG(trident, CH_NX_DELTA_CSO)); } }
/*--------------------------------------------------------------------------- snd_trident_write_cso_reg Description: This routine will write the new CSO offset register to hardware. Parameters: trident - pointer to target device class for 4DWave. voice - synthesizer voice structure CSO - new CSO value ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L585-L597
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_write_eso_reg
static void snd_trident_write_eso_reg(struct snd_trident * trident, struct snd_trident_voice * voice, unsigned int ESO) { voice->ESO = ESO; outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR)); if (trident->device != TRIDENT_DEVICE_ID_NX) { outw(voice->ESO, TRID_REG(trident, CH_DX_ESO_DELTA) + 2); } else { outl(((voice->Delta << 16) & 0xff000000) | (voice->ESO & 0x00ffffff), TRID_REG(trident, CH_NX_DELTA_ESO)); } }
/*--------------------------------------------------------------------------- snd_trident_write_eso_reg Description: This routine will write the new ESO offset register to hardware. Parameters: trident - pointer to target device class for 4DWave. voice - synthesizer voice structure ESO - new ESO value ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L611-L623
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_write_vol_reg
static void snd_trident_write_vol_reg(struct snd_trident * trident, struct snd_trident_voice * voice, unsigned int Vol) { voice->Vol = Vol; outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR)); switch (trident->device) { case TRIDENT_DEVICE_ID_DX: case TRIDENT_DEVICE_ID_NX: outb(voice->Vol >> 2, TRID_REG(trident, CH_GVSEL_PAN_VOL_CTRL_EC + 2)); break; case TRIDENT_DEVICE_ID_SI7018: /* dev_dbg(trident->card->dev, "voice->Vol = 0x%x\n", voice->Vol); */ outw((voice->CTRL << 12) | voice->Vol, TRID_REG(trident, CH_GVSEL_PAN_VOL_CTRL_EC)); break; } }
/*--------------------------------------------------------------------------- snd_trident_write_vol_reg Description: This routine will write the new voice volume register to hardware. Parameters: trident - pointer to target device class for 4DWave. voice - synthesizer voice structure Vol - new voice volume ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L637-L654
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_write_pan_reg
static void snd_trident_write_pan_reg(struct snd_trident * trident, struct snd_trident_voice * voice, unsigned int Pan) { voice->Pan = Pan; outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR)); outb(((voice->GVSel & 0x01) << 7) | (voice->Pan & 0x7f), TRID_REG(trident, CH_GVSEL_PAN_VOL_CTRL_EC + 3)); }
/*--------------------------------------------------------------------------- snd_trident_write_pan_reg Description: This routine will write the new voice pan register to hardware. Parameters: trident - pointer to target device class for 4DWave. voice - synthesizer voice structure Pan - new pan value ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L668-L676
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_write_rvol_reg
static void snd_trident_write_rvol_reg(struct snd_trident * trident, struct snd_trident_voice * voice, unsigned int RVol) { voice->RVol = RVol; outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR)); outw(((voice->FMC & 0x0003) << 14) | ((voice->RVol & 0x007f) << 7) | (voice->CVol & 0x007f), TRID_REG(trident, trident->device == TRIDENT_DEVICE_ID_NX ? CH_NX_ALPHA_FMS_FMC_RVOL_CVOL : CH_DX_FMC_RVOL_CVOL)); }
/*--------------------------------------------------------------------------- snd_trident_write_rvol_reg Description: This routine will write the new reverb volume register to hardware. Parameters: trident - pointer to target device class for 4DWave. voice - synthesizer voice structure RVol - new reverb volume ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L690-L700
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_write_cvol_reg
static void snd_trident_write_cvol_reg(struct snd_trident * trident, struct snd_trident_voice * voice, unsigned int CVol) { voice->CVol = CVol; outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR)); outw(((voice->FMC & 0x0003) << 14) | ((voice->RVol & 0x007f) << 7) | (voice->CVol & 0x007f), TRID_REG(trident, trident->device == TRIDENT_DEVICE_ID_NX ? CH_NX_ALPHA_FMS_FMC_RVOL_CVOL : CH_DX_FMC_RVOL_CVOL)); }
/*--------------------------------------------------------------------------- snd_trident_write_cvol_reg Description: This routine will write the new chorus volume register to hardware. Parameters: trident - pointer to target device class for 4DWave. voice - synthesizer voice structure CVol - new chorus volume ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L714-L724
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_convert_rate
static unsigned int snd_trident_convert_rate(unsigned int rate) { unsigned int delta; // We special case 44100 and 8000 since rounding with the equation // does not give us an accurate enough value. For 11025 and 22050 // the equation gives us the best answer. All other frequencies will // also use the equation. JDW if (rate == 44100) delta = 0xeb3; else if (rate == 8000) delta = 0x2ab; else if (rate == 48000) delta = 0x1000; else delta = (((rate << 12) + 24000) / 48000) & 0x0000ffff; return delta; }
/*--------------------------------------------------------------------------- snd_trident_convert_rate Description: This routine converts rate in HZ to hardware delta value. Parameters: trident - pointer to target device class for 4DWave. rate - Real or Virtual channel number. Returns: Delta value. ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L737-L754
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_convert_adc_rate
static unsigned int snd_trident_convert_adc_rate(unsigned int rate) { unsigned int delta; // We special case 44100 and 8000 since rounding with the equation // does not give us an accurate enough value. For 11025 and 22050 // the equation gives us the best answer. All other frequencies will // also use the equation. JDW if (rate == 44100) delta = 0x116a; else if (rate == 8000) delta = 0x6000; else if (rate == 48000) delta = 0x1000; else delta = ((48000 << 12) / rate) & 0x0000ffff; return delta; }
/*--------------------------------------------------------------------------- snd_trident_convert_adc_rate Description: This routine converts rate in HZ to hardware delta value. Parameters: trident - pointer to target device class for 4DWave. rate - Real or Virtual channel number. Returns: Delta value. ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L767-L784
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_spurious_threshold
static unsigned int snd_trident_spurious_threshold(unsigned int rate, unsigned int period_size) { unsigned int res = (rate * period_size) / 48000; if (res < 64) res = res / 2; else res -= 32; return res; }
/*--------------------------------------------------------------------------- snd_trident_spurious_threshold Description: This routine converts rate in HZ to spurious threshold. Parameters: trident - pointer to target device class for 4DWave. rate - Real or Virtual channel number. Returns: Delta value. ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L797-L806
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_control_mode
static unsigned int snd_trident_control_mode(struct snd_pcm_substream *substream) { unsigned int CTRL; struct snd_pcm_runtime *runtime = substream->runtime; /* set ctrl mode CTRL default: 8-bit (unsigned) mono, loop mode enabled */ CTRL = 0x00000001; if (snd_pcm_format_width(runtime->format) == 16) CTRL |= 0x00000008; // 16-bit data if (snd_pcm_format_signed(runtime->format)) CTRL |= 0x00000002; // signed data if (runtime->channels > 1) CTRL |= 0x00000004; // stereo data return CTRL; }
/*--------------------------------------------------------------------------- snd_trident_control_mode Description: This routine returns a control mode for a PCM channel. Parameters: trident - pointer to target device class for 4DWave. substream - PCM substream Returns: Control value. ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L819-L835
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_ioctl
static int snd_trident_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg) { /* FIXME: it seems that with small periods the behaviour of trident hardware is unpredictable and interrupt generator is broken */ #if 0 return snd_pcm_lib_ioctl(substream, cmd, arg); #endif return -1; }
/* * PCM part */ /*--------------------------------------------------------------------------- snd_trident_ioctl Description: Device I/O control handler for playback/capture parameters. Parameters: substream - PCM substream class cmd - what ioctl message to process arg - additional message infoarg Returns: Error status ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L854-L865
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_allocate_pcm_mem
static int snd_trident_allocate_pcm_mem(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_trident_voice *voice = runtime->private_data; int err; if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0) return err; if (trident->tlb.entries) { if (err > 0) { /* change */ if (voice->memblk) snd_trident_free_pages(trident, voice->memblk); voice->memblk = snd_trident_alloc_pages(trident, substream); if (voice->memblk == NULL) return -ENOMEM; } } return 0; }
/*--------------------------------------------------------------------------- snd_trident_allocate_pcm_mem Description: Allocate PCM ring buffer for given substream Parameters: substream - PCM substream class hw_params - hardware parameters Returns: Error status ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L879-L899
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_allocate_evoice
static int snd_trident_allocate_evoice(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_trident_voice *voice = runtime->private_data; struct snd_trident_voice *evoice = voice->extra; /* voice management */ if (params_buffer_size(hw_params) / 2 != params_period_size(hw_params)) { if (evoice == NULL) { evoice = snd_trident_alloc_voice(trident, SNDRV_TRIDENT_VOICE_TYPE_PCM, 0, 0); if (evoice == NULL) return -ENOMEM; voice->extra = evoice; evoice->substream = substream; } } else { if (evoice != NULL) { snd_trident_free_voice(trident, evoice); voice->extra = evoice = NULL; } } return 0; }
/*--------------------------------------------------------------------------- snd_trident_allocate_evoice Description: Allocate extra voice as interrupt generator Parameters: substream - PCM substream class hw_params - hardware parameters Returns: Error status ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L913-L939
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_hw_params
int snd_trident_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params) { int err; err = snd_trident_allocate_pcm_mem(substream, hw_params); if (err >= 0) err = snd_trident_allocate_evoice(substream, hw_params); return err; }
/*--------------------------------------------------------------------------- snd_trident_hw_params Description: Set the hardware parameters for the playback device. Parameters: substream - PCM substream class hw_params - hardware parameters Returns: Error status ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L953-L962
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_hw_free
static int snd_trident_hw_free(struct snd_pcm_substream *substream) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_trident_voice *voice = runtime->private_data; struct snd_trident_voice *evoice = voice ? voice->extra : NULL; if (trident->tlb.entries) { if (voice && voice->memblk) { snd_trident_free_pages(trident, voice->memblk); voice->memblk = NULL; } } snd_pcm_lib_free_pages(substream); if (evoice != NULL) { snd_trident_free_voice(trident, evoice); voice->extra = NULL; } return 0; }
/*--------------------------------------------------------------------------- snd_trident_playback_hw_free Description: Release the hardware resources for the playback device. Parameters: substream - PCM substream class Returns: Error status ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L975-L994
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_playback_prepare
int snd_trident_playback_prepare(struct snd_pcm_substream *substream) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_trident_voice *voice = runtime->private_data; struct snd_trident_voice *evoice = voice->extra; struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[substream->number]; spin_lock_irq(&trident->reg_lock); /* set delta (rate) value */ voice->Delta = snd_trident_convert_rate(runtime->rate); voice->spurious_threshold = snd_trident_spurious_threshold(runtime->rate, runtime->period_size); /* set Loop Begin Address */ //printk("runtime->dma_addr: %8.8X\n", runtime->dma_addr); if (voice->memblk) voice->LBA = voice->memblk->offset; else voice->LBA = runtime->dma_addr; voice->CSO = 0; voice->ESO = runtime->buffer_size - 1; /* in samples */ voice->CTRL = snd_trident_control_mode(substream); voice->FMC = 3; voice->GVSel = 1; voice->EC = 0; voice->Alpha = 0; voice->FMS = 0; voice->Vol = mix->vol; voice->RVol = mix->rvol; voice->CVol = mix->cvol; voice->Pan = mix->pan; voice->Attribute = 0; #if 0 voice->Attribute = (1<<(30-16))|(2<<(26-16))| (0<<(24-16))|(0x1f<<(19-16)); #else voice->Attribute = 0; #endif snd_trident_write_voice_regs(trident, voice); if (evoice != NULL) { evoice->Delta = voice->Delta; evoice->spurious_threshold = voice->spurious_threshold; evoice->LBA = voice->LBA; evoice->CSO = 0; evoice->ESO = (runtime->period_size * 2) + 4 - 1; /* in samples */ evoice->CTRL = voice->CTRL; evoice->FMC = 3; evoice->GVSel = trident->device == TRIDENT_DEVICE_ID_SI7018 ? 0 : 1; evoice->EC = 0; evoice->Alpha = 0; evoice->FMS = 0; evoice->Vol = 0x3ff; /* mute */ evoice->RVol = evoice->CVol = 0x7f; /* mute */ evoice->Pan = 0x7f; /* mute */ #if 0 evoice->Attribute = (1<<(30-16))|(2<<(26-16))| (0<<(24-16))|(0x1f<<(19-16)); #else evoice->Attribute = 0; #endif snd_trident_write_voice_regs(trident, evoice); evoice->isync2 = 1; evoice->isync_mark = runtime->period_size; evoice->ESO = (runtime->period_size * 2) - 1; } spin_unlock_irq(&trident->reg_lock); return 0; }
/*--------------------------------------------------------------------------- snd_trident_playback_prepare Description: Prepare playback device for playback. Parameters: substream - PCM substream class Returns: Error status ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L1007-L1080
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_capture_hw_params
static int snd_trident_capture_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params) { return snd_trident_allocate_pcm_mem(substream, hw_params); }
/*--------------------------------------------------------------------------- snd_trident_capture_hw_params Description: Set the hardware parameters for the capture device. Parameters: substream - PCM substream class hw_params - hardware parameters Returns: Error status ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L1094-L1098
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_capture_prepare
static int snd_trident_capture_prepare(struct snd_pcm_substream *substream) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_trident_voice *voice = runtime->private_data; unsigned int val, ESO_bytes; spin_lock_irq(&trident->reg_lock); // Initialize the channel and set channel Mode outb(0, TRID_REG(trident, LEGACY_DMAR15)); // Set DMA channel operation mode register outb(0x54, TRID_REG(trident, LEGACY_DMAR11)); // Set channel buffer Address, DMAR0 expects contiguous PCI memory area voice->LBA = runtime->dma_addr; outl(voice->LBA, TRID_REG(trident, LEGACY_DMAR0)); if (voice->memblk) voice->LBA = voice->memblk->offset; // set ESO ESO_bytes = snd_pcm_lib_buffer_bytes(substream) - 1; outb((ESO_bytes & 0x00ff0000) >> 16, TRID_REG(trident, LEGACY_DMAR6)); outw((ESO_bytes & 0x0000ffff), TRID_REG(trident, LEGACY_DMAR4)); ESO_bytes++; // Set channel sample rate, 4.12 format val = (((unsigned int) 48000L << 12) + (runtime->rate/2)) / runtime->rate; outw(val, TRID_REG(trident, T4D_SBDELTA_DELTA_R)); // Set channel interrupt blk length if (snd_pcm_format_width(runtime->format) == 16) { val = (unsigned short) ((ESO_bytes >> 1) - 1); } else { val = (unsigned short) (ESO_bytes - 1); } outl((val << 16) | val, TRID_REG(trident, T4D_SBBL_SBCL)); // Right now, set format and start to run captureing, // continuous run loop enable. trident->bDMAStart = 0x19; // 0001 1001b if (snd_pcm_format_width(runtime->format) == 16) trident->bDMAStart |= 0x80; if (snd_pcm_format_signed(runtime->format)) trident->bDMAStart |= 0x20; if (runtime->channels > 1) trident->bDMAStart |= 0x40; // Prepare capture intr channel voice->Delta = snd_trident_convert_rate(runtime->rate); voice->spurious_threshold = snd_trident_spurious_threshold(runtime->rate, runtime->period_size); voice->isync = 1; voice->isync_mark = runtime->period_size; voice->isync_max = runtime->buffer_size; // Set voice parameters voice->CSO = 0; voice->ESO = voice->isync_ESO = (runtime->period_size * 2) + 6 - 1; voice->CTRL = snd_trident_control_mode(substream); voice->FMC = 3; voice->RVol = 0x7f; voice->CVol = 0x7f; voice->GVSel = 1; voice->Pan = 0x7f; /* mute */ voice->Vol = 0x3ff; /* mute */ voice->EC = 0; voice->Alpha = 0; voice->FMS = 0; voice->Attribute = 0; snd_trident_write_voice_regs(trident, voice); spin_unlock_irq(&trident->reg_lock); return 0; }
/*--------------------------------------------------------------------------- snd_trident_capture_prepare Description: Prepare capture device for playback. Parameters: substream - PCM substream class Returns: Error status ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L1111-L1189
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_si7018_capture_hw_params
static int snd_trident_si7018_capture_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params) { int err; if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0) return err; return snd_trident_allocate_evoice(substream, hw_params); }
/*--------------------------------------------------------------------------- snd_trident_si7018_capture_hw_params Description: Set the hardware parameters for the capture device. Parameters: substream - PCM substream class hw_params - hardware parameters Returns: Error status ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L1203-L1212
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_si7018_capture_hw_free
static int snd_trident_si7018_capture_hw_free(struct snd_pcm_substream *substream) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_trident_voice *voice = runtime->private_data; struct snd_trident_voice *evoice = voice ? voice->extra : NULL; snd_pcm_lib_free_pages(substream); if (evoice != NULL) { snd_trident_free_voice(trident, evoice); voice->extra = NULL; } return 0; }
/*--------------------------------------------------------------------------- snd_trident_si7018_capture_hw_free Description: Release the hardware resources for the capture device. Parameters: substream - PCM substream class Returns: Error status ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L1225-L1238
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_si7018_capture_prepare
static int snd_trident_si7018_capture_prepare(struct snd_pcm_substream *substream) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_trident_voice *voice = runtime->private_data; struct snd_trident_voice *evoice = voice->extra; spin_lock_irq(&trident->reg_lock); voice->LBA = runtime->dma_addr; voice->Delta = snd_trident_convert_adc_rate(runtime->rate); voice->spurious_threshold = snd_trident_spurious_threshold(runtime->rate, runtime->period_size); // Set voice parameters voice->CSO = 0; voice->ESO = runtime->buffer_size - 1; /* in samples */ voice->CTRL = snd_trident_control_mode(substream); voice->FMC = 0; voice->RVol = 0; voice->CVol = 0; voice->GVSel = 1; voice->Pan = T4D_DEFAULT_PCM_PAN; voice->Vol = 0; voice->EC = 0; voice->Alpha = 0; voice->FMS = 0; voice->Attribute = (2 << (30-16)) | (2 << (26-16)) | (2 << (24-16)) | (1 << (23-16)); snd_trident_write_voice_regs(trident, voice); if (evoice != NULL) { evoice->Delta = snd_trident_convert_rate(runtime->rate); evoice->spurious_threshold = voice->spurious_threshold; evoice->LBA = voice->LBA; evoice->CSO = 0; evoice->ESO = (runtime->period_size * 2) + 20 - 1; /* in samples, 20 means correction */ evoice->CTRL = voice->CTRL; evoice->FMC = 3; evoice->GVSel = 0; evoice->EC = 0; evoice->Alpha = 0; evoice->FMS = 0; evoice->Vol = 0x3ff; /* mute */ evoice->RVol = evoice->CVol = 0x7f; /* mute */ evoice->Pan = 0x7f; /* mute */ evoice->Attribute = 0; snd_trident_write_voice_regs(trident, evoice); evoice->isync2 = 1; evoice->isync_mark = runtime->period_size; evoice->ESO = (runtime->period_size * 2) - 1; } spin_unlock_irq(&trident->reg_lock); return 0; }
/*--------------------------------------------------------------------------- snd_trident_si7018_capture_prepare Description: Prepare capture device for playback. Parameters: substream - PCM substream class Returns: Error status ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L1251-L1309
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_foldback_prepare
static int snd_trident_foldback_prepare(struct snd_pcm_substream *substream) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_trident_voice *voice = runtime->private_data; struct snd_trident_voice *evoice = voice->extra; spin_lock_irq(&trident->reg_lock); /* Set channel buffer Address */ if (voice->memblk) voice->LBA = voice->memblk->offset; else voice->LBA = runtime->dma_addr; /* set target ESO for channel */ voice->ESO = runtime->buffer_size - 1; /* in samples */ /* set sample rate */ voice->Delta = 0x1000; voice->spurious_threshold = snd_trident_spurious_threshold(48000, runtime->period_size); voice->CSO = 0; voice->CTRL = snd_trident_control_mode(substream); voice->FMC = 3; voice->RVol = 0x7f; voice->CVol = 0x7f; voice->GVSel = 1; voice->Pan = 0x7f; /* mute */ voice->Vol = 0x3ff; /* mute */ voice->EC = 0; voice->Alpha = 0; voice->FMS = 0; voice->Attribute = 0; /* set up capture channel */ outb(((voice->number & 0x3f) | 0x80), TRID_REG(trident, T4D_RCI + voice->foldback_chan)); snd_trident_write_voice_regs(trident, voice); if (evoice != NULL) { evoice->Delta = voice->Delta; evoice->spurious_threshold = voice->spurious_threshold; evoice->LBA = voice->LBA; evoice->CSO = 0; evoice->ESO = (runtime->period_size * 2) + 4 - 1; /* in samples */ evoice->CTRL = voice->CTRL; evoice->FMC = 3; evoice->GVSel = trident->device == TRIDENT_DEVICE_ID_SI7018 ? 0 : 1; evoice->EC = 0; evoice->Alpha = 0; evoice->FMS = 0; evoice->Vol = 0x3ff; /* mute */ evoice->RVol = evoice->CVol = 0x7f; /* mute */ evoice->Pan = 0x7f; /* mute */ evoice->Attribute = 0; snd_trident_write_voice_regs(trident, evoice); evoice->isync2 = 1; evoice->isync_mark = runtime->period_size; evoice->ESO = (runtime->period_size * 2) - 1; } spin_unlock_irq(&trident->reg_lock); return 0; }
/*--------------------------------------------------------------------------- snd_trident_foldback_prepare Description: Prepare foldback capture device for playback. Parameters: substream - PCM substream class Returns: Error status ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L1322-L1386
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_spdif_hw_params
static int snd_trident_spdif_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params) { struct snd_trident *trident = snd_pcm_substream_chip(substream); unsigned int old_bits = 0, change = 0; int err; err = snd_trident_allocate_pcm_mem(substream, hw_params); if (err < 0) return err; if (trident->device == TRIDENT_DEVICE_ID_SI7018) { err = snd_trident_allocate_evoice(substream, hw_params); if (err < 0) return err; } /* prepare SPDIF channel */ spin_lock_irq(&trident->reg_lock); old_bits = trident->spdif_pcm_bits; if (old_bits & IEC958_AES0_PROFESSIONAL) trident->spdif_pcm_bits &= ~IEC958_AES0_PRO_FS; else trident->spdif_pcm_bits &= ~(IEC958_AES3_CON_FS << 24); if (params_rate(hw_params) >= 48000) { trident->spdif_pcm_ctrl = 0x3c; // 48000 Hz trident->spdif_pcm_bits |= trident->spdif_bits & IEC958_AES0_PROFESSIONAL ? IEC958_AES0_PRO_FS_48000 : (IEC958_AES3_CON_FS_48000 << 24); } else if (params_rate(hw_params) >= 44100) { trident->spdif_pcm_ctrl = 0x3e; // 44100 Hz trident->spdif_pcm_bits |= trident->spdif_bits & IEC958_AES0_PROFESSIONAL ? IEC958_AES0_PRO_FS_44100 : (IEC958_AES3_CON_FS_44100 << 24); } else { trident->spdif_pcm_ctrl = 0x3d; // 32000 Hz trident->spdif_pcm_bits |= trident->spdif_bits & IEC958_AES0_PROFESSIONAL ? IEC958_AES0_PRO_FS_32000 : (IEC958_AES3_CON_FS_32000 << 24); } change = old_bits != trident->spdif_pcm_bits; spin_unlock_irq(&trident->reg_lock); #if 0 if (change) snd_ctl_notify(trident->card, SNDRV_CTL_EVENT_MASK_VALUE, &trident->spdif_pcm_ctl->id); #endif return 0; }
/*--------------------------------------------------------------------------- snd_trident_spdif_hw_params Description: Set the hardware parameters for the spdif device. Parameters: substream - PCM substream class hw_params - hardware parameters Returns: Error status ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L1400-L1454
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_spdif_prepare
static int snd_trident_spdif_prepare(struct snd_pcm_substream *substream) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_trident_voice *voice = runtime->private_data; struct snd_trident_voice *evoice = voice->extra; struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[substream->number]; unsigned int RESO, LBAO; unsigned int temp; spin_lock_irq(&trident->reg_lock); if (trident->device != TRIDENT_DEVICE_ID_SI7018) { /* set delta (rate) value */ voice->Delta = snd_trident_convert_rate(runtime->rate); voice->spurious_threshold = snd_trident_spurious_threshold(runtime->rate, runtime->period_size); /* set Loop Back Address */ LBAO = runtime->dma_addr; if (voice->memblk) voice->LBA = voice->memblk->offset; else voice->LBA = LBAO; voice->isync = 1; voice->isync3 = 1; voice->isync_mark = runtime->period_size; voice->isync_max = runtime->buffer_size; /* set target ESO for channel */ RESO = runtime->buffer_size - 1; voice->ESO = voice->isync_ESO = (runtime->period_size * 2) + 6 - 1; /* set ctrl mode */ voice->CTRL = snd_trident_control_mode(substream); voice->FMC = 3; voice->RVol = 0x7f; voice->CVol = 0x7f; voice->GVSel = 1; voice->Pan = 0x7f; voice->Vol = 0x3ff; voice->EC = 0; voice->CSO = 0; voice->Alpha = 0; voice->FMS = 0; voice->Attribute = 0; /* prepare surrogate IRQ channel */ snd_trident_write_voice_regs(trident, voice); outw((RESO & 0xffff), TRID_REG(trident, NX_SPESO)); outb((RESO >> 16), TRID_REG(trident, NX_SPESO + 2)); outl((LBAO & 0xfffffffc), TRID_REG(trident, NX_SPLBA)); outw((voice->CSO & 0xffff), TRID_REG(trident, NX_SPCTRL_SPCSO)); outb((voice->CSO >> 16), TRID_REG(trident, NX_SPCTRL_SPCSO + 2)); /* set SPDIF setting */ outb(trident->spdif_pcm_ctrl, TRID_REG(trident, NX_SPCTRL_SPCSO + 3)); outl(trident->spdif_pcm_bits, TRID_REG(trident, NX_SPCSTATUS)); } else { /* SiS */ /* set delta (rate) value */ voice->Delta = 0x800; voice->spurious_threshold = snd_trident_spurious_threshold(48000, runtime->period_size); /* set Loop Begin Address */ if (voice->memblk) voice->LBA = voice->memblk->offset; else voice->LBA = runtime->dma_addr; voice->CSO = 0; voice->ESO = runtime->buffer_size - 1; /* in samples */ voice->CTRL = snd_trident_control_mode(substream); voice->FMC = 3; voice->GVSel = 1; voice->EC = 0; voice->Alpha = 0; voice->FMS = 0; voice->Vol = mix->vol; voice->RVol = mix->rvol; voice->CVol = mix->cvol; voice->Pan = mix->pan; voice->Attribute = (1<<(30-16))|(7<<(26-16))| (0<<(24-16))|(0<<(19-16)); snd_trident_write_voice_regs(trident, voice); if (evoice != NULL) { evoice->Delta = voice->Delta; evoice->spurious_threshold = voice->spurious_threshold; evoice->LBA = voice->LBA; evoice->CSO = 0; evoice->ESO = (runtime->period_size * 2) + 4 - 1; /* in samples */ evoice->CTRL = voice->CTRL; evoice->FMC = 3; evoice->GVSel = trident->device == TRIDENT_DEVICE_ID_SI7018 ? 0 : 1; evoice->EC = 0; evoice->Alpha = 0; evoice->FMS = 0; evoice->Vol = 0x3ff; /* mute */ evoice->RVol = evoice->CVol = 0x7f; /* mute */ evoice->Pan = 0x7f; /* mute */ evoice->Attribute = 0; snd_trident_write_voice_regs(trident, evoice); evoice->isync2 = 1; evoice->isync_mark = runtime->period_size; evoice->ESO = (runtime->period_size * 2) - 1; } outl(trident->spdif_pcm_bits, TRID_REG(trident, SI_SPDIF_CS)); temp = inl(TRID_REG(trident, T4D_LFO_GC_CIR)); temp &= ~(1<<19); outl(temp, TRID_REG(trident, T4D_LFO_GC_CIR)); temp = inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL)); temp |= SPDIF_EN; outl(temp, TRID_REG(trident, SI_SERIAL_INTF_CTRL)); } spin_unlock_irq(&trident->reg_lock); return 0; }
/*--------------------------------------------------------------------------- snd_trident_spdif_prepare Description: Prepare SPDIF device for playback. Parameters: substream - PCM substream class Returns: Error status ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L1467-L1592
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_trigger
int snd_trident_trigger(struct snd_pcm_substream *substream, int cmd) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_pcm_substream *s; unsigned int what, whati, capture_flag, spdif_flag; struct snd_trident_voice *voice, *evoice; unsigned int val, go; switch (cmd) { case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: case SNDRV_PCM_TRIGGER_RESUME: go = 1; break; case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_PAUSE_PUSH: case SNDRV_PCM_TRIGGER_SUSPEND: go = 0; break; default: return -EINVAL; } what = whati = capture_flag = spdif_flag = 0; spin_lock(&trident->reg_lock); val = inl(TRID_REG(trident, T4D_STIMER)) & 0x00ffffff; snd_pcm_group_for_each_entry(s, substream) { if ((struct snd_trident *) snd_pcm_substream_chip(s) == trident) { voice = s->runtime->private_data; evoice = voice->extra; what |= 1 << (voice->number & 0x1f); if (evoice == NULL) { whati |= 1 << (voice->number & 0x1f); } else { what |= 1 << (evoice->number & 0x1f); whati |= 1 << (evoice->number & 0x1f); if (go) evoice->stimer = val; } if (go) { voice->running = 1; voice->stimer = val; } else { voice->running = 0; } snd_pcm_trigger_done(s, substream); if (voice->capture) capture_flag = 1; if (voice->spdif) spdif_flag = 1; } } if (spdif_flag) { if (trident->device != TRIDENT_DEVICE_ID_SI7018) { outl(trident->spdif_pcm_bits, TRID_REG(trident, NX_SPCSTATUS)); val = trident->spdif_pcm_ctrl; if (!go) val &= ~(0x28); outb(val, TRID_REG(trident, NX_SPCTRL_SPCSO + 3)); } else { outl(trident->spdif_pcm_bits, TRID_REG(trident, SI_SPDIF_CS)); val = inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL)) | SPDIF_EN; outl(val, TRID_REG(trident, SI_SERIAL_INTF_CTRL)); } } if (!go) outl(what, TRID_REG(trident, T4D_STOP_B)); val = inl(TRID_REG(trident, T4D_AINTEN_B)); if (go) { val |= whati; } else { val &= ~whati; } outl(val, TRID_REG(trident, T4D_AINTEN_B)); if (go) { outl(what, TRID_REG(trident, T4D_START_B)); if (capture_flag && trident->device != TRIDENT_DEVICE_ID_SI7018) outb(trident->bDMAStart, TRID_REG(trident, T4D_SBCTRL_SBE2R_SBDD)); } else { if (capture_flag && trident->device != TRIDENT_DEVICE_ID_SI7018) outb(0x00, TRID_REG(trident, T4D_SBCTRL_SBE2R_SBDD)); } spin_unlock(&trident->reg_lock); return 0; }
/*--------------------------------------------------------------------------- snd_trident_trigger Description: Start/stop devices Parameters: substream - PCM substream class cmd - trigger command (STOP, GO) Returns: Error status ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L1606-L1692
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_playback_pointer
snd_pcm_uframes_t snd_trident_playback_pointer(struct snd_pcm_substream *substream) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_trident_voice *voice = runtime->private_data; unsigned int cso; if (!voice->running) return 0; spin_lock(&trident->reg_lock); outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR)); if (trident->device != TRIDENT_DEVICE_ID_NX) { cso = inw(TRID_REG(trident, CH_DX_CSO_ALPHA_FMS + 2)); } else { // ID_4DWAVE_NX cso = (unsigned int) inl(TRID_REG(trident, CH_NX_DELTA_CSO)) & 0x00ffffff; } spin_unlock(&trident->reg_lock); if (cso >= runtime->buffer_size) cso = 0; return cso; }
/*--------------------------------------------------------------------------- snd_trident_playback_pointer Description: This routine return the playback position Parameters: substream - PCM substream class Returns: position of buffer ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L1705-L1731
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_capture_pointer
static snd_pcm_uframes_t snd_trident_capture_pointer(struct snd_pcm_substream *substream) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_trident_voice *voice = runtime->private_data; unsigned int result; if (!voice->running) return 0; result = inw(TRID_REG(trident, T4D_SBBL_SBCL)); if (runtime->channels > 1) result >>= 1; if (result > 0) result = runtime->buffer_size - result; return result; }
/*--------------------------------------------------------------------------- snd_trident_capture_pointer Description: This routine return the capture position Parameters: pcm1 - PCM device class Returns: position of buffer ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L1744-L1761
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_spdif_pointer
static snd_pcm_uframes_t snd_trident_spdif_pointer(struct snd_pcm_substream *substream) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_trident_voice *voice = runtime->private_data; unsigned int result; if (!voice->running) return 0; result = inl(TRID_REG(trident, NX_SPCTRL_SPCSO)) & 0x00ffffff; return result; }
/*--------------------------------------------------------------------------- snd_trident_spdif_pointer Description: This routine return the SPDIF playback position Parameters: substream - PCM substream class Returns: position of buffer ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L1774-L1787
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_playback_close
static int snd_trident_playback_close(struct snd_pcm_substream *substream) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_trident_voice *voice = runtime->private_data; snd_trident_pcm_mixer_free(trident, voice, substream); return 0; }
/*--------------------------------------------------------------------------- snd_trident_playback_close Description: This routine will close the 4DWave playback device. For now we will simply free the dma transfer buffer. Parameters: substream - PCM substream class ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L1968-L1976
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_spdif_open
static int snd_trident_spdif_open(struct snd_pcm_substream *substream) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_trident_voice *voice; struct snd_pcm_runtime *runtime = substream->runtime; voice = snd_trident_alloc_voice(trident, SNDRV_TRIDENT_VOICE_TYPE_PCM, 0, 0); if (voice == NULL) return -EAGAIN; voice->spdif = 1; voice->substream = substream; spin_lock_irq(&trident->reg_lock); trident->spdif_pcm_bits = trident->spdif_bits; spin_unlock_irq(&trident->reg_lock); runtime->private_data = voice; runtime->private_free = snd_trident_pcm_free_substream; if (trident->device == TRIDENT_DEVICE_ID_SI7018) { runtime->hw = snd_trident_spdif; } else { runtime->hw = snd_trident_spdif_7018; } trident->spdif_pcm_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; snd_ctl_notify(trident->card, SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO, &trident->spdif_pcm_ctl->id); #if 0 snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 0, 64*1024); #endif return 0; }
/*--------------------------------------------------------------------------- snd_trident_spdif_open Description: This routine will open the 4DWave SPDIF device. Parameters: substream - PCM substream class Returns: status - success or failure flag ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L1989-L2020
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_spdif_close
static int snd_trident_spdif_close(struct snd_pcm_substream *substream) { struct snd_trident *trident = snd_pcm_substream_chip(substream); unsigned int temp; spin_lock_irq(&trident->reg_lock); // restore default SPDIF setting if (trident->device != TRIDENT_DEVICE_ID_SI7018) { outb(trident->spdif_ctrl, TRID_REG(trident, NX_SPCTRL_SPCSO + 3)); outl(trident->spdif_bits, TRID_REG(trident, NX_SPCSTATUS)); } else { outl(trident->spdif_bits, TRID_REG(trident, SI_SPDIF_CS)); temp = inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL)); if (trident->spdif_ctrl) { temp |= SPDIF_EN; } else { temp &= ~SPDIF_EN; } outl(temp, TRID_REG(trident, SI_SERIAL_INTF_CTRL)); } spin_unlock_irq(&trident->reg_lock); trident->spdif_pcm_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE; #if 0 snd_ctl_notify(trident->card, SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO, &trident->spdif_pcm_ctl->id); #endif return 0; }
/*--------------------------------------------------------------------------- snd_trident_spdif_close Description: This routine will close the 4DWave SPDIF device. Parameters: substream - PCM substream class ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L2032-L2059
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_capture_open
static int snd_trident_capture_open(struct snd_pcm_substream *substream) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_trident_voice *voice; struct snd_pcm_runtime *runtime = substream->runtime; voice = snd_trident_alloc_voice(trident, SNDRV_TRIDENT_VOICE_TYPE_PCM, 0, 0); if (voice == NULL) return -EAGAIN; voice->capture = 1; voice->substream = substream; runtime->private_data = voice; runtime->private_free = snd_trident_pcm_free_substream; runtime->hw = snd_trident_capture; snd_pcm_set_sync(substream); #if 0 snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 0, 64*1024); #endif return 0; }
/*--------------------------------------------------------------------------- snd_trident_capture_open Description: This routine will open the 4DWave capture device. Parameters: substream - PCM substream class Returns: status - success or failure flag ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L2072-L2091
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_capture_close
static int snd_trident_capture_close(struct snd_pcm_substream *substream) { return 0; }
/*--------------------------------------------------------------------------- snd_trident_capture_close Description: This routine will close the 4DWave capture device. For now we will simply free the dma transfer buffer. Parameters: substream - PCM substream class ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L2102-L2105
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_foldback_open
static int snd_trident_foldback_open(struct snd_pcm_substream *substream) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_trident_voice *voice; struct snd_pcm_runtime *runtime = substream->runtime; voice = snd_trident_alloc_voice(trident, SNDRV_TRIDENT_VOICE_TYPE_PCM, 0, 0); if (voice == NULL) return -EAGAIN; voice->foldback_chan = substream->number; voice->substream = substream; runtime->private_data = voice; runtime->private_free = snd_trident_pcm_free_substream; runtime->hw = snd_trident_foldback; #if 0 snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 0, 64*1024); #endif return 0; }
/*--------------------------------------------------------------------------- snd_trident_foldback_open Description: This routine will open the 4DWave foldback capture device. Parameters: substream - PCM substream class Returns: status - success or failure flag ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L2118-L2136
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_foldback_close
static int snd_trident_foldback_close(struct snd_pcm_substream *substream) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_trident_voice *voice; struct snd_pcm_runtime *runtime = substream->runtime; voice = runtime->private_data; /* stop capture channel */ spin_lock_irq(&trident->reg_lock); outb(0x00, TRID_REG(trident, T4D_RCI + voice->foldback_chan)); spin_unlock_irq(&trident->reg_lock); return 0; }
/*--------------------------------------------------------------------------- snd_trident_foldback_close Description: This routine will close the 4DWave foldback capture device. For now we will simply free the dma transfer buffer. Parameters: substream - PCM substream class ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L2147-L2159
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_pcm
int snd_trident_pcm(struct snd_trident *trident, int device) { struct snd_pcm *pcm; int err; if ((err = snd_pcm_new(trident->card, "trident_dx_nx", device, trident->ChanPCM, 1, &pcm)) < 0) return err; pcm->private_data = trident; if (trident->tlb.entries) { snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_trident_nx_playback_ops); } else { snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_trident_playback_ops); } snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, trident->device != TRIDENT_DEVICE_ID_SI7018 ? &snd_trident_capture_ops : &snd_trident_si7018_capture_ops); pcm->info_flags = 0; pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX; strcpy(pcm->name, "Trident 4DWave"); trident->pcm = pcm; if (trident->tlb.entries) { struct snd_pcm_substream *substream; for (substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; substream; substream = substream->next) snd_pcm_lib_preallocate_pages(substream, SNDRV_DMA_TYPE_DEV_SG, snd_dma_pci_data(trident->pci), 64*1024, 128*1024); snd_pcm_lib_preallocate_pages(pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(trident->pci), 64*1024, 128*1024); } else { snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(trident->pci), 64*1024, 128*1024); } return 0; }
/*--------------------------------------------------------------------------- snd_trident_pcm Description: This routine registers the 4DWave device for PCM support. Parameters: trident - pointer to target device class for 4DWave. Returns: None ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L2267-L2307
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_foldback_pcm
int snd_trident_foldback_pcm(struct snd_trident *trident, int device) { struct snd_pcm *foldback; int err; int num_chan = 3; struct snd_pcm_substream *substream; if (trident->device == TRIDENT_DEVICE_ID_NX) num_chan = 4; if ((err = snd_pcm_new(trident->card, "trident_dx_nx", device, 0, num_chan, &foldback)) < 0) return err; foldback->private_data = trident; if (trident->tlb.entries) snd_pcm_set_ops(foldback, SNDRV_PCM_STREAM_CAPTURE, &snd_trident_nx_foldback_ops); else snd_pcm_set_ops(foldback, SNDRV_PCM_STREAM_CAPTURE, &snd_trident_foldback_ops); foldback->info_flags = 0; strcpy(foldback->name, "Trident 4DWave"); substream = foldback->streams[SNDRV_PCM_STREAM_CAPTURE].substream; strcpy(substream->name, "Front Mixer"); substream = substream->next; strcpy(substream->name, "Reverb Mixer"); substream = substream->next; strcpy(substream->name, "Chorus Mixer"); if (num_chan == 4) { substream = substream->next; strcpy(substream->name, "Second AC'97 ADC"); } trident->foldback = foldback; if (trident->tlb.entries) snd_pcm_lib_preallocate_pages_for_all(foldback, SNDRV_DMA_TYPE_DEV_SG, snd_dma_pci_data(trident->pci), 0, 128*1024); else snd_pcm_lib_preallocate_pages_for_all(foldback, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(trident->pci), 64*1024, 128*1024); return 0; }
/*--------------------------------------------------------------------------- snd_trident_foldback_pcm Description: This routine registers the 4DWave device for foldback PCM support. Parameters: trident - pointer to target device class for 4DWave. Returns: None ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L2320-L2359
f0cbde063396deb2c1246c9b3108a37755c68e9a
SBEMU
github_2023
crazii
c
snd_trident_spdif_pcm
int snd_trident_spdif_pcm(struct snd_trident *trident, int device) { struct snd_pcm *spdif; int err; if ((err = snd_pcm_new(trident->card, "trident_dx_nx IEC958", device, 1, 0, &spdif)) < 0) return err; spdif->private_data = trident; if (trident->device != TRIDENT_DEVICE_ID_SI7018) { snd_pcm_set_ops(spdif, SNDRV_PCM_STREAM_PLAYBACK, &snd_trident_spdif_ops); } else { snd_pcm_set_ops(spdif, SNDRV_PCM_STREAM_PLAYBACK, &snd_trident_spdif_7018_ops); } spdif->info_flags = 0; strcpy(spdif->name, "Trident 4DWave IEC958"); trident->spdif = spdif; snd_pcm_lib_preallocate_pages_for_all(spdif, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(trident->pci), 64*1024, 128*1024); return 0; }
/*--------------------------------------------------------------------------- snd_trident_spdif Description: This routine registers the 4DWave-NX device for SPDIF support. Parameters: trident - pointer to target device class for 4DWave-NX. Returns: None ---------------------------------------------------------------------------*/
https://github.com/crazii/SBEMU/blob/f0cbde063396deb2c1246c9b3108a37755c68e9a/drivers/trident/trident_main.c#L2372-L2393
f0cbde063396deb2c1246c9b3108a37755c68e9a