Lines Matching +full:dac +full:- +full:mode +full:- +full:mask
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
65 /* ------------------------------------------------------------------------- */
101 /* -------------------------------------------------------------------- */
104 /* ADC/DAC control */
122 /* -------------------------------------------------------------------- */
143 /* -------------------------------------------------------------------- */
149 return bus_space_read_4(sc->st, sc->sh, regno); in cs4281_rd()
155 bus_space_write_4(sc->st, sc->sh, regno, data); in cs4281_wr()
160 cs4281_clr4(struct sc_info *sc, int regno, u_int32_t mask) in cs4281_clr4() argument
164 cs4281_wr(sc, regno, r & ~mask); in cs4281_clr4()
168 cs4281_set4(struct sc_info *sc, int regno, u_int32_t mask) in cs4281_set4() argument
172 cs4281_wr(sc, regno, v | mask); in cs4281_set4()
176 cs4281_waitset(struct sc_info *sc, int regno, u_int32_t mask, int tries) in cs4281_waitset() argument
183 if ((v & mask) == mask) break; in cs4281_waitset()
184 tries --; in cs4281_waitset()
190 cs4281_waitclr(struct sc_info *sc, int regno, u_int32_t mask, int tries) in cs4281_waitclr() argument
197 if (v & mask) break; in cs4281_waitclr()
198 tries --; in cs4281_waitclr()
203 /* ------------------------------------------------------------------------- */
251 /* -------------------------------------------------------------------- */
273 device_printf(sc->dev, "cs4281_rdcd: DCV did not go\n"); in cs4281_rdcd()
274 return -1; in cs4281_rdcd()
279 device_printf(sc->dev,"cs4281_rdcd: VSTS did not come\n"); in cs4281_rdcd()
280 return -1; in cs4281_rdcd()
299 device_printf(sc->dev,"cs4281_wrcd: DCV did not go\n"); in cs4281_wrcd()
312 /* ------------------------------------------------------------------------- */
319 struct sc_chinfo *ch = (dir == PCMDIR_PLAY) ? &sc->pch : &sc->rch; in cs4281chan_init()
321 ch->buffer = b; in cs4281chan_init()
322 if (sndbuf_alloc(ch->buffer, sc->parent_dmat, 0, sc->bufsz) != 0) { in cs4281chan_init()
325 ch->parent = sc; in cs4281chan_init()
326 ch->channel = c; in cs4281chan_init()
328 ch->fmt = SND_FORMAT(AFMT_U8, 1, 0); in cs4281chan_init()
329 ch->spd = DSP_DEFAULT_SPEED; in cs4281chan_init()
330 ch->bps = 1; in cs4281chan_init()
331 ch->blksz = sndbuf_getsize(ch->buffer); in cs4281chan_init()
333 ch->dma_chan = (dir == PCMDIR_PLAY) ? CS4281_DMA_PLAY : CS4281_DMA_REC; in cs4281chan_init()
334 ch->dma_setup = 0; in cs4281chan_init()
346 struct sc_info *sc = ch->parent; in cs4281chan_setblocksize()
351 /* 2 interrupts are possible and used in buffer (half-empty,empty), in cs4281chan_setblocksize()
353 ch->blksz = MIN(blocksize, sc->bufsz / 2); in cs4281chan_setblocksize()
354 sndbuf_resize(ch->buffer, 2, ch->blksz); in cs4281chan_setblocksize()
355 ch->dma_setup = 0; in cs4281chan_setblocksize()
359 DEB(printf("cs4281chan_setblocksize: blksz %d Setting %d\n", blocksize, ch->blksz)); in cs4281chan_setblocksize()
361 return ch->blksz; in cs4281chan_setblocksize()
368 struct sc_info *sc = ch->parent; in cs4281chan_setspeed()
372 r = (ch->dma_chan == CS4281_DMA_PLAY) ? CS4281PCI_DACSR : CS4281PCI_ADCSR; in cs4281chan_setspeed()
377 ch->spd = cs4281_rv_to_rate(v); in cs4281chan_setspeed()
378 return ch->spd; in cs4281chan_setspeed()
385 struct sc_info *sc = ch->parent; in cs4281chan_setformat()
390 if (ch->dma_chan == CS4281_DMA_PLAY) in cs4281chan_setformat()
396 cs4281_wr(sc, CS4281PCI_DMR(ch->dma_chan), v); in cs4281chan_setformat()
400 ch->fmt = format; in cs4281chan_setformat()
401 ch->bps = cs4281_format_to_bps(format); in cs4281chan_setformat()
402 ch->dma_setup = 0; in cs4281chan_setformat()
411 struct sc_info *sc = ch->parent; in cs4281chan_getptr()
415 sz = sndbuf_getsize(ch->buffer); in cs4281chan_getptr()
416 dba = cs4281_rd(sc, CS4281PCI_DBA(ch->dma_chan)); in cs4281chan_getptr()
417 dca = cs4281_rd(sc, CS4281PCI_DCA(ch->dma_chan)); in cs4281chan_getptr()
418 ptr = (dca - dba + sz) % sz; in cs4281chan_getptr()
463 /* -------------------------------------------------------------------- */
464 /* ADC/DAC control */
466 /* adcdac_go enables/disable DMA channel, returns non-zero if DMA was
472 struct sc_info *sc = ch->parent; in adcdac_go()
475 going = !(cs4281_rd(sc, CS4281PCI_DCR(ch->dma_chan)) & CS4281PCI_DCR_MSK); in adcdac_go()
478 cs4281_clr4(sc, CS4281PCI_DCR(ch->dma_chan), CS4281PCI_DCR_MSK); in adcdac_go()
480 cs4281_set4(sc, CS4281PCI_DCR(ch->dma_chan), CS4281PCI_DCR_MSK); in adcdac_go()
490 struct sc_info *sc = ch->parent; in adcdac_prog()
493 if (!ch->dma_setup) { in adcdac_prog()
495 cs4281_wr(sc, CS4281PCI_DBA(ch->dma_chan), in adcdac_prog()
496 sndbuf_getbufaddr(ch->buffer)); in adcdac_prog()
497 cs4281_wr(sc, CS4281PCI_DBC(ch->dma_chan), in adcdac_prog()
498 sndbuf_getsize(ch->buffer) / ch->bps - 1); in adcdac_prog()
499 ch->dma_setup = 1; in adcdac_prog()
504 /* -------------------------------------------------------------------- */
518 chn_intr(sc->pch.channel); in cs4281_intr()
523 chn_intr(sc->rch.channel); in cs4281_intr()
527 /* Signal End-of-Interrupt */ in cs4281_intr()
531 /* -------------------------------------------------------------------- */
552 DEB(printf("cs4281_power %d -> %d\n", sc->power, state)); in cs4281_power()
553 sc->power = state; in cs4281_power()
584 /* (4) Power Up - this combination is essential. */ in cs4281_init()
594 device_printf(sc->dev, "Clock stabilization failed\n"); in cs4281_init()
595 return -1; in cs4281_init()
609 device_printf(sc->dev, "codec did not avail\n"); in cs4281_init()
610 return -1; in cs4281_init()
628 device_printf(sc->dev, "codec failed to calibrate\n"); in cs4281_init()
629 return -1; in cs4281_init()
640 device_printf(sc->dev, "cs4281 never got valid data\n"); in cs4281_init()
641 return -1; in cs4281_init()
653 /* Power on the DAC */ in cs4281_init()
657 /* Wait until DAC state ready */ in cs4281_init()
701 /* Set Auto-Initialize and set directions */ in cs4281_init()
735 /* -------------------------------------------------------------------- */
762 sc->dev = dev; in cs4281_pci_attach()
763 sc->type = pci_get_devid(dev); in cs4281_pci_attach()
769 device_printf(dev, "chip is in D%d power mode " in cs4281_pci_attach()
770 "-- setting to D0\n", pci_get_powerstate(dev)); in cs4281_pci_attach()
775 sc->regid = PCIR_BAR(0); in cs4281_pci_attach()
776 sc->regtype = SYS_RES_MEMORY; in cs4281_pci_attach()
777 sc->reg = bus_alloc_resource_any(dev, sc->regtype, &sc->regid, RF_ACTIVE); in cs4281_pci_attach()
778 if (!sc->reg) { in cs4281_pci_attach()
779 sc->regtype = SYS_RES_IOPORT; in cs4281_pci_attach()
780 sc->reg = bus_alloc_resource_any(dev, sc->regtype, &sc->regid, in cs4281_pci_attach()
782 if (!sc->reg) { in cs4281_pci_attach()
787 sc->st = rman_get_bustag(sc->reg); in cs4281_pci_attach()
788 sc->sh = rman_get_bushandle(sc->reg); in cs4281_pci_attach()
790 sc->memid = PCIR_BAR(1); in cs4281_pci_attach()
791 sc->mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->memid, in cs4281_pci_attach()
793 if (sc->mem == NULL) { in cs4281_pci_attach()
798 sc->irqid = 0; in cs4281_pci_attach()
799 sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irqid, in cs4281_pci_attach()
801 if (!sc->irq) { in cs4281_pci_attach()
806 if (snd_setup_intr(dev, sc->irq, 0, cs4281_intr, sc, &sc->ih)) { in cs4281_pci_attach()
811 sc->bufsz = pcm_getbuffersize(dev, 4096, CS4281_DEFAULT_BUFSZ, 65536); in cs4281_pci_attach()
818 /*maxsize*/sc->bufsz, /*nsegments*/1, in cs4281_pci_attach()
821 &sc->parent_dmat) != 0) { in cs4281_pci_attach()
830 if (cs4281_init(sc) == -1) { in cs4281_pci_attach()
848 (sc->regtype == SYS_RES_IOPORT)? "port" : "mem", in cs4281_pci_attach()
849 rman_get_start(sc->reg), rman_get_start(sc->irq), in cs4281_pci_attach()
859 if (sc->reg) in cs4281_pci_attach()
860 bus_release_resource(dev, sc->regtype, sc->regid, sc->reg); in cs4281_pci_attach()
861 if (sc->mem) in cs4281_pci_attach()
862 bus_release_resource(dev, SYS_RES_MEMORY, sc->memid, sc->mem); in cs4281_pci_attach()
863 if (sc->ih) in cs4281_pci_attach()
864 bus_teardown_intr(dev, sc->irq, sc->ih); in cs4281_pci_attach()
865 if (sc->irq) in cs4281_pci_attach()
866 bus_release_resource(dev, SYS_RES_IRQ, sc->irqid, sc->irq); in cs4281_pci_attach()
867 if (sc->parent_dmat) in cs4281_pci_attach()
868 bus_dma_tag_destroy(sc->parent_dmat); in cs4281_pci_attach()
889 bus_release_resource(dev, sc->regtype, sc->regid, sc->reg); in cs4281_pci_detach()
890 bus_release_resource(dev, SYS_RES_MEMORY, sc->memid, sc->mem); in cs4281_pci_detach()
891 bus_teardown_intr(dev, sc->irq, sc->ih); in cs4281_pci_detach()
892 bus_release_resource(dev, SYS_RES_IRQ, sc->irqid, sc->irq); in cs4281_pci_detach()
893 bus_dma_tag_destroy(sc->parent_dmat); in cs4281_pci_detach()
906 sc->rch.dma_active = adcdac_go(&sc->rch, 0); in cs4281_pci_suspend()
907 sc->pch.dma_active = adcdac_go(&sc->pch, 0); in cs4281_pci_suspend()
925 if (cs4281_init(sc) == -1) { in cs4281_pci_resume()
931 if (mixer_reinit(dev) == -1) { in cs4281_pci_resume()
937 cs4281chan_setspeed(NULL, &sc->rch, sc->rch.spd); in cs4281_pci_resume()
938 cs4281chan_setblocksize(NULL, &sc->rch, sc->rch.blksz); in cs4281_pci_resume()
939 cs4281chan_setformat(NULL, &sc->rch, sc->rch.fmt); in cs4281_pci_resume()
940 adcdac_go(&sc->rch, sc->rch.dma_active); in cs4281_pci_resume()
942 cs4281chan_setspeed(NULL, &sc->pch, sc->pch.spd); in cs4281_pci_resume()
943 cs4281chan_setblocksize(NULL, &sc->pch, sc->pch.blksz); in cs4281_pci_resume()
944 cs4281chan_setformat(NULL, &sc->pch, sc->pch.fmt); in cs4281_pci_resume()
945 adcdac_go(&sc->pch, sc->pch.dma_active); in cs4281_pci_resume()