Lines Matching +full:num +full:- +full:channels
1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2004-2007, David Dillow
7 * Inspired by the Trident 4D-WaveDX/NX driver.
28 static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
52 * we use the hardware's built-in Mid-Loop Interrupt and End-Loop Interrupt
60 * Capture channels do not have a SSO, so we allocate a playback channel to
86 int num;
137 * documented range of 8-0xfff8 samples. Given that they are 0-based,
138 * that places our period/buffer range at 9-0xfff9 samples. That makes the
139 * max buffer size 0xfff9 samples * 2 channels * 2 bytes per sample, and
189 void __iomem *base = voice->ctrl_base;
191 voice->sso += period;
192 if (voice->sso >= voice->buffer_size)
193 voice->sso -= voice->buffer_size;
196 if (voice->sso < 8)
197 voice->sso = 8;
200 writew(voice->sso & 0xffff, base + SIS_PLAY_DMA_SSO_ESO + 2);
205 if (voice->flags & VOICE_SSO_TIMING) {
206 sis_update_sso(voice, voice->period_size);
207 } else if (voice->flags & VOICE_SYNC_TIMING) {
213 if (voice->vperiod > voice->period_size) {
214 voice->vperiod -= voice->period_size;
215 if (voice->vperiod < voice->period_size)
216 sis_update_sso(voice, voice->vperiod);
218 sis_update_sso(voice, voice->period_size);
227 sync = voice->sync_cso;
228 sync -= readw(voice->sync_base + SIS_CAPTURE_DMA_FORMAT_CSO);
229 if (sync > (voice->sync_buffer_size / 2))
230 sync -= voice->sync_buffer_size;
249 * it really is past a period when we get our interrupt --
259 if (sync > -9)
260 voice->vperiod = voice->sync_period_size + 1;
262 voice->vperiod = voice->sync_period_size + sync + 10;
264 if (voice->vperiod < voice->buffer_size) {
265 sis_update_sso(voice, voice->vperiod);
266 voice->vperiod = 0;
268 sis_update_sso(voice, voice->period_size);
270 sync = voice->sync_cso + voice->sync_period_size;
271 if (sync >= voice->sync_buffer_size)
272 sync -= voice->sync_buffer_size;
273 voice->sync_cso = sync;
276 snd_pcm_period_elapsed(voice->substream);
295 unsigned long io = sis->ioport;
314 sis_voice_irq(status, sis->voices);
320 sis_voice_irq(status, &sis->voices[32]);
326 voice = &sis->capture_voice;
327 if (!voice->timing)
328 snd_pcm_period_elapsed(voice->substream);
367 /* Helper function: must hold sis->voice_lock on entry */
368 if (!sis->silence_users)
369 sis->silence_dma_addr = dma_map_single(&sis->pci->dev,
370 sis->suspend_state[0],
372 sis->silence_users++;
377 /* Helper function: must hold sis->voice_lock on entry */
378 sis->silence_users--;
379 if (!sis->silence_users)
380 dma_unmap_single(&sis->pci->dev, sis->silence_dma_addr, 4096,
386 guard(spinlock_irqsave)(&sis->voice_lock);
387 if (voice->timing) {
389 voice->timing->flags &= ~(VOICE_IN_USE | VOICE_SSO_TIMING |
391 voice->timing = NULL;
393 voice->flags &= ~(VOICE_IN_USE | VOICE_SSO_TIMING | VOICE_SYNC_TIMING);
403 voice = &sis->voices[i];
404 if (voice->flags & VOICE_IN_USE)
406 voice->flags |= VOICE_IN_USE;
417 guard(spinlock_irqsave)(&sis->voice_lock);
425 struct snd_pcm_runtime *runtime = substream->runtime;
426 struct voice *voice = runtime->private_data;
439 if (needed && !voice->timing) {
440 scoped_guard(spinlock_irqsave, &sis->voice_lock) {
441 voice->timing = __sis_alloc_playback_voice(sis);
442 if (voice->timing)
445 if (!voice->timing)
446 return -ENOMEM;
447 voice->timing->substream = substream;
448 } else if (!needed && voice->timing) {
450 voice->timing = NULL;
459 struct snd_pcm_runtime *runtime = substream->runtime;
464 return -EAGAIN;
466 voice->substream = substream;
467 runtime->private_data = voice;
468 runtime->hw = sis_playback_hw_info;
480 struct snd_pcm_runtime *runtime = substream->runtime;
481 struct voice *voice = runtime->private_data;
489 struct snd_pcm_runtime *runtime = substream->runtime;
490 struct voice *voice = runtime->private_data;
491 void __iomem *ctrl_base = voice->ctrl_base;
492 void __iomem *wave_base = voice->wave_base;
500 if (snd_pcm_format_width(runtime->format) == 8)
502 if (!snd_pcm_format_signed(runtime->format))
504 if (runtime->channels == 1)
510 dma_addr = runtime->dma_addr;
511 leo = runtime->buffer_size - 1;
515 if (runtime->period_size == (runtime->buffer_size / 2)) {
517 } else if (runtime->period_size != runtime->buffer_size) {
518 voice->flags |= VOICE_SSO_TIMING;
519 voice->sso = runtime->period_size - 1;
520 voice->period_size = runtime->period_size;
521 voice->buffer_size = runtime->buffer_size;
525 sso_eso |= (runtime->period_size - 1) << 16;
528 delta = sis_rate_to_delta(runtime->rate);
556 unsigned long io = sis->ioport;
580 return -EINVAL;
589 voice = s->runtime->private_data;
590 if (voice->flags & VOICE_CAPTURE) {
591 record |= 1 << voice->num;
592 voice = voice->timing;
599 play[voice->num / 32] |= 1 << (voice->num & 0x1f);
624 struct snd_pcm_runtime *runtime = substream->runtime;
625 struct voice *voice = runtime->private_data;
628 cso = readl(voice->ctrl_base + SIS_PLAY_DMA_FORMAT_CSO);
636 struct snd_pcm_runtime *runtime = substream->runtime;
637 struct voice *voice = &sis->capture_voice;
642 scoped_guard(spinlock_irqsave, &sis->voice_lock) {
643 if (voice->flags & VOICE_IN_USE)
646 voice->flags |= VOICE_IN_USE;
650 return -EAGAIN;
652 voice->substream = substream;
653 runtime->private_data = voice;
654 runtime->hw = sis_capture_hw_info;
655 runtime->hw.rates = sis->ac97[0]->rates[AC97_RATES_ADC];
671 rc = snd_ac97_set_rate(sis->ac97[0], AC97_PCM_LR_ADC_RATE,
686 struct snd_pcm_runtime *runtime = substream->runtime;
687 struct voice *timing = voice->timing;
688 void __iomem *play_base = timing->ctrl_base;
689 void __iomem *wave_base = timing->wave_base;
697 buffer_size = 4096 / runtime->channels;
698 buffer_size /= snd_pcm_format_size(runtime->format, 1);
707 * end -- this helps minimize the effects of any jitter. Adjust our
713 vperiod = runtime->period_size + 12;
721 tail = quarter_period - tail;
722 tail += loops - 1;
724 period_size -= tail;
727 sso = period_size - 1;
730 * don't need to use virtual periods -- disable them.
732 period_size = runtime->period_size;
733 sso = vperiod - 1;
740 timing->flags |= VOICE_SYNC_TIMING;
741 timing->sync_base = voice->ctrl_base;
742 timing->sync_cso = runtime->period_size;
743 timing->sync_period_size = runtime->period_size;
744 timing->sync_buffer_size = runtime->buffer_size;
745 timing->period_size = period_size;
746 timing->buffer_size = buffer_size;
747 timing->sso = sso;
748 timing->vperiod = vperiod;
750 /* Using unsigned samples with the all-zero silence buffer
752 * So ignore unsigned vs signed -- it doesn't change the timing.
755 if (snd_pcm_format_width(runtime->format) == 8)
757 if (runtime->channels == 1)
760 control = timing->buffer_size - 1;
762 sso_eso = timing->buffer_size - 1;
763 sso_eso |= timing->sso << 16;
765 delta = sis_rate_to_delta(runtime->rate);
770 writel(sis->silence_dma_addr, play_base + SIS_PLAY_DMA_BASE);
787 struct snd_pcm_runtime *runtime = substream->runtime;
788 struct voice *voice = runtime->private_data;
789 void __iomem *rec_base = voice->ctrl_base;
797 if (snd_pcm_format_width(runtime->format) == 8)
799 if (!snd_pcm_format_signed(runtime->format))
801 if (runtime->channels == 1)
804 dma_addr = runtime->dma_addr;
805 leo = runtime->buffer_size - 1;
812 if (voice->timing) {
816 if (runtime->period_size != runtime->buffer_size)
855 rc = snd_pcm_new(sis->card, "SiS7019", 0, 64, 1, &pcm);
859 pcm->private_data = sis;
860 strscpy(pcm->name, "SiS7019");
861 sis->pcm = pcm;
870 &sis->pci->dev, 64*1024, 128*1024);
877 unsigned long io = sis->ioport;
891 /* Get the AC97 semaphore -- software first, so we don't spin
894 guard(mutex)(&sis->ac97_mutex);
897 while ((inw(io + SIS_AC97_SEMA) & SIS_AC97_SEMA_BUSY) && --count)
912 } while (--count);
923 while ((inw(io + SIS_AC97_STATUS) & SIS_AC97_STATUS_BUSY) && --count)
934 dev_err(&sis->pci->dev, "ac97 codec %d timeout cmd 0x%08x\n",
949 sis_ac97_rw(ac97->private_data, ac97->num,
950 (val << 16) | (reg << 8) | cmd[ac97->num]);
960 return sis_ac97_rw(ac97->private_data, ac97->num,
961 (reg << 8) | cmd[ac97->num]);
977 rc = snd_ac97_bus(sis->card, 0, &ops, NULL, &bus);
978 if (!rc && sis->codecs_present & SIS_PRIMARY_CODEC_PRESENT)
979 rc = snd_ac97_mixer(bus, &ac97, &sis->ac97[0]);
980 ac97.num = 1;
981 if (!rc && (sis->codecs_present & SIS_SECONDARY_CODEC_PRESENT))
982 rc = snd_ac97_mixer(bus, &ac97, &sis->ac97[1]);
983 ac97.num = 2;
984 if (!rc && (sis->codecs_present & SIS_TERTIARY_CODEC_PRESENT))
985 rc = snd_ac97_mixer(bus, &ac97, &sis->ac97[2]);
995 struct sis7019 *sis = card->private_data;
999 outl(SIS_GCR_SOFTWARE_RESET, sis->ioport + SIS_GCR);
1001 outl(0, sis->ioport + SIS_GCR);
1002 outl(0, sis->ioport + SIS_GIER);
1006 if (sis->irq >= 0)
1007 free_irq(sis->irq, sis);
1012 unsigned long io = sis->ioport;
1013 void __iomem *ioaddr = sis->ioaddr;
1025 /* Get the AC-link semaphore, and reset the codecs
1028 while ((inw(io + SIS_AC97_SEMA) & SIS_AC97_SEMA_BUSY) && --count)
1032 return -EIO;
1038 while ((inw(io + SIS_AC97_STATUS) & SIS_AC97_STATUS_BUSY) && --count)
1045 return -EIO;
1052 sis->codecs_present = 0;
1057 sis->codecs_present |= SIS_PRIMARY_CODEC_PRESENT;
1059 sis->codecs_present |= SIS_SECONDARY_CODEC_PRESENT;
1061 sis->codecs_present |= SIS_TERTIARY_CODEC_PRESENT;
1063 if (sis->codecs_present == codecs)
1071 if (!sis->codecs_present) {
1072 dev_err(&sis->pci->dev, "could not find any codecs\n");
1073 return -EIO;
1076 if (sis->codecs_present != codecs) {
1077 dev_warn(&sis->pci->dev, "missing codecs, found %0x, expected %0x\n",
1078 sis->codecs_present, codecs);
1082 * and enable PCM slots on the AC-link for L/R playback (3 & 4) and
1083 * record channels. We're going to want to use Variable Rate Audio
1092 /* All AC97 PCM slots should be sourced from sub-mixer 0.
1100 /* Reset the synchronization groups for all of the channels
1103 * assign sub-mixer 0 to all playback channels, and avoid any
1141 struct sis7019 *sis = card->private_data;
1142 void __iomem *ioaddr = sis->ioaddr;
1146 if (sis->codecs_present & SIS_PRIMARY_CODEC_PRESENT)
1147 snd_ac97_suspend(sis->ac97[0]);
1148 if (sis->codecs_present & SIS_SECONDARY_CODEC_PRESENT)
1149 snd_ac97_suspend(sis->ac97[1]);
1150 if (sis->codecs_present & SIS_TERTIARY_CODEC_PRESENT)
1151 snd_ac97_suspend(sis->ac97[2]);
1153 /* snd_pcm_suspend_all() stopped all channels, so we're quiescent.
1155 if (sis->irq >= 0) {
1156 free_irq(sis->irq, sis);
1157 sis->irq = -1;
1163 memcpy_fromio(sis->suspend_state[i], ioaddr, 4096);
1174 struct sis7019 *sis = card->private_data;
1175 void __iomem *ioaddr = sis->ioaddr;
1179 dev_err(&pci->dev, "unable to re-init controller\n");
1183 if (request_irq(pci->irq, sis_interrupt, IRQF_SHARED,
1185 dev_err(&pci->dev, "unable to regain IRQ %d\n", pci->irq);
1193 memcpy_toio(ioaddr, sis->suspend_state[i], 4096);
1197 memset(sis->suspend_state[0], 0, 4096);
1199 sis->irq = pci->irq;
1201 if (sis->codecs_present & SIS_PRIMARY_CODEC_PRESENT)
1202 snd_ac97_resume(sis->ac97[0]);
1203 if (sis->codecs_present & SIS_SECONDARY_CODEC_PRESENT)
1204 snd_ac97_resume(sis->ac97[1]);
1205 if (sis->codecs_present & SIS_TERTIARY_CODEC_PRESENT)
1206 snd_ac97_resume(sis->ac97[2]);
1213 return -EIO;
1228 sis->suspend_state[i] = devm_kmalloc(&sis->pci->dev, 4096,
1230 if (!sis->suspend_state[i])
1231 return -ENOMEM;
1233 memset(sis->suspend_state[0], 0, 4096);
1241 struct sis7019 *sis = card->private_data;
1250 rc = dma_set_mask(&pci->dev, DMA_BIT_MASK(30));
1252 dev_err(&pci->dev, "architecture does not support 30-bit PCI busmaster DMA");
1253 return -ENXIO;
1256 mutex_init(&sis->ac97_mutex);
1257 spin_lock_init(&sis->voice_lock);
1258 sis->card = card;
1259 sis->pci = pci;
1260 sis->irq = -1;
1261 sis->ioport = pci_resource_start(pci, 0);
1265 dev_err(&pci->dev, "unable request regions\n");
1269 sis->ioaddr = devm_ioremap(&pci->dev, pci_resource_start(pci, 1), 0x4000);
1270 if (!sis->ioaddr) {
1271 dev_err(&pci->dev, "unable to remap MMIO, aborting\n");
1272 return -EIO;
1277 dev_err(&pci->dev, "unable to allocate state storage\n");
1284 card->private_free = sis_chip_free;
1286 rc = request_irq(pci->irq, sis_interrupt, IRQF_SHARED, KBUILD_MODNAME,
1289 dev_err(&pci->dev, "unable to allocate irq %d\n", sis->irq);
1293 sis->irq = pci->irq;
1294 card->sync_irq = sis->irq;
1298 voice = &sis->voices[i];
1299 voice->num = i;
1300 voice->ctrl_base = SIS_PLAY_DMA_ADDR(sis->ioaddr, i);
1301 voice->wave_base = SIS_WAVE_ADDR(sis->ioaddr, i);
1304 voice = &sis->capture_voice;
1305 voice->flags = VOICE_CAPTURE;
1306 voice->num = SIS_CAPTURE_CHAN_AC97_PCM_IN;
1307 voice->ctrl_base = SIS_CAPTURE_DMA_ADDR(sis->ioaddr, voice->num);
1320 return -ENOENT;
1326 * We assume that SIS_PRIMARY_*_PRESENT matches bits 0-2.
1333 rc = snd_devm_card_new(&pci->dev, index, id, THIS_MODULE,
1338 strscpy(card->driver, "SiS7019");
1339 strscpy(card->shortname, "SiS7019");
1344 sis = card->private_data;
1354 snprintf(card->longname, sizeof(card->longname),
1356 card->shortname, snd_ac97_get_short_name(sis->ac97[0]),
1357 sis->ioport, sis->irq);
1370 return snd_card_free_on_error(&pci->dev, __snd_sis7019_probe(pci, pci_id));