Home | History | Annotate | Line # | Download | only in ebus
cs4231_ebus.c revision 1.5.2.2
      1  1.5.2.2  nathanw /*	$NetBSD: cs4231_ebus.c,v 1.5.2.2 2002/04/01 07:45:12 nathanw Exp $ */
      2  1.5.2.2  nathanw 
      3  1.5.2.2  nathanw /*
      4  1.5.2.2  nathanw  * Copyright (c) 2002 Valeriy E. Ushakov
      5  1.5.2.2  nathanw  * All rights reserved.
      6  1.5.2.2  nathanw  *
      7  1.5.2.2  nathanw  * Redistribution and use in source and binary forms, with or without
      8  1.5.2.2  nathanw  * modification, are permitted provided that the following conditions
      9  1.5.2.2  nathanw  * are met:
     10  1.5.2.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     11  1.5.2.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     12  1.5.2.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.5.2.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     14  1.5.2.2  nathanw  *    documentation and/or other materials provided with the distribution.
     15  1.5.2.2  nathanw  * 3. The name of the author may not be used to endorse or promote products
     16  1.5.2.2  nathanw  *    derived from this software without specific prior written permission
     17  1.5.2.2  nathanw  *
     18  1.5.2.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  1.5.2.2  nathanw  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  1.5.2.2  nathanw  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  1.5.2.2  nathanw  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  1.5.2.2  nathanw  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23  1.5.2.2  nathanw  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24  1.5.2.2  nathanw  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25  1.5.2.2  nathanw  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26  1.5.2.2  nathanw  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27  1.5.2.2  nathanw  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  1.5.2.2  nathanw  */
     29  1.5.2.2  nathanw 
     30  1.5.2.2  nathanw #include <sys/param.h>
     31  1.5.2.2  nathanw #include <sys/systm.h>
     32  1.5.2.2  nathanw #include <sys/errno.h>
     33  1.5.2.2  nathanw #include <sys/device.h>
     34  1.5.2.2  nathanw #include <sys/malloc.h>
     35  1.5.2.2  nathanw 
     36  1.5.2.2  nathanw #include <machine/autoconf.h>
     37  1.5.2.2  nathanw #include <machine/cpu.h>
     38  1.5.2.2  nathanw #include <dev/ebus/ebusreg.h>
     39  1.5.2.2  nathanw #include <dev/ebus/ebusvar.h>
     40  1.5.2.2  nathanw 
     41  1.5.2.2  nathanw #include <sys/audioio.h>
     42  1.5.2.2  nathanw #include <dev/audio_if.h>
     43  1.5.2.2  nathanw 
     44  1.5.2.2  nathanw #include <dev/ic/ad1848reg.h>
     45  1.5.2.2  nathanw #include <dev/ic/cs4231reg.h>
     46  1.5.2.2  nathanw #include <dev/ic/ad1848var.h>
     47  1.5.2.2  nathanw #include <dev/ic/cs4231var.h>
     48  1.5.2.2  nathanw 
     49  1.5.2.2  nathanw #ifdef AUDIO_DEBUG
     50  1.5.2.2  nathanw int cs4231_ebus_debug = 0;
     51  1.5.2.2  nathanw #define DPRINTF(x)	if (cs4231_ebus_debug) printf x
     52  1.5.2.2  nathanw #else
     53  1.5.2.2  nathanw #define DPRINTF(x)
     54  1.5.2.2  nathanw #endif
     55  1.5.2.2  nathanw 
     56  1.5.2.2  nathanw 
     57  1.5.2.2  nathanw struct cs4231_ebus_softc {
     58  1.5.2.2  nathanw 	struct cs4231_softc sc_cs4231;
     59  1.5.2.2  nathanw 
     60  1.5.2.2  nathanw 	bus_space_tag_t sc_bt;
     61  1.5.2.2  nathanw 	bus_space_handle_t sc_pdmareg; /* playback DMA */
     62  1.5.2.2  nathanw 	bus_space_handle_t sc_cdmareg; /* record DMA */
     63  1.5.2.2  nathanw };
     64  1.5.2.2  nathanw 
     65  1.5.2.2  nathanw 
     66  1.5.2.2  nathanw void	cs4231_ebus_attach(struct device *, struct device *, void *);
     67  1.5.2.2  nathanw int	cs4231_ebus_match(struct device *, struct cfdata *, void *);
     68  1.5.2.2  nathanw 
     69  1.5.2.2  nathanw struct cfattach audiocs_ebus_ca = {
     70  1.5.2.2  nathanw 	sizeof(struct cs4231_ebus_softc), cs4231_ebus_match, cs4231_ebus_attach
     71  1.5.2.2  nathanw };
     72  1.5.2.2  nathanw 
     73  1.5.2.2  nathanw 
     74  1.5.2.2  nathanw /* audio_hw_if methods specific to ebus dma */
     75  1.5.2.2  nathanw static int	cs4231_ebus_trigger_output(void *, void *, void *, int,
     76  1.5.2.2  nathanw 					   void (*)(void *), void *,
     77  1.5.2.2  nathanw 					   struct audio_params *);
     78  1.5.2.2  nathanw static int	cs4231_ebus_trigger_input(void *, void *, void *, int,
     79  1.5.2.2  nathanw 					  void (*)(void *), void *,
     80  1.5.2.2  nathanw 					  struct audio_params *);
     81  1.5.2.2  nathanw static int	cs4231_ebus_halt_output(void *);
     82  1.5.2.2  nathanw static int	cs4231_ebus_halt_input(void *);
     83  1.5.2.2  nathanw 
     84  1.5.2.2  nathanw struct audio_hw_if audiocs_ebus_hw_if = {
     85  1.5.2.2  nathanw 	cs4231_open,
     86  1.5.2.2  nathanw 	cs4231_close,
     87  1.5.2.2  nathanw 	NULL,			/* drain */
     88  1.5.2.2  nathanw 	ad1848_query_encoding,
     89  1.5.2.2  nathanw 	ad1848_set_params,
     90  1.5.2.2  nathanw 	cs4231_round_blocksize,
     91  1.5.2.2  nathanw 	ad1848_commit_settings,
     92  1.5.2.2  nathanw 	NULL,			/* init_output */
     93  1.5.2.2  nathanw 	NULL,			/* init_input */
     94  1.5.2.2  nathanw 	NULL,			/* start_output */
     95  1.5.2.2  nathanw 	NULL,			/* start_input */
     96  1.5.2.2  nathanw 	cs4231_ebus_halt_output,
     97  1.5.2.2  nathanw 	cs4231_ebus_halt_input,
     98  1.5.2.2  nathanw 	NULL,			/* speaker_ctl */
     99  1.5.2.2  nathanw 	cs4231_getdev,
    100  1.5.2.2  nathanw 	NULL,			/* setfd */
    101  1.5.2.2  nathanw 	cs4231_set_port,
    102  1.5.2.2  nathanw 	cs4231_get_port,
    103  1.5.2.2  nathanw 	cs4231_query_devinfo,
    104  1.5.2.2  nathanw 	cs4231_malloc,
    105  1.5.2.2  nathanw 	cs4231_free,
    106  1.5.2.2  nathanw 	cs4231_round_buffersize,
    107  1.5.2.2  nathanw 	NULL,			/* mappage */
    108  1.5.2.2  nathanw 	cs4231_get_props,
    109  1.5.2.2  nathanw 	cs4231_ebus_trigger_output,
    110  1.5.2.2  nathanw 	cs4231_ebus_trigger_input,
    111  1.5.2.2  nathanw 	NULL,			/* dev_ioctl */
    112  1.5.2.2  nathanw };
    113  1.5.2.2  nathanw 
    114  1.5.2.2  nathanw #ifdef AUDIO_DEBUG
    115  1.5.2.2  nathanw static void	cs4231_ebus_regdump(char *, struct cs4231_ebus_softc *);
    116  1.5.2.2  nathanw #endif
    117  1.5.2.2  nathanw 
    118  1.5.2.2  nathanw static int	cs4231_ebus_dma_reset(bus_space_tag_t, bus_space_handle_t);
    119  1.5.2.2  nathanw static int	cs4231_ebus_trigger_transfer(struct cs4231_softc *,
    120  1.5.2.2  nathanw 			struct cs_transfer *,
    121  1.5.2.2  nathanw 			bus_space_tag_t, bus_space_handle_t,
    122  1.5.2.2  nathanw 			int, void *, void *, int, void (*)(void *), void *,
    123  1.5.2.2  nathanw 			struct audio_params *);
    124  1.5.2.2  nathanw static void	cs4231_ebus_dma_advance(struct cs_transfer *,
    125  1.5.2.2  nathanw 					bus_space_tag_t, bus_space_handle_t);
    126  1.5.2.2  nathanw static int	cs4231_ebus_dma_intr(struct cs_transfer *,
    127  1.5.2.2  nathanw 				     bus_space_tag_t, bus_space_handle_t);
    128  1.5.2.2  nathanw static int	cs4231_ebus_intr(void *);
    129  1.5.2.2  nathanw 
    130  1.5.2.2  nathanw 
    131  1.5.2.2  nathanw int
    132  1.5.2.2  nathanw cs4231_ebus_match(parent, cf, aux)
    133  1.5.2.2  nathanw 	struct device *parent;
    134  1.5.2.2  nathanw 	struct cfdata *cf;
    135  1.5.2.2  nathanw 	void *aux;
    136  1.5.2.2  nathanw {
    137  1.5.2.2  nathanw 	struct ebus_attach_args *ea = aux;
    138  1.5.2.2  nathanw 
    139  1.5.2.2  nathanw 	if (strcmp(ea->ea_name, AUDIOCS_PROM_NAME) == 0)
    140  1.5.2.2  nathanw 		return (1);
    141  1.5.2.2  nathanw #ifdef __sparc__		/* XXX: Krups */
    142  1.5.2.2  nathanw 	if (strcmp(ea->ea_name, "sound") == 0)
    143  1.5.2.2  nathanw 		return (1);
    144  1.5.2.2  nathanw #endif
    145  1.5.2.2  nathanw 
    146  1.5.2.2  nathanw 	return (0);
    147  1.5.2.2  nathanw }
    148  1.5.2.2  nathanw 
    149  1.5.2.2  nathanw 
    150  1.5.2.2  nathanw void
    151  1.5.2.2  nathanw cs4231_ebus_attach(parent, self, aux)
    152  1.5.2.2  nathanw 	struct device *parent, *self;
    153  1.5.2.2  nathanw 	void *aux;
    154  1.5.2.2  nathanw {
    155  1.5.2.2  nathanw 	struct cs4231_ebus_softc *ebsc = (struct cs4231_ebus_softc *)self;
    156  1.5.2.2  nathanw 	struct cs4231_softc *sc = &ebsc->sc_cs4231;
    157  1.5.2.2  nathanw 	struct ebus_attach_args *ea = aux;
    158  1.5.2.2  nathanw 	bus_space_handle_t bh;
    159  1.5.2.2  nathanw 	int i;
    160  1.5.2.2  nathanw 
    161  1.5.2.2  nathanw 	sc->sc_bustag = ebsc->sc_bt = ea->ea_bustag;
    162  1.5.2.2  nathanw 	sc->sc_dmatag = ea->ea_dmatag;
    163  1.5.2.2  nathanw 
    164  1.5.2.2  nathanw 	/*
    165  1.5.2.2  nathanw 	 * These are the register we get from the prom:
    166  1.5.2.2  nathanw 	 *	- CS4231 registers
    167  1.5.2.2  nathanw 	 *	- Playback EBus DMA controller
    168  1.5.2.2  nathanw 	 *	- Capture EBus DMA controller
    169  1.5.2.2  nathanw 	 *	- AUXIO audio register (codec powerdown)
    170  1.5.2.2  nathanw 	 *
    171  1.5.2.2  nathanw 	 * Map my registers in, if they aren't already in virtual
    172  1.5.2.2  nathanw 	 * address space.
    173  1.5.2.2  nathanw 	 */
    174  1.5.2.2  nathanw 	if (bus_space_map(ea->ea_bustag, EBUS_ADDR_FROM_REG(&ea->ea_reg[0]),
    175  1.5.2.2  nathanw 		ea->ea_reg[0].size, 0, &bh) != 0) {
    176  1.5.2.2  nathanw 		printf("%s: unable to map registers\n",
    177  1.5.2.2  nathanw 			self->dv_xname);
    178  1.5.2.2  nathanw 		return;
    179  1.5.2.2  nathanw 	}
    180  1.5.2.2  nathanw 
    181  1.5.2.2  nathanw 	/* XXX: map playback DMA registers (we just know where they are) */
    182  1.5.2.2  nathanw 	if (bus_space_map(ea->ea_bustag,
    183  1.5.2.2  nathanw 			  BUS_ADDR(0x14, 0x702000), /* XXX: magic num */
    184  1.5.2.2  nathanw 			  EBUS_DMAC_SIZE,
    185  1.5.2.2  nathanw 			  0, &ebsc->sc_pdmareg) != 0)
    186  1.5.2.2  nathanw 	{
    187  1.5.2.2  nathanw 		printf("%s: unable to map playback DMA registers\n",
    188  1.5.2.2  nathanw 		       self->dv_xname);
    189  1.5.2.2  nathanw 		return;
    190  1.5.2.2  nathanw 	}
    191  1.5.2.2  nathanw 
    192  1.5.2.2  nathanw 	/* XXX: map capture DMA registers (we just know where they are) */
    193  1.5.2.2  nathanw 	if (bus_space_map(ea->ea_bustag,
    194  1.5.2.2  nathanw 			  BUS_ADDR(0x14, 0x704000), /* XXX: magic num */
    195  1.5.2.2  nathanw 			  EBUS_DMAC_SIZE,
    196  1.5.2.2  nathanw 			  0, &ebsc->sc_cdmareg) != 0)
    197  1.5.2.2  nathanw 	{
    198  1.5.2.2  nathanw 		printf("%s: unable to map capture DMA registers\n",
    199  1.5.2.2  nathanw 		       self->dv_xname);
    200  1.5.2.2  nathanw 		return;
    201  1.5.2.2  nathanw 	}
    202  1.5.2.2  nathanw 
    203  1.5.2.2  nathanw 	/* establish interrupt channels */
    204  1.5.2.2  nathanw 	for (i = 0; i < ea->ea_nintr; ++i)
    205  1.5.2.2  nathanw 		bus_intr_establish(ea->ea_bustag,
    206  1.5.2.2  nathanw 				   ea->ea_intr[i], IPL_AUDIO, 0,
    207  1.5.2.2  nathanw 				   cs4231_ebus_intr, ebsc);
    208  1.5.2.2  nathanw 
    209  1.5.2.2  nathanw 	cs4231_common_attach(sc, bh);
    210  1.5.2.2  nathanw 	printf("\n");
    211  1.5.2.2  nathanw 
    212  1.5.2.2  nathanw 	/* XXX: todo: move to cs4231_common_attach, pass hw_if as arg? */
    213  1.5.2.2  nathanw 	audio_attach_mi(&audiocs_ebus_hw_if, sc, &sc->sc_ad1848.sc_dev);
    214  1.5.2.2  nathanw }
    215  1.5.2.2  nathanw 
    216  1.5.2.2  nathanw 
    217  1.5.2.2  nathanw #ifdef AUDIO_DEBUG
    218  1.5.2.2  nathanw static void
    219  1.5.2.2  nathanw cs4231_ebus_regdump(label, ebsc)
    220  1.5.2.2  nathanw 	char *label;
    221  1.5.2.2  nathanw 	struct cs4231_ebus_softc *ebsc;
    222  1.5.2.2  nathanw {
    223  1.5.2.2  nathanw 	/* char bits[128]; */
    224  1.5.2.2  nathanw 
    225  1.5.2.2  nathanw 	printf("cs4231regdump(%s): regs:", label);
    226  1.5.2.2  nathanw 	/* XXX: dump ebus dma and aux registers */
    227  1.5.2.2  nathanw 	ad1848_dump_regs(&ebsc->sc_cs4231.sc_ad1848);
    228  1.5.2.2  nathanw }
    229  1.5.2.2  nathanw #endif /* AUDIO_DEBUG */
    230  1.5.2.2  nathanw 
    231  1.5.2.2  nathanw 
    232  1.5.2.2  nathanw /* XXX: nothing CS4231-specific in this code... */
    233  1.5.2.2  nathanw static int
    234  1.5.2.2  nathanw cs4231_ebus_dma_reset(dt, dh)
    235  1.5.2.2  nathanw 	bus_space_tag_t dt;
    236  1.5.2.2  nathanw 	bus_space_handle_t dh;
    237  1.5.2.2  nathanw {
    238  1.5.2.2  nathanw 	u_int32_t csr;
    239  1.5.2.2  nathanw 	int timo;
    240  1.5.2.2  nathanw 
    241  1.5.2.2  nathanw 	/* reset, also clear TC, just in case */
    242  1.5.2.2  nathanw 	bus_space_write_4(dt, dh, EBUS_DMAC_DCSR, EBDMA_RESET | EBDMA_TC);
    243  1.5.2.2  nathanw 
    244  1.5.2.2  nathanw 	for (timo = 50000; timo != 0; --timo) {
    245  1.5.2.2  nathanw 		csr = bus_space_read_4(dt, dh, EBUS_DMAC_DCSR);
    246  1.5.2.2  nathanw 		if ((csr & (EBDMA_CYC_PEND | EBDMA_DRAIN)) == 0)
    247  1.5.2.2  nathanw 			break;
    248  1.5.2.2  nathanw 	}
    249  1.5.2.2  nathanw 
    250  1.5.2.2  nathanw 	if (timo == 0) {
    251  1.5.2.2  nathanw 		char bits[128];
    252  1.5.2.2  nathanw 
    253  1.5.2.2  nathanw 		printf("cs4231_ebus_dma_reset: timed out: csr=%s\n",
    254  1.5.2.2  nathanw 		       bitmask_snprintf(csr, EBUS_DCSR_BITS,
    255  1.5.2.2  nathanw 					bits, sizeof(bits)));
    256  1.5.2.2  nathanw 		return (ETIMEDOUT);
    257  1.5.2.2  nathanw 	}
    258  1.5.2.2  nathanw 
    259  1.5.2.2  nathanw 	bus_space_write_4(dt, dh, EBUS_DMAC_DCSR, csr & ~EBDMA_RESET);
    260  1.5.2.2  nathanw 	return (0);
    261  1.5.2.2  nathanw }
    262  1.5.2.2  nathanw 
    263  1.5.2.2  nathanw 
    264  1.5.2.2  nathanw static void
    265  1.5.2.2  nathanw cs4231_ebus_dma_advance(t, dt, dh)
    266  1.5.2.2  nathanw 	struct cs_transfer *t;
    267  1.5.2.2  nathanw 	bus_space_tag_t dt;
    268  1.5.2.2  nathanw 	bus_space_handle_t dh;
    269  1.5.2.2  nathanw {
    270  1.5.2.2  nathanw 	bus_addr_t dmaaddr;
    271  1.5.2.2  nathanw 	bus_size_t dmasize;
    272  1.5.2.2  nathanw 
    273  1.5.2.2  nathanw 	cs4231_transfer_advance(t, &dmaaddr, &dmasize);
    274  1.5.2.2  nathanw 
    275  1.5.2.2  nathanw 	bus_space_write_4(dt, dh, EBUS_DMAC_DNBR, (u_int32_t)dmasize);
    276  1.5.2.2  nathanw 	bus_space_write_4(dt, dh, EBUS_DMAC_DNAR, (u_int32_t)dmaaddr);
    277  1.5.2.2  nathanw }
    278  1.5.2.2  nathanw 
    279  1.5.2.2  nathanw 
    280  1.5.2.2  nathanw /*
    281  1.5.2.2  nathanw  * Trigger transfer "t" using DMA controller "dmac".
    282  1.5.2.2  nathanw  * "iswrite" defines direction of the transfer.
    283  1.5.2.2  nathanw  */
    284  1.5.2.2  nathanw static int
    285  1.5.2.2  nathanw cs4231_ebus_trigger_transfer(sc, t, dt, dh, iswrite,
    286  1.5.2.2  nathanw 			     start, end, blksize,
    287  1.5.2.2  nathanw 			     intr, arg, param)
    288  1.5.2.2  nathanw 	struct cs4231_softc *sc;
    289  1.5.2.2  nathanw 	struct cs_transfer *t;
    290  1.5.2.2  nathanw 	bus_space_tag_t dt;
    291  1.5.2.2  nathanw 	bus_space_handle_t dh;
    292  1.5.2.2  nathanw 	int iswrite;
    293  1.5.2.2  nathanw 	void *start, *end;
    294  1.5.2.2  nathanw 	int blksize;
    295  1.5.2.2  nathanw 	void (*intr)(void *);
    296  1.5.2.2  nathanw 	void *arg;
    297  1.5.2.2  nathanw 	struct audio_params *param;
    298  1.5.2.2  nathanw {
    299  1.5.2.2  nathanw 	u_int32_t csr;
    300  1.5.2.2  nathanw 	bus_addr_t dmaaddr;
    301  1.5.2.2  nathanw 	bus_size_t dmasize;
    302  1.5.2.2  nathanw 	int ret;
    303  1.5.2.2  nathanw 
    304  1.5.2.2  nathanw 	ret = cs4231_transfer_init(sc, t, &dmaaddr, &dmasize,
    305  1.5.2.2  nathanw 				   start, end, blksize, intr, arg);
    306  1.5.2.2  nathanw 	if (ret != 0)
    307  1.5.2.2  nathanw 		return (ret);
    308  1.5.2.2  nathanw 
    309  1.5.2.2  nathanw 	ret = cs4231_ebus_dma_reset(dt, dh);
    310  1.5.2.2  nathanw 	if (ret != 0)
    311  1.5.2.2  nathanw 		return (ret);
    312  1.5.2.2  nathanw 
    313  1.5.2.2  nathanw 	csr = bus_space_read_4(dt, dh, EBUS_DMAC_DCSR);
    314  1.5.2.2  nathanw 	bus_space_write_4(dt, dh, EBUS_DMAC_DCSR,
    315  1.5.2.2  nathanw 			  csr | EBDMA_EN_NEXT | (iswrite ? EBDMA_WRITE : 0)
    316  1.5.2.2  nathanw 			  | EBDMA_EN_DMA | EBDMA_EN_CNT | EBDMA_INT_EN);
    317  1.5.2.2  nathanw 
    318  1.5.2.2  nathanw 	/* first load: propagated to DACR/DBCR */
    319  1.5.2.2  nathanw 	bus_space_write_4(dt, dh, EBUS_DMAC_DNBR, (u_int32_t)dmasize);
    320  1.5.2.2  nathanw 	bus_space_write_4(dt, dh, EBUS_DMAC_DNAR, (u_int32_t)dmaaddr);
    321  1.5.2.2  nathanw 
    322  1.5.2.2  nathanw 	/* next load: goes to DNAR/DNBR */
    323  1.5.2.2  nathanw 	cs4231_ebus_dma_advance(t, dt, dh);
    324  1.5.2.2  nathanw 
    325  1.5.2.2  nathanw 	return (0);
    326  1.5.2.2  nathanw }
    327  1.5.2.2  nathanw 
    328  1.5.2.2  nathanw 
    329  1.5.2.2  nathanw static int
    330  1.5.2.2  nathanw cs4231_ebus_trigger_output(addr, start, end, blksize, intr, arg, param)
    331  1.5.2.2  nathanw 	void *addr;
    332  1.5.2.2  nathanw 	void *start, *end;
    333  1.5.2.2  nathanw 	int blksize;
    334  1.5.2.2  nathanw 	void (*intr)(void *);
    335  1.5.2.2  nathanw 	void *arg;
    336  1.5.2.2  nathanw 	struct audio_params *param;
    337  1.5.2.2  nathanw {
    338  1.5.2.2  nathanw 	struct cs4231_ebus_softc *ebsc = addr;
    339  1.5.2.2  nathanw 	struct cs4231_softc *sc = &ebsc->sc_cs4231;
    340  1.5.2.2  nathanw 	int cfg, ret;
    341  1.5.2.2  nathanw 
    342  1.5.2.2  nathanw 	ret = cs4231_ebus_trigger_transfer(sc, &sc->sc_playback,
    343  1.5.2.2  nathanw 					   ebsc->sc_bt, ebsc->sc_pdmareg,
    344  1.5.2.2  nathanw 					   0, /* iswrite */
    345  1.5.2.2  nathanw 					   start, end, blksize,
    346  1.5.2.2  nathanw 					   intr, arg, param);
    347  1.5.2.2  nathanw 	if (ret != 0)
    348  1.5.2.2  nathanw 		return (ret);
    349  1.5.2.2  nathanw 
    350  1.5.2.2  nathanw 	ad_write(&sc->sc_ad1848, SP_LOWER_BASE_COUNT, 0xff);
    351  1.5.2.2  nathanw 	ad_write(&sc->sc_ad1848, SP_UPPER_BASE_COUNT, 0xff);
    352  1.5.2.2  nathanw 
    353  1.5.2.2  nathanw 	cfg = ad_read(&sc->sc_ad1848, SP_INTERFACE_CONFIG);
    354  1.5.2.2  nathanw 	ad_write(&sc->sc_ad1848, SP_INTERFACE_CONFIG, cfg | PLAYBACK_ENABLE);
    355  1.5.2.2  nathanw 
    356  1.5.2.2  nathanw 	return (0);
    357  1.5.2.2  nathanw }
    358  1.5.2.2  nathanw 
    359  1.5.2.2  nathanw 
    360  1.5.2.2  nathanw static int
    361  1.5.2.2  nathanw cs4231_ebus_trigger_input(addr, start, end, blksize, intr, arg, param)
    362  1.5.2.2  nathanw 	void *addr;
    363  1.5.2.2  nathanw 	void *start, *end;
    364  1.5.2.2  nathanw 	int blksize;
    365  1.5.2.2  nathanw 	void (*intr)(void *);
    366  1.5.2.2  nathanw 	void *arg;
    367  1.5.2.2  nathanw 	struct audio_params *param;
    368  1.5.2.2  nathanw {
    369  1.5.2.2  nathanw 	struct cs4231_ebus_softc *ebsc = addr;
    370  1.5.2.2  nathanw 	struct cs4231_softc *sc = &ebsc->sc_cs4231;
    371  1.5.2.2  nathanw 	int cfg, ret;
    372  1.5.2.2  nathanw 
    373  1.5.2.2  nathanw 	ret = cs4231_ebus_trigger_transfer(sc, &sc->sc_capture,
    374  1.5.2.2  nathanw 					   ebsc->sc_bt, ebsc->sc_cdmareg,
    375  1.5.2.2  nathanw 					   1, /* iswrite */
    376  1.5.2.2  nathanw 					   start, end, blksize,
    377  1.5.2.2  nathanw 					   intr, arg, param);
    378  1.5.2.2  nathanw 	if (ret != 0)
    379  1.5.2.2  nathanw 		return (ret);
    380  1.5.2.2  nathanw 
    381  1.5.2.2  nathanw 	ad_write(&sc->sc_ad1848, CS_LOWER_REC_CNT, 0xff);
    382  1.5.2.2  nathanw 	ad_write(&sc->sc_ad1848, CS_UPPER_REC_CNT, 0xff);
    383  1.5.2.2  nathanw 
    384  1.5.2.2  nathanw 	cfg = ad_read(&sc->sc_ad1848, SP_INTERFACE_CONFIG);
    385  1.5.2.2  nathanw 	ad_write(&sc->sc_ad1848, SP_INTERFACE_CONFIG, cfg | CAPTURE_ENABLE);
    386  1.5.2.2  nathanw 
    387  1.5.2.2  nathanw 	return (0);
    388  1.5.2.2  nathanw }
    389  1.5.2.2  nathanw 
    390  1.5.2.2  nathanw 
    391  1.5.2.2  nathanw static int
    392  1.5.2.2  nathanw cs4231_ebus_halt_output(addr)
    393  1.5.2.2  nathanw 	void *addr;
    394  1.5.2.2  nathanw {
    395  1.5.2.2  nathanw 	struct cs4231_ebus_softc *ebsc = addr;
    396  1.5.2.2  nathanw 	struct cs4231_softc *sc = &ebsc->sc_cs4231;
    397  1.5.2.2  nathanw 	u_int32_t csr;
    398  1.5.2.2  nathanw 	int cfg;
    399  1.5.2.2  nathanw 
    400  1.5.2.2  nathanw 	sc->sc_playback.t_active = 0;
    401  1.5.2.2  nathanw 
    402  1.5.2.2  nathanw 	csr = bus_space_read_4(ebsc->sc_bt, ebsc->sc_pdmareg, EBUS_DMAC_DCSR);
    403  1.5.2.2  nathanw 	bus_space_write_4(ebsc->sc_bt, ebsc->sc_pdmareg, EBUS_DMAC_DCSR,
    404  1.5.2.2  nathanw 			  csr & ~EBDMA_EN_DMA);
    405  1.5.2.2  nathanw 
    406  1.5.2.2  nathanw 	cfg = ad_read(&sc->sc_ad1848, SP_INTERFACE_CONFIG);
    407  1.5.2.2  nathanw 	ad_write(&sc->sc_ad1848, SP_INTERFACE_CONFIG,
    408  1.5.2.2  nathanw 		 cfg & ~PLAYBACK_ENABLE);
    409  1.5.2.2  nathanw 
    410  1.5.2.2  nathanw 	return (0);
    411  1.5.2.2  nathanw }
    412  1.5.2.2  nathanw 
    413  1.5.2.2  nathanw 
    414  1.5.2.2  nathanw static int
    415  1.5.2.2  nathanw cs4231_ebus_halt_input(addr)
    416  1.5.2.2  nathanw 	void *addr;
    417  1.5.2.2  nathanw {
    418  1.5.2.2  nathanw 	struct cs4231_ebus_softc *ebsc = addr;
    419  1.5.2.2  nathanw 	struct cs4231_softc *sc = &ebsc->sc_cs4231;
    420  1.5.2.2  nathanw 	u_int32_t csr;
    421  1.5.2.2  nathanw 	int cfg;
    422  1.5.2.2  nathanw 
    423  1.5.2.2  nathanw 	sc->sc_capture.t_active = 0;
    424  1.5.2.2  nathanw 
    425  1.5.2.2  nathanw 	csr = bus_space_read_4(ebsc->sc_bt, ebsc->sc_cdmareg, EBUS_DMAC_DCSR);
    426  1.5.2.2  nathanw 	bus_space_write_4(ebsc->sc_bt, ebsc->sc_cdmareg, EBUS_DMAC_DCSR,
    427  1.5.2.2  nathanw 			  csr & ~EBDMA_EN_DMA);
    428  1.5.2.2  nathanw 
    429  1.5.2.2  nathanw 	cfg = ad_read(&sc->sc_ad1848, SP_INTERFACE_CONFIG);
    430  1.5.2.2  nathanw 	ad_write(&sc->sc_ad1848, SP_INTERFACE_CONFIG,
    431  1.5.2.2  nathanw 		 cfg & ~CAPTURE_ENABLE);
    432  1.5.2.2  nathanw 
    433  1.5.2.2  nathanw 	return (0);
    434  1.5.2.2  nathanw }
    435  1.5.2.2  nathanw 
    436  1.5.2.2  nathanw 
    437  1.5.2.2  nathanw static int
    438  1.5.2.2  nathanw cs4231_ebus_dma_intr(t, dt, dh)
    439  1.5.2.2  nathanw 	struct cs_transfer *t;
    440  1.5.2.2  nathanw 	bus_space_tag_t dt;
    441  1.5.2.2  nathanw 	bus_space_handle_t dh;
    442  1.5.2.2  nathanw {
    443  1.5.2.2  nathanw 	u_int32_t csr;
    444  1.5.2.2  nathanw #ifdef AUDIO_DEBUG
    445  1.5.2.2  nathanw 	char bits[128];
    446  1.5.2.2  nathanw #endif
    447  1.5.2.2  nathanw 
    448  1.5.2.2  nathanw 	/* read DMA status, clear TC bit by writing it back */
    449  1.5.2.2  nathanw 	csr = bus_space_read_4(dt, dh, EBUS_DMAC_DCSR);
    450  1.5.2.2  nathanw 	bus_space_write_4(dt, dh, EBUS_DMAC_DCSR, csr);
    451  1.5.2.2  nathanw 	DPRINTF(("audiocs: %s dcsr=%s\n", t->t_name,
    452  1.5.2.2  nathanw 		 bitmask_snprintf(csr, EBUS_DCSR_BITS, bits, sizeof(bits))));
    453  1.5.2.2  nathanw 
    454  1.5.2.2  nathanw 	if (csr & EBDMA_ERR_PEND) {
    455  1.5.2.2  nathanw 		++t->t_ierrcnt.ev_count;
    456  1.5.2.2  nathanw 		printf("audiocs: %s DMA error, resetting\n", t->t_name);
    457  1.5.2.2  nathanw 		cs4231_ebus_dma_reset(dt, dh);
    458  1.5.2.2  nathanw 		/* how to notify audio(9)??? */
    459  1.5.2.2  nathanw 		return (1);
    460  1.5.2.2  nathanw 	}
    461  1.5.2.2  nathanw 
    462  1.5.2.2  nathanw 	if ((csr & EBDMA_INT_PEND) == 0)
    463  1.5.2.2  nathanw 		return (0);
    464  1.5.2.2  nathanw 
    465  1.5.2.2  nathanw 	++t->t_intrcnt.ev_count;
    466  1.5.2.2  nathanw 
    467  1.5.2.2  nathanw 	if ((csr & EBDMA_TC) == 0) { /* can this happen? */
    468  1.5.2.2  nathanw 		printf("audiocs: %s INT_PEND but !TC\n", t->t_name);
    469  1.5.2.2  nathanw 		return (1);
    470  1.5.2.2  nathanw 	}
    471  1.5.2.2  nathanw 
    472  1.5.2.2  nathanw 	if (!t->t_active)
    473  1.5.2.2  nathanw 		return (1);
    474  1.5.2.2  nathanw 
    475  1.5.2.2  nathanw 	cs4231_ebus_dma_advance(t, dt, dh);
    476  1.5.2.2  nathanw 
    477  1.5.2.2  nathanw 	/* call audio(9) framework while dma is chugging along */
    478  1.5.2.2  nathanw 	if (t->t_intr != NULL)
    479  1.5.2.2  nathanw 		(*t->t_intr)(t->t_arg);
    480  1.5.2.2  nathanw 	return (1);
    481  1.5.2.2  nathanw }
    482  1.5.2.2  nathanw 
    483  1.5.2.2  nathanw 
    484  1.5.2.2  nathanw static int
    485  1.5.2.2  nathanw cs4231_ebus_intr(arg)
    486  1.5.2.2  nathanw 	void *arg;
    487  1.5.2.2  nathanw {
    488  1.5.2.2  nathanw 	struct cs4231_ebus_softc *ebsc = arg;
    489  1.5.2.2  nathanw 	struct cs4231_softc *sc = &ebsc->sc_cs4231;
    490  1.5.2.2  nathanw 	int status;
    491  1.5.2.2  nathanw 	int ret;
    492  1.5.2.2  nathanw #ifdef AUDIO_DEBUG
    493  1.5.2.2  nathanw 	char bits[128];
    494  1.5.2.2  nathanw #endif
    495  1.5.2.2  nathanw 
    496  1.5.2.2  nathanw 	status = ADREAD(&sc->sc_ad1848, AD1848_STATUS);
    497  1.5.2.2  nathanw 
    498  1.5.2.2  nathanw #ifdef AUDIO_DEBUG
    499  1.5.2.2  nathanw 	if (cs4231_ebus_debug > 1)
    500  1.5.2.2  nathanw 		cs4231_ebus_regdump("audiointr", ebsc);
    501  1.5.2.2  nathanw 
    502  1.5.2.2  nathanw 	DPRINTF(("%s: status: %s\n", sc->sc_ad1848.sc_dev.dv_xname,
    503  1.5.2.2  nathanw 		 bitmask_snprintf(status, AD_R2_BITS, bits, sizeof(bits))));
    504  1.5.2.2  nathanw #endif
    505  1.5.2.2  nathanw 
    506  1.5.2.2  nathanw 	if (status & INTERRUPT_STATUS) {
    507  1.5.2.2  nathanw #ifdef AUDIO_DEBUG
    508  1.5.2.2  nathanw 		int reason;
    509  1.5.2.2  nathanw 
    510  1.5.2.2  nathanw 		reason = ad_read(&sc->sc_ad1848, CS_IRQ_STATUS);
    511  1.5.2.2  nathanw 		DPRINTF(("%s: i24: %s\n", sc->sc_ad1848.sc_dev.dv_xname,
    512  1.5.2.2  nathanw 		  bitmask_snprintf(reason, CS_I24_BITS, bits, sizeof(bits))));
    513  1.5.2.2  nathanw #endif
    514  1.5.2.2  nathanw 		/* clear interrupt from ad1848 */
    515  1.5.2.2  nathanw 		ADWRITE(&sc->sc_ad1848, AD1848_STATUS, 0);
    516  1.5.2.2  nathanw 	}
    517  1.5.2.2  nathanw 
    518  1.5.2.2  nathanw 	ret = 0;
    519  1.5.2.2  nathanw 
    520  1.5.2.2  nathanw 	if (cs4231_ebus_dma_intr(&sc->sc_capture,
    521  1.5.2.2  nathanw 				 ebsc->sc_bt, ebsc->sc_cdmareg) != 0)
    522  1.5.2.2  nathanw 	{
    523  1.5.2.2  nathanw 		++sc->sc_intrcnt.ev_count;
    524  1.5.2.2  nathanw 		ret = 1;
    525  1.5.2.2  nathanw 	}
    526  1.5.2.2  nathanw 
    527  1.5.2.2  nathanw 	if (cs4231_ebus_dma_intr(&sc->sc_playback,
    528  1.5.2.2  nathanw 				 ebsc->sc_bt, ebsc->sc_pdmareg) != 0)
    529  1.5.2.2  nathanw 	{
    530  1.5.2.2  nathanw 		++sc->sc_intrcnt.ev_count;
    531  1.5.2.2  nathanw 		ret = 1;
    532  1.5.2.2  nathanw 	}
    533  1.5.2.2  nathanw 
    534  1.5.2.2  nathanw 	return (ret);
    535  1.5.2.2  nathanw }
    536