Lines Matching +full:pcm +full:- +full:interface +full:- +full:rate

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
9 * Copyright (c) 1996-1998 Crystal Semiconductor Corp.
37 #include <dev/sound/pcm/sound.h>
38 #include <dev/sound/pcm/ac97.h>
80 /* -------------------------------------------------------------------- */
118 /* -------------------------------------------------------------------- */
125 old = csa->active; in csa_active()
126 csa->active += run; in csa_active()
128 if ((csa->active > 1) || (csa->active < -1)) in csa_active()
129 csa->active = 0; in csa_active()
130 if (csa->card->active) in csa_active()
131 return (csa->card->active(!(csa->active && old))); in csa_active()
136 /* -------------------------------------------------------------------- */
146 if (csa_readcodec(&csa->res, regno + BA0_AC97_RESET, &data)) in csa_rdcd()
148 csa_active(csa, -1); in csa_rdcd()
159 csa_writecodec(&csa->res, regno + BA0_AC97_RESET, data); in csa_wrcd()
160 csa_active(csa, -1); in csa_wrcd()
183 * Compute the values used to drive the actual sample rate conversion. in csa_setplaysamplerate()
188 * ulCorrectionPerGOF = floor((Fs,in * 2^26 - Fs,out * ulPhiIncr) / in csa_setplaysamplerate()
190 * ulCorrectionPerSec = Fs,in * 2^26 - Fs,out * phiIncr - in csa_setplaysamplerate()
201 ulTemp1 -= ulPhiIncr * ulOutRate; in csa_setplaysamplerate()
206 ulTemp1 -= ulTemp2 * ulOutRate; in csa_setplaysamplerate()
208 ulTemp1 -= ulCorrectionPerGOF * GOF_PER_SEC; in csa_setplaysamplerate()
229 * We can only decimate by up to a factor of 1/9th the hardware rate. in csa_setcapturesamplerate()
236 * We can not capture at at rate greater than the Input Rate (48000). in csa_setcapturesamplerate()
243 * Compute the values used to drive the actual sample rate conversion. in csa_setcapturesamplerate()
247 * ulCoeffIncr = -floor((Fs,out * 2^23) / Fs,in) in csa_setcapturesamplerate()
249 * ulCorrectionPerGOF = floor((Fs,in * 2^26 - Fs,out * ulPhiIncr) / in csa_setcapturesamplerate()
251 * ulCorrectionPerSec = Fs,in * 2^26 - Fs,out * phiIncr - in csa_setcapturesamplerate()
261 * ulInitialDelay = dividend(((24 * Fs,in) + Fs,out - 1) / Fs,out) in csa_setcapturesamplerate()
265 ulTemp1 -= ulCoeffIncr * ulInRate; in csa_setcapturesamplerate()
273 ulTemp1 -= ulPhiIncr * ulOutRate; in csa_setcapturesamplerate()
278 ulTemp1 -= ulTemp2 * ulOutRate; in csa_setcapturesamplerate()
280 ulTemp1 -= ulCorrectionPerGOF * GOF_PER_SEC; in csa_setcapturesamplerate()
282 ulInitialDelay = ((ulInRate * 24) + ulOutRate - 1) / ulOutRate; in csa_setcapturesamplerate()
297 * the output sample rate. in csa_setcapturesamplerate()
338 if (!csa->pch.dma) { in csa_startplaydma()
339 resp = &csa->res; in csa_startplaydma()
342 csa_writemem(resp, BA1_PCTL, ul | csa->pctl); in csa_startplaydma()
344 csa->pch.dma = 1; in csa_startplaydma()
354 if (!csa->rch.dma) { in csa_startcapturedma()
355 resp = &csa->res; in csa_startcapturedma()
358 csa_writemem(resp, BA1_CCTL, ul | csa->cctl); in csa_startcapturedma()
360 csa->rch.dma = 1; in csa_startcapturedma()
370 if (csa->pch.dma) { in csa_stopplaydma()
371 resp = &csa->res; in csa_stopplaydma()
373 csa->pctl = ul & 0xffff0000; in csa_stopplaydma()
376 csa->pch.dma = 0; in csa_stopplaydma()
384 if (!csa->rch.dma) { in csa_stopplaydma()
397 if (csa->rch.dma) { in csa_stopcapturedma()
398 resp = &csa->res; in csa_stopcapturedma()
400 csa->cctl = ul & 0x0000ffff; in csa_stopcapturedma()
403 csa->rch.dma = 0; in csa_stopcapturedma()
411 if (!csa->pch.dma) { in csa_stopcapturedma()
480 struct csa_info *csa = ch->parent; in csa_setupchan()
481 csa_res *resp = &csa->res; in csa_setupchan()
484 if (ch->dir == PCMDIR_PLAY) { in csa_setupchan()
486 csa_writemem(resp, BA1_PBA, sndbuf_getbufaddr(ch->buffer)); in csa_setupchan()
489 csa->pfie = csa_readmem(resp, BA1_PFIE) & ~0x0000f03f; in csa_setupchan()
490 if (!(ch->fmt & AFMT_SIGNED)) in csa_setupchan()
491 csa->pfie |= 0x8000; in csa_setupchan()
492 if (ch->fmt & AFMT_BIGENDIAN) in csa_setupchan()
493 csa->pfie |= 0x4000; in csa_setupchan()
494 if (AFMT_CHANNEL(ch->fmt) < 2) in csa_setupchan()
495 csa->pfie |= 0x2000; in csa_setupchan()
496 if (ch->fmt & AFMT_8BIT) in csa_setupchan()
497 csa->pfie |= 0x1000; in csa_setupchan()
498 csa_writemem(resp, BA1_PFIE, csa->pfie); in csa_setupchan()
501 if (ch->fmt & AFMT_16BIT) in csa_setupchan()
503 if (AFMT_CHANNEL(ch->fmt) > 1) in csa_setupchan()
505 tmp--; in csa_setupchan()
511 /* rate */ in csa_setupchan()
512 csa_setplaysamplerate(resp, ch->spd); in csa_setupchan()
513 } else if (ch->dir == PCMDIR_REC) { in csa_setupchan()
515 csa_writemem(resp, BA1_CBA, sndbuf_getbufaddr(ch->buffer)); in csa_setupchan()
520 /* rate */ in csa_setupchan()
521 csa_setcapturesamplerate(resp, ch->spd); in csa_setupchan()
526 /* -------------------------------------------------------------------- */
527 /* channel interface */
533 struct csa_chinfo *ch = (dir == PCMDIR_PLAY)? &csa->pch : &csa->rch; in csachan_init()
535 ch->parent = csa; in csachan_init()
536 ch->channel = c; in csachan_init()
537 ch->buffer = b; in csachan_init()
538 ch->dir = dir; in csachan_init()
539 if (sndbuf_alloc(ch->buffer, csa->parent_dmat, 0, CS461x_BUFFSIZE) != 0) in csachan_init()
549 ch->fmt = format; in csachan_setformat()
558 ch->spd = speed; in csachan_setspeed()
559 return ch->spd; /* XXX calc real speed */ in csachan_setspeed()
572 struct csa_info *csa = ch->parent; in csachan_trigger()
580 if (ch->dir == PCMDIR_PLAY) in csachan_trigger()
585 if (ch->dir == PCMDIR_PLAY) in csachan_trigger()
589 csa_active(csa, -1); in csachan_trigger()
598 struct csa_info *csa = ch->parent; in csachan_getptr()
602 resp = &csa->res; in csachan_getptr()
604 if (ch->dir == PCMDIR_PLAY) { in csachan_getptr()
605 ptr = csa_readmem(resp, BA1_PBA) - sndbuf_getbufaddr(ch->buffer); in csachan_getptr()
606 if ((ch->fmt & AFMT_U8) != 0 || (ch->fmt & AFMT_S8) != 0) in csachan_getptr()
609 ptr = csa_readmem(resp, BA1_CBA) - sndbuf_getbufaddr(ch->buffer); in csachan_getptr()
610 if ((ch->fmt & AFMT_U8) != 0 || (ch->fmt & AFMT_S8) != 0) in csachan_getptr()
621 return (ch->dir == PCMDIR_PLAY)? &csa_playcaps : &csa_reccaps; in csachan_getcaps()
636 /* -------------------------------------------------------------------- */
643 if ((csa->binfo->hisr & HISR_VC0) != 0) in csa_intr()
644 chn_intr(csa->pch.channel); in csa_intr()
645 if ((csa->binfo->hisr & HISR_VC1) != 0) in csa_intr()
646 chn_intr(csa->rch.channel); in csa_intr()
649 /* -------------------------------------------------------------------- */
660 resp = &csa->res; in csa_init()
662 csa->pfie = 0; in csa_init()
690 resp = &csa->res; in csa_allocres()
691 if (resp->io == NULL) { in csa_allocres()
692 resp->io = bus_alloc_resource_any(dev, SYS_RES_MEMORY, in csa_allocres()
693 &resp->io_rid, RF_ACTIVE); in csa_allocres()
694 if (resp->io == NULL) in csa_allocres()
697 if (resp->mem == NULL) { in csa_allocres()
698 resp->mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, in csa_allocres()
699 &resp->mem_rid, RF_ACTIVE); in csa_allocres()
700 if (resp->mem == NULL) in csa_allocres()
703 if (resp->irq == NULL) { in csa_allocres()
704 resp->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, in csa_allocres()
705 &resp->irq_rid, RF_ACTIVE | RF_SHAREABLE); in csa_allocres()
706 if (resp->irq == NULL) in csa_allocres()
717 &csa->parent_dmat) != 0) in csa_allocres()
731 resp = &csa->res; in csa_releaseres()
732 if (resp->irq != NULL) { in csa_releaseres()
733 if (csa->ih) in csa_releaseres()
734 bus_teardown_intr(dev, resp->irq, csa->ih); in csa_releaseres()
735 bus_release_resource(dev, SYS_RES_IRQ, resp->irq_rid, resp->irq); in csa_releaseres()
736 resp->irq = NULL; in csa_releaseres()
738 if (resp->io != NULL) { in csa_releaseres()
739 bus_release_resource(dev, SYS_RES_MEMORY, resp->io_rid, resp->io); in csa_releaseres()
740 resp->io = NULL; in csa_releaseres()
742 if (resp->mem != NULL) { in csa_releaseres()
743 bus_release_resource(dev, SYS_RES_MEMORY, resp->mem_rid, resp->mem); in csa_releaseres()
744 resp->mem = NULL; in csa_releaseres()
746 if (csa->parent_dmat != NULL) { in csa_releaseres()
747 bus_dma_tag_destroy(csa->parent_dmat); in csa_releaseres()
748 csa->parent_dmat = NULL; in csa_releaseres()
763 if (func == NULL || func->func != SCF_PCM) in pcmcsa_probe()
766 s = "CS461x PCM Audio"; in pcmcsa_probe()
783 csa->binfo = func->varinfo; in pcmcsa_attach()
786 * PCTL and CCTL can be stored into csa->pctl and csa->cctl, in pcmcsa_attach()
789 csa->pch.dma = csa->rch.dma = 1; in pcmcsa_attach()
790 csa->active = 0; in pcmcsa_attach()
791 csa->card = csa->binfo->card; in pcmcsa_attach()
794 resp = &csa->res; in pcmcsa_attach()
795 resp->io_rid = PCIR_BAR(0); in pcmcsa_attach()
796 resp->mem_rid = PCIR_BAR(1); in pcmcsa_attach()
797 resp->irq_rid = 0; in pcmcsa_attach()
813 if (csa->card->inv_eapd) in pcmcsa_attach()
815 if (mixer_init(dev, ac97_getmixerclass(), codec) == -1) { in pcmcsa_attach()
822 rman_get_start(resp->irq), in pcmcsa_attach()
826 if (snd_setup_intr(dev, resp->irq, 0, csa_intr, csa, &csa->ih)) { in pcmcsa_attach()
833 csa_active(csa, -1); in pcmcsa_attach()
873 csa_readcodec(&csa->res, BA0_AC97_RESET + count, &csa->ac97[i]); in csa_ac97_suspend()
876 csa_writecodec(&csa->res, BA0_AC97_MASTER_VOLUME, 0x8000); in csa_ac97_suspend()
877 csa_writecodec(&csa->res, BA0_AC97_HEADPHONE_VOLUME, 0x8000); in csa_ac97_suspend()
878 csa_writecodec(&csa->res, BA0_AC97_MASTER_VOLUME_MONO, 0x8000); in csa_ac97_suspend()
879 csa_writecodec(&csa->res, BA0_AC97_PCM_OUT_VOLUME, 0x8000); in csa_ac97_suspend()
881 csa_readcodec(&csa->res, BA0_AC97_POWERDOWN, &csa->ac97_powerdown); in csa_ac97_suspend()
882 csa_readcodec(&csa->res, BA0_AC97_GENERAL_PURPOSE, in csa_ac97_suspend()
883 &csa->ac97_general_purpose); in csa_ac97_suspend()
892 csa_readcodec(&csa->res, BA0_AC97_POWERDOWN, &tmp); in csa_ac97_suspend()
893 csa_writecodec(&csa->res, BA0_AC97_POWERDOWN, in csa_ac97_suspend()
896 csa_readcodec(&csa->res, BA0_AC97_POWERDOWN, &tmp); in csa_ac97_suspend()
897 csa_writecodec(&csa->res, BA0_AC97_POWERDOWN, in csa_ac97_suspend()
900 csa_readcodec(&csa->res, BA0_AC97_POWERDOWN, &tmp); in csa_ac97_suspend()
901 csa_writecodec(&csa->res, BA0_AC97_POWERDOWN, in csa_ac97_suspend()
920 csa_writecodec(&csa->res, BA0_AC97_GENERAL_PURPOSE, in csa_ac97_resume()
921 csa->ac97_general_purpose); in csa_ac97_resume()
926 csa_writecodec(&csa->res, BA0_AC97_POWERDOWN, csa->ac97_powerdown); in csa_ac97_resume()
935 csa_writecodec(&csa->res, BA0_AC97_RESET + count, csa->ac97[i]); in csa_ac97_resume()
945 resp = &csa->res; in pcmcsa_suspend()
966 csa_writecodec(&csa->res, BA0_AC97_POWERDOWN, 0x300); in pcmcsa_suspend()
978 csa_active(csa, -1); in pcmcsa_suspend()
990 resp = &csa->res; in pcmcsa_resume()
1009 csa_setupchan(&csa->pch); in pcmcsa_resume()
1011 csa_setupchan(&csa->rch); in pcmcsa_resume()
1014 csa_active(csa, -1); in pcmcsa_resume()
1020 /* Device interface */
1031 "pcm",