Lines Matching +full:on +full:- +full:the +full:- +full:go
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHERIN CONTRACT, STRICT
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THEPOSSIBILITY OF
30 * The order of pokes in the initiation sequence is based on Linux
65 /* ------------------------------------------------------------------------- */
101 /* -------------------------------------------------------------------- */
105 static u_int32_t adcdac_go(struct sc_chinfo *ch, u_int32_t go);
113 /* talk to the card */
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()
184 tries --; in cs4281_waitset()
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()
347 u_int32_t go; in cs4281chan_setblocksize() local
349 go = adcdac_go(ch, 0); 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()
357 adcdac_go(ch, go); 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()
369 u_int32_t go, v, r; in cs4281chan_setspeed() local
371 go = adcdac_go(ch, 0); /* pause */ in cs4281chan_setspeed()
372 r = (ch->dma_chan == CS4281_DMA_PLAY) ? CS4281PCI_DACSR : CS4281PCI_ADCSR; in cs4281chan_setspeed()
375 adcdac_go(ch, go); /* unpause */ 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()
386 u_int32_t v, go; in cs4281chan_setformat() local
388 go = adcdac_go(ch, 0); /* pause */ 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()
398 adcdac_go(ch, go); /* unpause */ 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()
424 cs4281chan_trigger(kobj_t obj, void *data, int go) in cs4281chan_trigger() argument
428 switch(go) { in cs4281chan_trigger()
463 /* -------------------------------------------------------------------- */
466 /* adcdac_go enables/disable DMA channel, returns non-zero if DMA was
470 adcdac_go(struct sc_chinfo *ch, u_int32_t go) in adcdac_go() argument
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()
477 if (go) 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()
491 u_int32_t go; in adcdac_prog() local
493 if (!ch->dma_setup) { in adcdac_prog()
494 go = adcdac_go(ch, 0); 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()
500 adcdac_go(ch, go); in adcdac_prog()
504 /* -------------------------------------------------------------------- */
505 /* The interrupt handler */
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 /* -------------------------------------------------------------------- */
542 /* Power on */ in cs4281_power()
552 DEB(printf("cs4281_power %d -> %d\n", sc->power, state)); in cs4281_power()
553 sc->power = state; in cs4281_power()
567 /* (1) Make ESYN 0 to turn sync pulse on AC97 link */ in cs4281_init()
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()
664 /* Power on the ADC */ in cs4281_init()
701 /* Set Auto-Initialize and set directions */ in cs4281_init()
735 /* -------------------------------------------------------------------- */
736 /* Probe and attach the card */
762 sc->dev = dev; in cs4281_pci_attach()
763 sc->type = pci_get_devid(dev); in cs4281_pci_attach()
768 /* Reset the power state. */ 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()
831 device_printf(dev, "unable to initialize the card\n"); in cs4281_pci_attach()
847 snprintf(status, SND_STATUSLEN, "%s 0x%jx irq %jd on %s", 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()
926 device_printf(dev, "unable to reinitialize the card\n"); in cs4281_pci_resume()
931 if (mixer_reinit(dev) == -1) { in cs4281_pci_resume()
932 device_printf(dev, "unable to reinitialize the mixer\n"); 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()