Home | History | Annotate | Line # | Download | only in ic
cs4231.c revision 1.4.4.4
      1  1.4.4.3   nathanw /*	$NetBSD: cs4231.c,v 1.4.4.4 2002/08/27 23:46:35 nathanw Exp $	*/
      2      1.1       mrg 
      3      1.1       mrg /*-
      4      1.1       mrg  * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
      5      1.1       mrg  * All rights reserved.
      6      1.1       mrg  *
      7      1.1       mrg  * This code is derived from software contributed to The NetBSD Foundation
      8      1.1       mrg  * by Paul Kranenburg.
      9      1.1       mrg  *
     10      1.1       mrg  * Redistribution and use in source and binary forms, with or without
     11      1.1       mrg  * modification, are permitted provided that the following conditions
     12      1.1       mrg  * are met:
     13      1.1       mrg  * 1. Redistributions of source code must retain the above copyright
     14      1.1       mrg  *    notice, this list of conditions and the following disclaimer.
     15      1.1       mrg  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.1       mrg  *    notice, this list of conditions and the following disclaimer in the
     17      1.1       mrg  *    documentation and/or other materials provided with the distribution.
     18      1.1       mrg  * 3. All advertising materials mentioning features or use of this software
     19      1.1       mrg  *    must display the following acknowledgement:
     20      1.1       mrg  *        This product includes software developed by the NetBSD
     21      1.1       mrg  *        Foundation, Inc. and its contributors.
     22      1.1       mrg  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23      1.1       mrg  *    contributors may be used to endorse or promote products derived
     24      1.1       mrg  *    from this software without specific prior written permission.
     25      1.1       mrg  *
     26      1.1       mrg  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27      1.1       mrg  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28      1.1       mrg  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29      1.1       mrg  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30      1.1       mrg  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31      1.1       mrg  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32      1.1       mrg  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33      1.1       mrg  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34      1.1       mrg  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35      1.1       mrg  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36      1.1       mrg  * POSSIBILITY OF SUCH DAMAGE.
     37      1.1       mrg  */
     38  1.4.4.2   nathanw 
     39  1.4.4.2   nathanw #include <sys/cdefs.h>
     40  1.4.4.2   nathanw __KERNEL_RCSID(0, "$NetBSD: cs4231.c,v 1.4.4.4 2002/08/27 23:46:35 nathanw Exp $");
     41      1.1       mrg 
     42      1.1       mrg #include "audio.h"
     43      1.1       mrg #if NAUDIO > 0
     44      1.1       mrg 
     45      1.1       mrg #include <sys/param.h>
     46      1.1       mrg #include <sys/systm.h>
     47      1.1       mrg #include <sys/errno.h>
     48      1.1       mrg #include <sys/device.h>
     49      1.1       mrg #include <sys/malloc.h>
     50      1.1       mrg 
     51      1.1       mrg #include <machine/autoconf.h>
     52      1.1       mrg #include <machine/cpu.h>
     53      1.1       mrg 
     54      1.1       mrg #include <sys/audioio.h>
     55      1.1       mrg #include <dev/audio_if.h>
     56      1.1       mrg 
     57      1.1       mrg #include <dev/ic/ad1848reg.h>
     58      1.1       mrg #include <dev/ic/cs4231reg.h>
     59      1.1       mrg #include <dev/ic/ad1848var.h>
     60      1.1       mrg #include <dev/ic/cs4231var.h>
     61      1.1       mrg 
     62      1.1       mrg /*---*/
     63      1.1       mrg #define CSAUDIO_DAC_LVL		0
     64      1.1       mrg #define CSAUDIO_LINE_IN_LVL	1
     65      1.1       mrg #define CSAUDIO_MONO_LVL	2
     66      1.1       mrg #define CSAUDIO_CD_LVL		3
     67  1.4.4.4   nathanw #define CSAUDIO_OUTPUT_LVL	4
     68      1.1       mrg #define CSAUDIO_OUT_LVL		5
     69      1.1       mrg #define CSAUDIO_LINE_IN_MUTE	6
     70      1.1       mrg #define CSAUDIO_DAC_MUTE	7
     71      1.1       mrg #define CSAUDIO_CD_MUTE		8
     72      1.1       mrg #define CSAUDIO_MONO_MUTE	9
     73  1.4.4.4   nathanw #define CSAUDIO_OUTPUT_MUTE	10
     74  1.4.4.4   nathanw #define CSAUDIO_OUT_MUTE	11
     75  1.4.4.4   nathanw #define CSAUDIO_REC_LVL		12
     76  1.4.4.4   nathanw #define CSAUDIO_RECORD_SOURCE	13
     77  1.4.4.4   nathanw 
     78  1.4.4.4   nathanw #define CSAUDIO_INPUT_CLASS	14
     79  1.4.4.4   nathanw #define CSAUDIO_MONITOR_CLASS	15
     80  1.4.4.4   nathanw #define CSAUDIO_RECORD_CLASS	16
     81      1.1       mrg 
     82      1.1       mrg #ifdef AUDIO_DEBUG
     83  1.4.4.3   nathanw int     cs4231_debug = 0;
     84  1.4.4.3   nathanw #define DPRINTF(x)      if (cs4231_debug) printf x
     85      1.1       mrg #else
     86      1.1       mrg #define DPRINTF(x)
     87      1.1       mrg #endif
     88      1.1       mrg 
     89      1.1       mrg struct audio_device cs4231_device = {
     90      1.1       mrg 	"cs4231",
     91      1.1       mrg 	"x",
     92      1.1       mrg 	"audio"
     93      1.1       mrg };
     94      1.1       mrg 
     95      1.1       mrg 
     96  1.4.4.3   nathanw /* ad1848 sc_{read,write}reg */
     97  1.4.4.3   nathanw static int	cs4231_read(struct ad1848_softc *, int);
     98  1.4.4.3   nathanw static void	cs4231_write(struct ad1848_softc *, int, int);
     99      1.1       mrg 
    100      1.1       mrg int
    101      1.1       mrg cs4231_read(sc, index)
    102      1.1       mrg 	struct ad1848_softc	*sc;
    103      1.1       mrg 	int			index;
    104      1.1       mrg {
    105  1.4.4.3   nathanw 
    106      1.1       mrg 	return bus_space_read_1(sc->sc_iot, sc->sc_ioh, (index << 2));
    107      1.1       mrg }
    108      1.1       mrg 
    109      1.1       mrg void
    110      1.1       mrg cs4231_write(sc, index, value)
    111      1.1       mrg 	struct ad1848_softc	*sc;
    112      1.1       mrg 	int			index, value;
    113      1.1       mrg {
    114  1.4.4.3   nathanw 
    115      1.1       mrg 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, (index << 2), value);
    116      1.1       mrg }
    117      1.1       mrg 
    118      1.1       mrg 
    119      1.1       mrg void
    120  1.4.4.3   nathanw cs4231_common_attach(sc, ioh)
    121      1.3  augustss 	struct cs4231_softc *sc;
    122  1.4.4.3   nathanw 	bus_space_handle_t ioh;
    123      1.1       mrg {
    124      1.1       mrg 	char *buf;
    125      1.1       mrg 	int reg;
    126      1.1       mrg 
    127  1.4.4.3   nathanw 	sc->sc_ad1848.parent = sc;
    128  1.4.4.3   nathanw 	sc->sc_ad1848.sc_iot = sc->sc_bustag;
    129  1.4.4.3   nathanw 	sc->sc_ad1848.sc_ioh = ioh;
    130  1.4.4.3   nathanw 	sc->sc_ad1848.sc_readreg = cs4231_read;
    131  1.4.4.3   nathanw 	sc->sc_ad1848.sc_writereg = cs4231_write;
    132  1.4.4.3   nathanw 
    133  1.4.4.3   nathanw 	sc->sc_playback.t_name = "playback";
    134  1.4.4.3   nathanw 	sc->sc_capture.t_name = "capture";
    135  1.4.4.3   nathanw 
    136  1.4.4.3   nathanw 	evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR,
    137  1.4.4.3   nathanw 			     NULL,
    138  1.4.4.3   nathanw 			     sc->sc_ad1848.sc_dev.dv_xname, "total");
    139  1.4.4.3   nathanw 
    140  1.4.4.3   nathanw 	evcnt_attach_dynamic(&sc->sc_playback.t_intrcnt, EVCNT_TYPE_INTR,
    141  1.4.4.3   nathanw 			     &sc->sc_intrcnt,
    142  1.4.4.3   nathanw 			     sc->sc_ad1848.sc_dev.dv_xname, "playback");
    143  1.4.4.3   nathanw 
    144  1.4.4.3   nathanw 	evcnt_attach_dynamic(&sc->sc_playback.t_ierrcnt, EVCNT_TYPE_INTR,
    145  1.4.4.3   nathanw 			     &sc->sc_intrcnt,
    146  1.4.4.3   nathanw 			     sc->sc_ad1848.sc_dev.dv_xname, "perrors");
    147  1.4.4.3   nathanw 
    148  1.4.4.3   nathanw 	evcnt_attach_dynamic(&sc->sc_capture.t_intrcnt, EVCNT_TYPE_INTR,
    149  1.4.4.3   nathanw 			     &sc->sc_intrcnt,
    150  1.4.4.3   nathanw 			     sc->sc_ad1848.sc_dev.dv_xname, "capture");
    151  1.4.4.3   nathanw 
    152  1.4.4.3   nathanw 	evcnt_attach_dynamic(&sc->sc_capture.t_ierrcnt, EVCNT_TYPE_INTR,
    153  1.4.4.3   nathanw 			     &sc->sc_intrcnt,
    154  1.4.4.3   nathanw 			     sc->sc_ad1848.sc_dev.dv_xname, "cerrors");
    155  1.4.4.3   nathanw 
    156  1.4.4.3   nathanw 	/* put chip in native mode to access (extended) ID register */
    157      1.1       mrg 	reg = ad_read(&sc->sc_ad1848, SP_MISC_INFO);
    158      1.1       mrg 	ad_write(&sc->sc_ad1848, SP_MISC_INFO, reg | MODE2);
    159      1.1       mrg 
    160  1.4.4.3   nathanw 	/* read version numbers from I25 */
    161      1.1       mrg 	reg = ad_read(&sc->sc_ad1848, CS_VERSION_ID);
    162      1.1       mrg 	switch (reg & (CS_VERSION_NUMBER | CS_VERSION_CHIPID)) {
    163      1.1       mrg 	case 0xa0:
    164      1.1       mrg 		sc->sc_ad1848.chip_name = "CS4231A";
    165      1.1       mrg 		break;
    166      1.1       mrg 	case 0x80:
    167      1.1       mrg 		sc->sc_ad1848.chip_name = "CS4231";
    168      1.1       mrg 		break;
    169      1.1       mrg 	case 0x82:
    170      1.1       mrg 		sc->sc_ad1848.chip_name = "CS4232";
    171      1.1       mrg 		break;
    172      1.1       mrg 	default:
    173      1.1       mrg 		if ((buf = malloc(32, M_TEMP, M_NOWAIT)) != NULL) {
    174  1.4.4.3   nathanw 			sprintf(buf, "unknown rev: %x/%x", reg&0xe0, reg&7);
    175      1.1       mrg 			sc->sc_ad1848.chip_name = buf;
    176      1.1       mrg 		}
    177      1.1       mrg 	}
    178  1.4.4.3   nathanw 
    179  1.4.4.3   nathanw 	sc->sc_ad1848.mode = 2;	/* put ad1848 driver in `MODE 2' mode */
    180  1.4.4.3   nathanw 	ad1848_attach(&sc->sc_ad1848);
    181      1.1       mrg }
    182      1.1       mrg 
    183      1.1       mrg void *
    184      1.1       mrg cs4231_malloc(addr, direction, size, pool, flags)
    185      1.1       mrg 	void *addr;
    186      1.1       mrg 	int direction;
    187      1.1       mrg 	size_t size;
    188      1.1       mrg 	int pool, flags;
    189      1.1       mrg {
    190      1.1       mrg 	struct cs4231_softc *sc = addr;
    191      1.4        pk 	bus_dma_tag_t dmatag = sc->sc_dmatag;
    192      1.1       mrg 	struct cs_dma *p;
    193      1.1       mrg 
    194      1.1       mrg 	p = malloc(sizeof(*p), pool, flags);
    195      1.1       mrg 	if (p == NULL)
    196      1.1       mrg 		return (NULL);
    197      1.1       mrg 
    198      1.4        pk 	/* Allocate a DMA map */
    199      1.4        pk 	if (bus_dmamap_create(dmatag, size, 1, size, 0,
    200      1.4        pk 				BUS_DMA_NOWAIT, &p->dmamap) != 0)
    201      1.4        pk 		goto fail1;
    202      1.4        pk 
    203      1.4        pk 	/* Allocate DMA memory */
    204      1.1       mrg 	p->size = size;
    205      1.4        pk 	if (bus_dmamem_alloc(dmatag, size, 64*1024, 0,
    206      1.4        pk 				p->segs, sizeof(p->segs)/sizeof(p->segs[0]),
    207      1.4        pk 				&p->nsegs, BUS_DMA_NOWAIT) != 0)
    208      1.4        pk 		goto fail2;
    209      1.4        pk 
    210      1.4        pk 	/* Map DMA memory into kernel space */
    211      1.4        pk 	if (bus_dmamem_map(dmatag, p->segs, p->nsegs, p->size,
    212      1.4        pk 			   &p->addr, BUS_DMA_NOWAIT|BUS_DMA_COHERENT) != 0)
    213      1.4        pk 		goto fail3;
    214      1.4        pk 
    215      1.4        pk 	/* Load the buffer */
    216      1.4        pk 	if (bus_dmamap_load(dmatag, p->dmamap,
    217      1.4        pk 			    p->addr, size, NULL, BUS_DMA_NOWAIT) != 0)
    218      1.4        pk 		goto fail4;
    219      1.1       mrg 
    220      1.1       mrg 	p->next = sc->sc_dmas;
    221      1.1       mrg 	sc->sc_dmas = p;
    222      1.1       mrg 	return (p->addr);
    223      1.4        pk 
    224      1.4        pk fail4:
    225      1.4        pk 	bus_dmamem_unmap(dmatag, p->addr, p->size);
    226      1.4        pk fail3:
    227      1.4        pk 	bus_dmamem_free(dmatag, p->segs, p->nsegs);
    228      1.4        pk fail2:
    229      1.4        pk 	bus_dmamap_destroy(dmatag, p->dmamap);
    230      1.4        pk fail1:
    231      1.4        pk 	free(p, pool);
    232      1.4        pk 	return (NULL);
    233      1.1       mrg }
    234      1.1       mrg 
    235      1.1       mrg void
    236      1.1       mrg cs4231_free(addr, ptr, pool)
    237      1.1       mrg 	void *addr;
    238      1.1       mrg 	void *ptr;
    239      1.1       mrg 	int pool;
    240      1.1       mrg {
    241      1.1       mrg 	struct cs4231_softc *sc = addr;
    242      1.4        pk 	bus_dma_tag_t dmatag = sc->sc_dmatag;
    243      1.1       mrg 	struct cs_dma *p, **pp;
    244      1.1       mrg 
    245      1.1       mrg 	for (pp = &sc->sc_dmas; (p = *pp) != NULL; pp = &(*pp)->next) {
    246      1.1       mrg 		if (p->addr != ptr)
    247      1.1       mrg 			continue;
    248      1.4        pk 		bus_dmamap_unload(dmatag, p->dmamap);
    249      1.4        pk 		bus_dmamem_unmap(dmatag, p->addr, p->size);
    250      1.4        pk 		bus_dmamem_free(dmatag, p->segs, p->nsegs);
    251      1.4        pk 		bus_dmamap_destroy(dmatag, p->dmamap);
    252      1.1       mrg 		*pp = p->next;
    253      1.1       mrg 		free(p, pool);
    254      1.1       mrg 		return;
    255      1.1       mrg 	}
    256      1.1       mrg 	printf("cs4231_free: rogue pointer\n");
    257      1.1       mrg }
    258      1.1       mrg 
    259  1.4.4.3   nathanw 
    260  1.4.4.3   nathanw /*
    261  1.4.4.3   nathanw  * Set up transfer and return DMA address and byte count in paddr and psize
    262  1.4.4.3   nathanw  * for bus dependent trigger_{in,out}put to load into the dma controller.
    263  1.4.4.3   nathanw  */
    264  1.4.4.3   nathanw int
    265  1.4.4.3   nathanw cs4231_transfer_init(sc, t, paddr, psize, start, end, blksize, intr, arg)
    266  1.4.4.3   nathanw 	struct cs4231_softc *sc;
    267  1.4.4.3   nathanw 	struct cs_transfer *t;
    268  1.4.4.3   nathanw 	bus_addr_t *paddr;
    269  1.4.4.3   nathanw 	bus_size_t *psize;
    270  1.4.4.3   nathanw 	void *start, *end;
    271  1.4.4.3   nathanw 	int blksize;
    272  1.4.4.3   nathanw 	void (*intr)(void *);
    273  1.4.4.3   nathanw 	void *arg;
    274  1.4.4.3   nathanw {
    275  1.4.4.3   nathanw 	struct cs_dma *p;
    276  1.4.4.3   nathanw 	vsize_t n;
    277  1.4.4.3   nathanw 
    278  1.4.4.3   nathanw 	if (t->t_active) {
    279  1.4.4.3   nathanw 		printf("%s: %s already running\n",
    280  1.4.4.3   nathanw 		       sc->sc_ad1848.sc_dev.dv_xname, t->t_name);
    281  1.4.4.3   nathanw 		return (EINVAL);
    282  1.4.4.3   nathanw 	}
    283  1.4.4.3   nathanw 
    284  1.4.4.3   nathanw 	t->t_intr = intr;
    285  1.4.4.3   nathanw 	t->t_arg = arg;
    286  1.4.4.3   nathanw 
    287  1.4.4.3   nathanw 	for (p = sc->sc_dmas; p != NULL && p->addr != start; p = p->next)
    288  1.4.4.3   nathanw 		continue;
    289  1.4.4.3   nathanw 	if (p == NULL) {
    290  1.4.4.3   nathanw 		printf("%s: bad %s addr %p\n",
    291  1.4.4.3   nathanw 		       sc->sc_ad1848.sc_dev.dv_xname, t->t_name, start);
    292  1.4.4.3   nathanw 		return (EINVAL);
    293  1.4.4.3   nathanw 	}
    294  1.4.4.3   nathanw 
    295  1.4.4.3   nathanw 	n = (char *)end - (char *)start;
    296  1.4.4.3   nathanw 
    297  1.4.4.3   nathanw 	t->t_dma = p;		/* the DMA memory segment */
    298  1.4.4.3   nathanw 	t->t_segsz = n;		/* size of DMA segment */
    299  1.4.4.3   nathanw 	t->t_blksz = blksize;	/* do transfers in blksize chunks */
    300  1.4.4.3   nathanw 
    301  1.4.4.3   nathanw 	if (n > t->t_blksz)
    302  1.4.4.3   nathanw 		n = t->t_blksz;
    303  1.4.4.3   nathanw 
    304  1.4.4.3   nathanw 	t->t_cnt = n;
    305  1.4.4.3   nathanw 
    306  1.4.4.3   nathanw 	/* for caller to load into dma controller */
    307  1.4.4.3   nathanw 	*paddr = t->t_dma->dmamap->dm_segs[0].ds_addr;
    308  1.4.4.3   nathanw 	*psize = n;
    309  1.4.4.3   nathanw 
    310  1.4.4.3   nathanw 	DPRINTF(("%s: init %s: [%p..%p] %lu bytes %lu blocks;"
    311  1.4.4.3   nathanw 		 " dma at 0x%lx count %lu\n",
    312  1.4.4.3   nathanw 		 sc->sc_ad1848.sc_dev.dv_xname, t->t_name,
    313  1.4.4.3   nathanw 		 start, end, (u_long)t->t_segsz, (u_long)t->t_blksz,
    314  1.4.4.3   nathanw 		 (u_long)*paddr, (u_long)*psize));
    315  1.4.4.3   nathanw 
    316  1.4.4.3   nathanw 	t->t_active = 1;
    317  1.4.4.3   nathanw 	return (0);
    318  1.4.4.3   nathanw }
    319  1.4.4.3   nathanw 
    320  1.4.4.3   nathanw /*
    321  1.4.4.3   nathanw  * Compute next DMA address/counter, update transfer status.
    322  1.4.4.3   nathanw  */
    323  1.4.4.3   nathanw void
    324  1.4.4.3   nathanw cs4231_transfer_advance(t, paddr, psize)
    325  1.4.4.3   nathanw 	struct cs_transfer *t;
    326  1.4.4.3   nathanw 	bus_addr_t *paddr;
    327  1.4.4.3   nathanw 	bus_size_t *psize;
    328  1.4.4.3   nathanw {
    329  1.4.4.3   nathanw 	bus_addr_t dmabase, nextaddr;
    330  1.4.4.3   nathanw 	bus_size_t togo;
    331  1.4.4.3   nathanw 
    332  1.4.4.3   nathanw 	dmabase = t->t_dma->dmamap->dm_segs[0].ds_addr;
    333  1.4.4.3   nathanw 
    334  1.4.4.3   nathanw 	togo = t->t_segsz - t->t_cnt;
    335  1.4.4.3   nathanw 	if (togo == 0) {	/* roll over */
    336  1.4.4.3   nathanw 		nextaddr = dmabase;
    337  1.4.4.3   nathanw 		t->t_cnt = togo = t->t_blksz;
    338  1.4.4.3   nathanw 	} else {
    339  1.4.4.3   nathanw 		nextaddr = dmabase + t->t_cnt;
    340  1.4.4.3   nathanw 		if (togo > t->t_blksz)
    341  1.4.4.3   nathanw 			togo = t->t_blksz;
    342  1.4.4.3   nathanw 		t->t_cnt += togo;
    343  1.4.4.3   nathanw 	}
    344  1.4.4.3   nathanw 
    345  1.4.4.3   nathanw 	/* for caller to load into dma controller */
    346  1.4.4.3   nathanw 	*paddr = nextaddr;
    347  1.4.4.3   nathanw 	*psize = togo;
    348  1.4.4.3   nathanw }
    349  1.4.4.3   nathanw 
    350  1.4.4.3   nathanw 
    351      1.1       mrg int
    352      1.1       mrg cs4231_open(addr, flags)
    353      1.1       mrg 	void *addr;
    354      1.1       mrg 	int flags;
    355      1.1       mrg {
    356      1.1       mrg 	struct cs4231_softc *sc = addr;
    357      1.1       mrg 
    358      1.1       mrg 	DPRINTF(("sa_open: unit %p\n", sc));
    359      1.1       mrg 
    360      1.1       mrg 	if (sc->sc_open)
    361      1.1       mrg 		return (EBUSY);
    362  1.4.4.3   nathanw 
    363      1.1       mrg 	sc->sc_open = 1;
    364  1.4.4.3   nathanw 
    365  1.4.4.3   nathanw 	sc->sc_playback.t_active = 0;
    366  1.4.4.3   nathanw 	sc->sc_playback.t_intr = NULL;
    367  1.4.4.3   nathanw 	sc->sc_playback.t_arg = NULL;
    368  1.4.4.3   nathanw 
    369  1.4.4.3   nathanw 	sc->sc_capture.t_active = 0;
    370  1.4.4.3   nathanw 	sc->sc_capture.t_intr = NULL;
    371  1.4.4.3   nathanw 	sc->sc_capture.t_arg = NULL;
    372  1.4.4.3   nathanw 
    373  1.4.4.3   nathanw 	/* no interrupts from ad1848 */
    374      1.1       mrg 	ad_write(&sc->sc_ad1848, SP_PIN_CONTROL, 0);
    375      1.1       mrg 	ad1848_reset(&sc->sc_ad1848);
    376      1.1       mrg 
    377  1.4.4.3   nathanw 	DPRINTF(("sa_open: ok -> sc=%p\n", sc));
    378      1.1       mrg 	return (0);
    379      1.1       mrg }
    380      1.1       mrg 
    381      1.1       mrg void
    382      1.1       mrg cs4231_close(addr)
    383      1.1       mrg 	void *addr;
    384      1.1       mrg {
    385      1.3  augustss 	struct cs4231_softc *sc = addr;
    386      1.1       mrg 
    387      1.1       mrg 	DPRINTF(("sa_close: sc=%p\n", sc));
    388  1.4.4.3   nathanw 
    389  1.4.4.3   nathanw 	/* audio(9) already called halt methods */
    390      1.1       mrg 	sc->sc_open = 0;
    391      1.1       mrg 
    392      1.1       mrg 	DPRINTF(("sa_close: closed.\n"));
    393      1.1       mrg }
    394      1.1       mrg 
    395      1.1       mrg size_t
    396      1.1       mrg cs4231_round_buffersize(addr, direction, size)
    397      1.1       mrg 	void *addr;
    398      1.1       mrg 	int direction;
    399      1.1       mrg 	size_t size;
    400      1.1       mrg {
    401  1.4.4.3   nathanw 
    402      1.1       mrg 	return (size);
    403      1.1       mrg }
    404      1.1       mrg 
    405      1.1       mrg int
    406      1.1       mrg cs4231_round_blocksize(addr, blk)
    407      1.1       mrg 	void *addr;
    408      1.1       mrg 	int blk;
    409      1.1       mrg {
    410  1.4.4.3   nathanw 
    411  1.4.4.3   nathanw 	return (blk & ~3);
    412      1.1       mrg }
    413      1.1       mrg 
    414      1.1       mrg int
    415      1.1       mrg cs4231_getdev(addr, retp)
    416      1.1       mrg         void *addr;
    417      1.1       mrg         struct audio_device *retp;
    418      1.1       mrg {
    419  1.4.4.3   nathanw 
    420      1.1       mrg         *retp = cs4231_device;
    421      1.1       mrg         return (0);
    422      1.1       mrg }
    423      1.1       mrg 
    424      1.1       mrg static ad1848_devmap_t csmapping[] = {
    425      1.1       mrg 	{ CSAUDIO_DAC_LVL, AD1848_KIND_LVL, AD1848_AUX1_CHANNEL },
    426      1.1       mrg 	{ CSAUDIO_LINE_IN_LVL, AD1848_KIND_LVL, AD1848_LINE_CHANNEL },
    427      1.1       mrg 	{ CSAUDIO_MONO_LVL, AD1848_KIND_LVL, AD1848_MONO_CHANNEL },
    428      1.1       mrg 	{ CSAUDIO_CD_LVL, AD1848_KIND_LVL, AD1848_AUX2_CHANNEL },
    429  1.4.4.4   nathanw 	{ CSAUDIO_OUTPUT_LVL, AD1848_KIND_LVL, AD1848_MONITOR_CHANNEL },
    430      1.1       mrg 	{ CSAUDIO_OUT_LVL, AD1848_KIND_LVL, AD1848_DAC_CHANNEL },
    431      1.1       mrg 	{ CSAUDIO_DAC_MUTE, AD1848_KIND_MUTE, AD1848_AUX1_CHANNEL },
    432      1.1       mrg 	{ CSAUDIO_LINE_IN_MUTE, AD1848_KIND_MUTE, AD1848_LINE_CHANNEL },
    433      1.1       mrg 	{ CSAUDIO_MONO_MUTE, AD1848_KIND_MUTE, AD1848_MONO_CHANNEL },
    434      1.1       mrg 	{ CSAUDIO_CD_MUTE, AD1848_KIND_MUTE, AD1848_AUX2_CHANNEL },
    435  1.4.4.4   nathanw 	{ CSAUDIO_OUTPUT_MUTE, AD1848_KIND_MUTE, AD1848_MONITOR_CHANNEL },
    436  1.4.4.4   nathanw 	{ CSAUDIO_OUT_MUTE, AD1848_KIND_MUTE, AD1848_OUT_CHANNEL },
    437      1.1       mrg 	{ CSAUDIO_REC_LVL, AD1848_KIND_RECORDGAIN, -1 },
    438      1.1       mrg 	{ CSAUDIO_RECORD_SOURCE, AD1848_KIND_RECORDSOURCE, -1 }
    439      1.1       mrg };
    440      1.1       mrg 
    441      1.1       mrg static int nummap = sizeof(csmapping) / sizeof(csmapping[0]);
    442      1.1       mrg 
    443      1.1       mrg 
    444      1.1       mrg int
    445      1.1       mrg cs4231_set_port(addr, cp)
    446      1.1       mrg 	void *addr;
    447      1.1       mrg 	mixer_ctrl_t *cp;
    448      1.1       mrg {
    449      1.1       mrg 	struct ad1848_softc *ac = addr;
    450      1.1       mrg 
    451      1.1       mrg 	DPRINTF(("cs4231_set_port: port=%d", cp->dev));
    452      1.1       mrg 	return (ad1848_mixer_set_port(ac, csmapping, nummap, cp));
    453      1.1       mrg }
    454      1.1       mrg 
    455      1.1       mrg int
    456      1.1       mrg cs4231_get_port(addr, cp)
    457      1.1       mrg 	void *addr;
    458      1.1       mrg 	mixer_ctrl_t *cp;
    459      1.1       mrg {
    460      1.1       mrg 	struct ad1848_softc *ac = addr;
    461      1.1       mrg 
    462      1.1       mrg 	DPRINTF(("cs4231_get_port: port=%d", cp->dev));
    463      1.1       mrg 	return (ad1848_mixer_get_port(ac, csmapping, nummap, cp));
    464      1.1       mrg }
    465      1.1       mrg 
    466      1.1       mrg int
    467      1.1       mrg cs4231_get_props(addr)
    468      1.1       mrg 	void *addr;
    469      1.1       mrg {
    470  1.4.4.3   nathanw 
    471      1.1       mrg 	return (AUDIO_PROP_FULLDUPLEX);
    472      1.1       mrg }
    473      1.1       mrg 
    474      1.1       mrg int
    475      1.1       mrg cs4231_query_devinfo(addr, dip)
    476      1.1       mrg 	void *addr;
    477      1.3  augustss 	mixer_devinfo_t *dip;
    478      1.1       mrg {
    479      1.1       mrg 
    480      1.1       mrg 	switch(dip->index) {
    481      1.1       mrg 
    482      1.1       mrg 	case CSAUDIO_DAC_LVL:		/*  dacout */
    483      1.1       mrg 		dip->type = AUDIO_MIXER_VALUE;
    484      1.1       mrg 		dip->mixer_class = CSAUDIO_INPUT_CLASS;
    485      1.1       mrg 		dip->prev = AUDIO_MIXER_LAST;
    486      1.1       mrg 		dip->next = CSAUDIO_DAC_MUTE;
    487      1.1       mrg 		strcpy(dip->label.name, AudioNdac);
    488      1.1       mrg 		dip->un.v.num_channels = 2;
    489      1.1       mrg 		strcpy(dip->un.v.units.name, AudioNvolume);
    490      1.1       mrg 		break;
    491      1.1       mrg 
    492      1.1       mrg 	case CSAUDIO_LINE_IN_LVL:	/* line */
    493      1.1       mrg 		dip->type = AUDIO_MIXER_VALUE;
    494      1.1       mrg 		dip->mixer_class = CSAUDIO_INPUT_CLASS;
    495      1.1       mrg 		dip->prev = AUDIO_MIXER_LAST;
    496      1.1       mrg 		dip->next = CSAUDIO_LINE_IN_MUTE;
    497      1.1       mrg 		strcpy(dip->label.name, AudioNline);
    498      1.1       mrg 		dip->un.v.num_channels = 2;
    499      1.1       mrg 		strcpy(dip->un.v.units.name, AudioNvolume);
    500      1.1       mrg 		break;
    501      1.1       mrg 
    502  1.4.4.3   nathanw 	case CSAUDIO_MONO_LVL:	/* mono/microphone mixer */
    503  1.4.4.3   nathanw 		dip->type = AUDIO_MIXER_VALUE;
    504  1.4.4.3   nathanw 		dip->mixer_class = CSAUDIO_INPUT_CLASS;
    505  1.4.4.3   nathanw 		dip->prev = AUDIO_MIXER_LAST;
    506  1.4.4.3   nathanw 		dip->next = CSAUDIO_MONO_MUTE;
    507  1.4.4.3   nathanw 		strcpy(dip->label.name, AudioNmicrophone);
    508  1.4.4.3   nathanw 		dip->un.v.num_channels = 1;
    509  1.4.4.3   nathanw 		strcpy(dip->un.v.units.name, AudioNvolume);
    510  1.4.4.3   nathanw 		break;
    511  1.4.4.3   nathanw 
    512      1.1       mrg 	case CSAUDIO_CD_LVL:		/* cd */
    513      1.1       mrg 		dip->type = AUDIO_MIXER_VALUE;
    514      1.1       mrg 		dip->mixer_class = CSAUDIO_INPUT_CLASS;
    515      1.1       mrg 		dip->prev = AUDIO_MIXER_LAST;
    516      1.1       mrg 		dip->next = CSAUDIO_CD_MUTE;
    517      1.1       mrg 		strcpy(dip->label.name, AudioNcd);
    518      1.1       mrg 		dip->un.v.num_channels = 2;
    519      1.1       mrg 		strcpy(dip->un.v.units.name, AudioNvolume);
    520      1.1       mrg 		break;
    521      1.1       mrg 
    522      1.1       mrg 
    523  1.4.4.4   nathanw 	case CSAUDIO_OUTPUT_LVL:	/* monitor level */
    524      1.1       mrg 		dip->type = AUDIO_MIXER_VALUE;
    525      1.1       mrg 		dip->mixer_class = CSAUDIO_MONITOR_CLASS;
    526  1.4.4.4   nathanw 		dip->next = CSAUDIO_OUTPUT_MUTE;
    527      1.1       mrg 		dip->prev = AUDIO_MIXER_LAST;
    528      1.1       mrg 		strcpy(dip->label.name, AudioNmonitor);
    529      1.1       mrg 		dip->un.v.num_channels = 1;
    530      1.1       mrg 		strcpy(dip->un.v.units.name, AudioNvolume);
    531      1.1       mrg 		break;
    532      1.1       mrg 
    533  1.4.4.4   nathanw 	case CSAUDIO_OUT_LVL:		/* cs4231 output volume */
    534      1.1       mrg 		dip->type = AUDIO_MIXER_VALUE;
    535      1.1       mrg 		dip->mixer_class = CSAUDIO_MONITOR_CLASS;
    536  1.4.4.4   nathanw 		dip->next = dip->prev = AUDIO_MIXER_LAST;
    537  1.4.4.4   nathanw 		strcpy(dip->label.name, AudioNmaster);
    538      1.1       mrg 		dip->un.v.num_channels = 2;
    539      1.1       mrg 		strcpy(dip->un.v.units.name, AudioNvolume);
    540      1.1       mrg 		break;
    541      1.1       mrg 
    542  1.4.4.4   nathanw 	case CSAUDIO_OUT_MUTE: /* mute built-in speaker */
    543  1.4.4.4   nathanw 		dip->mixer_class = CSAUDIO_MONITOR_CLASS;
    544  1.4.4.4   nathanw 		dip->type = AUDIO_MIXER_ENUM;
    545  1.4.4.4   nathanw 		dip->prev = CSAUDIO_MONITOR_CLASS;
    546  1.4.4.4   nathanw 		dip->next = AUDIO_MIXER_LAST;
    547  1.4.4.4   nathanw 		strcpy(dip->label.name, AudioNmono);
    548  1.4.4.4   nathanw 		/* names reversed, this is a "mute" value used as "mono enabled" */
    549  1.4.4.4   nathanw 		dip->un.e.num_mem = 2;
    550  1.4.4.4   nathanw 		strcpy(dip->un.e.member[0].label.name, AudioNon);
    551  1.4.4.4   nathanw 		dip->un.e.member[0].ord = 0;
    552  1.4.4.4   nathanw 		strcpy(dip->un.e.member[1].label.name, AudioNoff);
    553  1.4.4.4   nathanw 		dip->un.e.member[1].ord = 1;
    554  1.4.4.4   nathanw 		break;
    555  1.4.4.4   nathanw 
    556      1.1       mrg 	case CSAUDIO_LINE_IN_MUTE:
    557      1.1       mrg 		dip->mixer_class = CSAUDIO_INPUT_CLASS;
    558      1.1       mrg 		dip->type = AUDIO_MIXER_ENUM;
    559      1.1       mrg 		dip->prev = CSAUDIO_LINE_IN_LVL;
    560      1.1       mrg 		dip->next = AUDIO_MIXER_LAST;
    561      1.1       mrg 		goto mute;
    562      1.1       mrg 
    563      1.1       mrg 	case CSAUDIO_DAC_MUTE:
    564      1.1       mrg 		dip->mixer_class = CSAUDIO_INPUT_CLASS;
    565      1.1       mrg 		dip->type = AUDIO_MIXER_ENUM;
    566      1.1       mrg 		dip->prev = CSAUDIO_DAC_LVL;
    567      1.1       mrg 		dip->next = AUDIO_MIXER_LAST;
    568      1.1       mrg 		goto mute;
    569      1.1       mrg 
    570      1.1       mrg 	case CSAUDIO_CD_MUTE:
    571      1.1       mrg 		dip->mixer_class = CSAUDIO_INPUT_CLASS;
    572      1.1       mrg 		dip->type = AUDIO_MIXER_ENUM;
    573      1.1       mrg 		dip->prev = CSAUDIO_CD_LVL;
    574      1.1       mrg 		dip->next = AUDIO_MIXER_LAST;
    575      1.1       mrg 		goto mute;
    576      1.1       mrg 
    577      1.1       mrg 	case CSAUDIO_MONO_MUTE:
    578      1.1       mrg 		dip->mixer_class = CSAUDIO_INPUT_CLASS;
    579      1.1       mrg 		dip->type = AUDIO_MIXER_ENUM;
    580      1.1       mrg 		dip->prev = CSAUDIO_MONO_LVL;
    581      1.1       mrg 		dip->next = AUDIO_MIXER_LAST;
    582      1.1       mrg 		goto mute;
    583      1.1       mrg 
    584  1.4.4.4   nathanw 	case CSAUDIO_OUTPUT_MUTE:
    585  1.4.4.3   nathanw 		dip->mixer_class = CSAUDIO_MONITOR_CLASS;
    586      1.1       mrg 		dip->type = AUDIO_MIXER_ENUM;
    587  1.4.4.4   nathanw 		dip->prev = CSAUDIO_OUTPUT_LVL;
    588      1.1       mrg 		dip->next = AUDIO_MIXER_LAST;
    589      1.1       mrg 	mute:
    590      1.1       mrg 		strcpy(dip->label.name, AudioNmute);
    591      1.1       mrg 		dip->un.e.num_mem = 2;
    592      1.1       mrg 		strcpy(dip->un.e.member[0].label.name, AudioNoff);
    593      1.1       mrg 		dip->un.e.member[0].ord = 0;
    594      1.1       mrg 		strcpy(dip->un.e.member[1].label.name, AudioNon);
    595      1.1       mrg 		dip->un.e.member[1].ord = 1;
    596      1.1       mrg 		break;
    597      1.1       mrg 
    598      1.1       mrg 	case CSAUDIO_REC_LVL:	/* record level */
    599      1.1       mrg 		dip->type = AUDIO_MIXER_VALUE;
    600      1.1       mrg 		dip->mixer_class = CSAUDIO_RECORD_CLASS;
    601      1.1       mrg 		dip->prev = AUDIO_MIXER_LAST;
    602      1.1       mrg 		dip->next = CSAUDIO_RECORD_SOURCE;
    603      1.1       mrg 		strcpy(dip->label.name, AudioNrecord);
    604      1.1       mrg 		dip->un.v.num_channels = 2;
    605      1.1       mrg 		strcpy(dip->un.v.units.name, AudioNvolume);
    606      1.1       mrg 		break;
    607      1.1       mrg 
    608      1.1       mrg 	case CSAUDIO_RECORD_SOURCE:
    609      1.1       mrg 		dip->mixer_class = CSAUDIO_RECORD_CLASS;
    610      1.1       mrg 		dip->type = AUDIO_MIXER_ENUM;
    611      1.1       mrg 		dip->prev = CSAUDIO_REC_LVL;
    612      1.1       mrg 		dip->next = AUDIO_MIXER_LAST;
    613      1.1       mrg 		strcpy(dip->label.name, AudioNsource);
    614      1.1       mrg 		dip->un.e.num_mem = 4;
    615      1.1       mrg 		strcpy(dip->un.e.member[0].label.name, AudioNoutput);
    616      1.1       mrg 		dip->un.e.member[0].ord = DAC_IN_PORT;
    617      1.1       mrg 		strcpy(dip->un.e.member[1].label.name, AudioNmicrophone);
    618      1.1       mrg 		dip->un.e.member[1].ord = MIC_IN_PORT;
    619      1.1       mrg 		strcpy(dip->un.e.member[2].label.name, AudioNdac);
    620      1.1       mrg 		dip->un.e.member[2].ord = AUX1_IN_PORT;
    621      1.1       mrg 		strcpy(dip->un.e.member[3].label.name, AudioNline);
    622      1.1       mrg 		dip->un.e.member[3].ord = LINE_IN_PORT;
    623      1.1       mrg 		break;
    624      1.1       mrg 
    625      1.1       mrg 	case CSAUDIO_INPUT_CLASS:		/* input class descriptor */
    626      1.1       mrg 		dip->type = AUDIO_MIXER_CLASS;
    627      1.1       mrg 		dip->mixer_class = CSAUDIO_INPUT_CLASS;
    628      1.1       mrg 		dip->next = dip->prev = AUDIO_MIXER_LAST;
    629      1.1       mrg 		strcpy(dip->label.name, AudioCinputs);
    630      1.1       mrg 		break;
    631      1.1       mrg 
    632  1.4.4.4   nathanw 	case CSAUDIO_MONITOR_CLASS:		/* output class descriptor */
    633      1.1       mrg 		dip->type = AUDIO_MIXER_CLASS;
    634      1.1       mrg 		dip->mixer_class = CSAUDIO_MONITOR_CLASS;
    635      1.1       mrg 		dip->next = dip->prev = AUDIO_MIXER_LAST;
    636      1.1       mrg 		strcpy(dip->label.name, AudioCmonitor);
    637      1.1       mrg 		break;
    638  1.4.4.4   nathanw 
    639      1.1       mrg 	case CSAUDIO_RECORD_CLASS:		/* record source class */
    640      1.1       mrg 		dip->type = AUDIO_MIXER_CLASS;
    641      1.1       mrg 		dip->mixer_class = CSAUDIO_RECORD_CLASS;
    642      1.1       mrg 		dip->next = dip->prev = AUDIO_MIXER_LAST;
    643      1.1       mrg 		strcpy(dip->label.name, AudioCrecord);
    644      1.1       mrg 		break;
    645      1.1       mrg 
    646      1.1       mrg 	default:
    647      1.1       mrg 		return ENXIO;
    648      1.1       mrg 		/*NOTREACHED*/
    649      1.1       mrg 	}
    650      1.1       mrg 	DPRINTF(("AUDIO_MIXER_DEVINFO: name=%s\n", dip->label.name));
    651      1.1       mrg 
    652      1.1       mrg 	return (0);
    653      1.1       mrg }
    654      1.1       mrg 
    655      1.1       mrg #endif /* NAUDIO > 0 */
    656