Lines Matching +full:control +full:- +full:channel
1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright 2003 Vivien Chappelier <vivien.chappelier@linux-mips.org>
15 #include <linux/dma-mapping.h>
26 #include <sound/control.h>
33 MODULE_AUTHOR("Vivien Chappelier <vivien.chappelier@linux-mips.org>");
37 static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
53 #define CHANNEL_CONTROL_RESET BIT(10) /* 1: reset channel */
66 #define CHANNEL_RING_MASK (CHANNEL_RING_SIZE - 1)
79 /* definition of the chip-specific record */
88 struct snd_sgio2audio_chan channel[3];
100 * Returns unsigned register value on success, -errno on failure.
107 guard(spinlock_irqsave)(&chip->ad1843_lock);
110 CODEC_CONTROL_READ, &mace->perif.audio.codec_control);
112 val = readq(&mace->perif.audio.codec_control); /* flush bus */
115 val = readq(&mace->perif.audio.codec_read);
128 guard(spinlock_irqsave)(&chip->ad1843_lock);
132 &mace->perif.audio.codec_control);
134 val = readq(&mace->perif.audio.codec_control); /* flush bus */
145 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
146 uinfo->count = 2;
147 uinfo->value.integer.min = 0;
148 uinfo->value.integer.max = ad1843_get_gain_max(&chip->ad1843,
149 (int)kcontrol->private_value);
159 vol = ad1843_get_gain(&chip->ad1843, (int)kcontrol->private_value);
161 ucontrol->value.integer.value[0] = (vol >> 8) & 0xFF;
162 ucontrol->value.integer.value[1] = vol & 0xFF;
173 oldvol = ad1843_get_gain(&chip->ad1843, kcontrol->private_value);
174 newvol = (ucontrol->value.integer.value[0] << 8) |
175 ucontrol->value.integer.value[1];
177 newvol = ad1843_set_gain(&chip->ad1843, kcontrol->private_value,
197 ucontrol->value.enumerated.item[0] = ad1843_get_recsrc(&chip->ad1843);
207 oldsrc = ad1843_get_recsrc(&chip->ad1843);
208 newsrc = ad1843_set_recsrc(&chip->ad1843,
209 ucontrol->value.enumerated.item[0]);
214 /* dac1/pcm0 mixer control */
226 /* dac2/pcm1 mixer control */
238 /* record level mixer control */
249 /* record level source control */
259 /* line mixer control */
271 /* cd mixer control */
283 /* mic mixer control */
299 err = snd_ctl_add(chip->card,
304 err = snd_ctl_add(chip->card,
309 err = snd_ctl_add(chip->card,
314 err = snd_ctl_add(chip->card,
318 err = snd_ctl_add(chip->card,
323 err = snd_ctl_add(chip->card,
328 err = snd_ctl_add(chip->card,
336 /* low-level audio interface DMA */
350 struct snd_pcm_runtime *runtime = chip->channel[ch].substream->runtime;
352 guard(spinlock_irqsave)(&chip->channel[ch].lock);
354 src_base = (unsigned long) chip->ring_base | (ch << CHANNEL_RING_SHIFT);
355 src_pos = readq(&mace->perif.audio.chan[ch].read_ptr);
356 dst_base = runtime->dma_area;
357 dst_pos = chip->channel[ch].pos;
358 dst_mask = frames_to_bytes(runtime, runtime->buffer_size) - 1;
361 chip->channel[ch].size += (count >> 3); /* in frames */
362 ret = chip->channel[ch].size >= runtime->period_size;
363 chip->channel[ch].size %= runtime->period_size;
375 count -= sizeof(u64);
378 writeq(src_pos, &mace->perif.audio.chan[ch].read_ptr); /* in bytes */
379 chip->channel[ch].pos = dst_pos;
396 struct snd_pcm_runtime *runtime = chip->channel[ch].substream->runtime;
398 guard(spinlock_irqsave)(&chip->channel[ch].lock);
400 dst_base = (unsigned long)chip->ring_base | (ch << CHANNEL_RING_SHIFT);
401 dst_pos = readq(&mace->perif.audio.chan[ch].write_ptr);
402 src_base = runtime->dma_area;
403 src_pos = chip->channel[ch].pos;
404 src_mask = frames_to_bytes(runtime, runtime->buffer_size) - 1;
407 chip->channel[ch].size += (count >> 3); /* in frames */
408 ret = chip->channel[ch].size >= runtime->period_size;
409 chip->channel[ch].size %= runtime->period_size;
423 count -= sizeof(u64);
426 writeq(dst_pos, &mace->perif.audio.chan[ch].write_ptr); /* in bytes */
427 chip->channel[ch].pos = src_pos;
435 struct snd_sgio2audio_chan *chan = substream->runtime->private_data;
436 int ch = chan->idx;
438 /* reset DMA channel */
439 writeq(CHANNEL_CONTROL_RESET, &mace->perif.audio.chan[ch].control);
441 writeq(0, &mace->perif.audio.chan[ch].control);
443 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
445 snd_sgio2audio_dma_push_frag(chip, ch, CHANNEL_RING_SIZE - 32);
449 &mace->perif.audio.chan[ch].control);
455 struct snd_sgio2audio_chan *chan = substream->runtime->private_data;
457 writeq(0, &mace->perif.audio.chan[chan->idx].control);
468 substream = chan->substream;
470 ch = chan->idx;
473 count = CHANNEL_RING_SIZE -
474 readq(&mace->perif.audio.chan[ch].depth) - 32;
488 substream = chan->substream;
490 ch = chan->idx;
492 count = CHANNEL_RING_SIZE -
493 readq(&mace->perif.audio.chan[ch].depth) - 32;
505 substream = chan->substream;
535 struct snd_pcm_runtime *runtime = substream->runtime;
537 runtime->hw = snd_sgio2audio_pcm_hw;
538 runtime->private_data = &chip->channel[1];
545 struct snd_pcm_runtime *runtime = substream->runtime;
547 runtime->hw = snd_sgio2audio_pcm_hw;
548 runtime->private_data = &chip->channel[2];
556 struct snd_pcm_runtime *runtime = substream->runtime;
558 runtime->hw = snd_sgio2audio_pcm_hw;
559 runtime->private_data = &chip->channel[0];
566 struct snd_pcm_runtime *runtime = substream->runtime;
568 runtime->private_data = NULL;
576 struct snd_pcm_runtime *runtime = substream->runtime;
577 struct snd_sgio2audio_chan *chan = substream->runtime->private_data;
578 int ch = chan->idx;
580 guard(spinlock_irqsave)(&chip->channel[ch].lock);
582 /* Setup the pseudo-dma transfer pointers. */
583 chip->channel[ch].pos = 0;
584 chip->channel[ch].size = 0;
585 chip->channel[ch].substream = substream;
589 switch (substream->stream) {
591 ad1843_setup_dac(&chip->ad1843,
592 ch - 1,
593 runtime->rate,
595 runtime->channels);
598 ad1843_setup_adc(&chip->ad1843,
599 runtime->rate,
601 runtime->channels);
621 return -EINVAL;
631 struct snd_sgio2audio_chan *chan = substream->runtime->private_data;
634 return bytes_to_frames(substream->runtime,
635 chip->channel[chan->idx].pos);
674 err = snd_pcm_new(chip->card, "SGI O2 Audio", 0, 1, 1, &pcm);
678 pcm->private_data = chip;
679 strscpy(pcm->name, "SGI O2 DAC1");
689 err = snd_pcm_new(chip->card, "SGI O2 Audio", 1, 1, 0, &pcm);
693 pcm->private_data = chip;
694 strscpy(pcm->name, "SGI O2 DAC2");
714 .desc = "Capture DMA Channel 0"
724 .desc = "Playback DMA Channel 1"
729 .desc = "Memory Error Channel 1"
734 .desc = "Playback DMA Channel 2"
739 .desc = "Memory Error Channel 2"
750 writeq(AUDIO_CONTROL_RESET, &mace->perif.audio.control);
752 writeq(0, &mace->perif.audio.control);
757 &chip->channel[snd_sgio2_isr_table[i].idx]);
759 dma_free_coherent(chip->card->dev, MACEISA_RINGBUFFERS_SIZE,
760 chip->ring_base, chip->ring_base_dma);
769 struct snd_sgio2audio *chip = device->device_data;
788 if (!(readq(&mace->perif.audio.control) & AUDIO_CONTROL_CODEC_PRESENT))
789 return -ENOENT;
793 return -ENOMEM;
795 chip->card = card;
797 chip->ring_base = dma_alloc_coherent(card->dev,
799 &chip->ring_base_dma, GFP_KERNEL);
800 if (chip->ring_base == NULL) {
804 return -ENOMEM;
807 spin_lock_init(&chip->ad1843_lock);
811 spin_lock_init(&chip->channel[i].lock);
812 chip->channel[i].idx = i;
821 &chip->channel[snd_sgio2_isr_table[i].idx])) {
825 return -EBUSY;
830 writeq(AUDIO_CONTROL_RESET, &mace->perif.audio.control);
832 writeq(0, &mace->perif.audio.control);
836 writeq(chip->ring_base_dma, &mace->perif.ctrl.ringbase);
839 chip->ad1843.read = read_ad1843_reg;
840 chip->ad1843.write = write_ad1843_reg;
841 chip->ad1843.chip = chip;
844 err = ad1843_init(&chip->ad1843);
865 err = snd_card_new(&pdev->dev, index, id, THIS_MODULE, 0, &card);
886 strscpy(card->driver, "SGI O2 Audio");
887 strscpy(card->shortname, "SGI O2 Audio");
888 sprintf(card->longname, "%s irq %i-%i",
889 card->shortname,