Lines Matching +full:has +full:- +full:chip +full:- +full:id
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>
33 MODULE_AUTHOR("Vivien Chappelier <vivien.chappelier@linux-mips.org>");
37 static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
38 static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
42 module_param(id, charp, 0444);
43 MODULE_PARM_DESC(id, "ID string for SGI O2 soundcard.");
66 #define CHANNEL_RING_MASK (CHANNEL_RING_SIZE - 1)
79 /* definition of the chip-specific record */
100 * Returns unsigned register value on success, -errno on failure.
104 struct snd_sgio2audio *chip = priv;
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);
125 struct snd_sgio2audio *chip = priv;
128 guard(spinlock_irqsave)(&chip->ad1843_lock);
132 &mace->perif.audio.codec_control);
134 val = readq(&mace->perif.audio.codec_control); /* flush bus */
143 struct snd_sgio2audio *chip = snd_kcontrol_chip(kcontrol);
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);
156 struct snd_sgio2audio *chip = snd_kcontrol_chip(kcontrol);
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;
170 struct snd_sgio2audio *chip = snd_kcontrol_chip(kcontrol);
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,
195 struct snd_sgio2audio *chip = snd_kcontrol_chip(kcontrol);
197 ucontrol->value.enumerated.item[0] = ad1843_get_recsrc(&chip->ad1843);
204 struct snd_sgio2audio *chip = snd_kcontrol_chip(kcontrol);
207 oldsrc = ad1843_get_recsrc(&chip->ad1843);
208 newsrc = ad1843_set_recsrc(&chip->ad1843,
209 ucontrol->value.enumerated.item[0]);
295 static int snd_sgio2audio_new_mixer(struct snd_sgio2audio *chip)
299 err = snd_ctl_add(chip->card,
300 snd_ctl_new1(&sgio2audio_ctrl_pcm0, chip));
304 err = snd_ctl_add(chip->card,
305 snd_ctl_new1(&sgio2audio_ctrl_pcm1, chip));
309 err = snd_ctl_add(chip->card,
310 snd_ctl_new1(&sgio2audio_ctrl_reclevel, chip));
314 err = snd_ctl_add(chip->card,
315 snd_ctl_new1(&sgio2audio_ctrl_recsource, chip));
318 err = snd_ctl_add(chip->card,
319 snd_ctl_new1(&sgio2audio_ctrl_line, chip));
323 err = snd_ctl_add(chip->card,
324 snd_ctl_new1(&sgio2audio_ctrl_cd, chip));
328 err = snd_ctl_add(chip->card,
329 snd_ctl_new1(&sgio2audio_ctrl_mic, chip));
336 /* low-level audio interface DMA */
339 /* returns 1 if a period has elapsed */
340 static int snd_sgio2audio_dma_pull_frag(struct snd_sgio2audio *chip,
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;
360 /* check if a period has elapsed */
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;
385 /* returns 1 if a period has elapsed */
386 static int snd_sgio2audio_dma_push_frag(struct snd_sgio2audio *chip,
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;
406 /* check if a period has elapsed */
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;
434 struct snd_sgio2audio *chip = snd_pcm_substream_chip(substream);
435 struct snd_sgio2audio_chan *chan = substream->runtime->private_data;
436 int ch = chan->idx;
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);
465 struct snd_sgio2audio *chip;
468 substream = chan->substream;
469 chip = snd_pcm_substream_chip(substream);
470 ch = chan->idx;
473 count = CHANNEL_RING_SIZE -
474 readq(&mace->perif.audio.chan[ch].depth) - 32;
475 if (snd_sgio2audio_dma_pull_frag(chip, ch, count))
485 struct snd_sgio2audio *chip;
488 substream = chan->substream;
489 chip = snd_pcm_substream_chip(substream);
490 ch = chan->idx;
492 count = CHANNEL_RING_SIZE -
493 readq(&mace->perif.audio.chan[ch].depth) - 32;
494 if (snd_sgio2audio_dma_push_frag(chip, ch, count))
505 substream = chan->substream;
534 struct snd_sgio2audio *chip = snd_pcm_substream_chip(substream);
535 struct snd_pcm_runtime *runtime = substream->runtime;
537 runtime->hw = snd_sgio2audio_pcm_hw;
538 runtime->private_data = &chip->channel[1];
544 struct snd_sgio2audio *chip = snd_pcm_substream_chip(substream);
545 struct snd_pcm_runtime *runtime = substream->runtime;
547 runtime->hw = snd_sgio2audio_pcm_hw;
548 runtime->private_data = &chip->channel[2];
555 struct snd_sgio2audio *chip = snd_pcm_substream_chip(substream);
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;
575 struct snd_sgio2audio *chip = snd_pcm_substream_chip(substream);
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;
630 struct snd_sgio2audio *chip = snd_pcm_substream_chip(substream);
631 struct snd_sgio2audio_chan *chan = substream->runtime->private_data;
634 return bytes_to_frames(substream->runtime,
635 chip->channel[chan->idx].pos);
668 static int snd_sgio2audio_new_pcm(struct snd_sgio2audio *chip)
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");
745 static int snd_sgio2audio_free(struct snd_sgio2audio *chip)
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);
763 kfree(chip);
769 struct snd_sgio2audio *chip = device->device_data;
771 return snd_sgio2audio_free(chip);
781 struct snd_sgio2audio *chip;
788 if (!(readq(&mace->perif.audio.control) & AUDIO_CONTROL_CODEC_PRESENT))
789 return -ENOENT;
791 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
792 if (chip == NULL)
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) {
803 kfree(chip);
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])) {
822 snd_sgio2audio_free(chip);
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);
846 snd_sgio2audio_free(chip);
850 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
852 snd_sgio2audio_free(chip);
855 *rchip = chip;
862 struct snd_sgio2audio *chip;
865 err = snd_card_new(&pdev->dev, index, id, THIS_MODULE, 0, &card);
869 err = snd_sgio2audio_create(card, &chip);
875 err = snd_sgio2audio_new_pcm(chip);
880 err = snd_sgio2audio_new_mixer(chip);
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,