Home | History | Annotate | Line # | Download | only in dev
audioamd.c revision 1.7.4.5
      1  1.7.4.5  thorpej /*	$NetBSD: audioamd.c,v 1.7.4.5 2002/12/11 06:12:01 thorpej Exp $	*/
      2  1.7.4.2  nathanw /*	NetBSD: am7930_sparc.c,v 1.44 1999/03/14 22:29:00 jonathan Exp 	*/
      3  1.7.4.2  nathanw 
      4  1.7.4.2  nathanw /*
      5  1.7.4.2  nathanw  * Copyright (c) 1995 Rolf Grossmann
      6  1.7.4.2  nathanw  * All rights reserved.
      7  1.7.4.2  nathanw  *
      8  1.7.4.2  nathanw  * Redistribution and use in source and binary forms, with or without
      9  1.7.4.2  nathanw  * modification, are permitted provided that the following conditions
     10  1.7.4.2  nathanw  * are met:
     11  1.7.4.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     12  1.7.4.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     13  1.7.4.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.7.4.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     15  1.7.4.2  nathanw  *    documentation and/or other materials provided with the distribution.
     16  1.7.4.2  nathanw  * 3. All advertising materials mentioning features or use of this software
     17  1.7.4.2  nathanw  *    must display the following acknowledgement:
     18  1.7.4.2  nathanw  *      This product includes software developed by Rolf Grossmann.
     19  1.7.4.2  nathanw  * 4. The name of the author may not be used to endorse or promote products
     20  1.7.4.2  nathanw  *    derived from this software without specific prior written permission
     21  1.7.4.2  nathanw  *
     22  1.7.4.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  1.7.4.2  nathanw  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  1.7.4.2  nathanw  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  1.7.4.2  nathanw  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  1.7.4.2  nathanw  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  1.7.4.2  nathanw  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  1.7.4.2  nathanw  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  1.7.4.2  nathanw  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  1.7.4.2  nathanw  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  1.7.4.2  nathanw  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  1.7.4.2  nathanw  */
     33  1.7.4.2  nathanw 
     34  1.7.4.2  nathanw #include "audio.h"
     35  1.7.4.2  nathanw #if NAUDIO > 0
     36  1.7.4.2  nathanw 
     37  1.7.4.2  nathanw #include <sys/param.h>
     38  1.7.4.2  nathanw #include <sys/systm.h>
     39  1.7.4.2  nathanw #include <sys/errno.h>
     40  1.7.4.2  nathanw #include <sys/device.h>
     41  1.7.4.2  nathanw 
     42  1.7.4.2  nathanw #include <machine/bus.h>
     43  1.7.4.2  nathanw #include <machine/intr.h>
     44  1.7.4.2  nathanw #include <machine/autoconf.h>
     45  1.7.4.2  nathanw 
     46  1.7.4.2  nathanw #include <sys/audioio.h>
     47  1.7.4.2  nathanw #include <dev/audio_if.h>
     48  1.7.4.2  nathanw 
     49  1.7.4.2  nathanw #include <dev/ic/am7930reg.h>
     50  1.7.4.2  nathanw #include <dev/ic/am7930var.h>
     51  1.7.4.2  nathanw #include <sparc/dev/audioamdvar.h>
     52  1.7.4.2  nathanw 
     53  1.7.4.2  nathanw #define AUDIO_ROM_NAME "audio"
     54  1.7.4.2  nathanw 
     55  1.7.4.2  nathanw #ifdef AUDIO_DEBUG
     56  1.7.4.2  nathanw #define DPRINTF(x)      if (am7930debug) printf x
     57  1.7.4.2  nathanw #define DPRINTFN(n,x)   if (am7930debug>(n)) printf x
     58  1.7.4.2  nathanw #else
     59  1.7.4.2  nathanw #define DPRINTF(x)
     60  1.7.4.2  nathanw #define DPRINTFN(n,x)
     61  1.7.4.2  nathanw #endif	/* AUDIO_DEBUG */
     62  1.7.4.2  nathanw 
     63  1.7.4.2  nathanw 
     64  1.7.4.2  nathanw /* interrupt interfaces */
     65  1.7.4.2  nathanw int	am7930hwintr __P((void *));
     66  1.7.4.2  nathanw struct auio *auiop;
     67  1.7.4.5  thorpej void	am7930swintr __P((void *));
     68  1.7.4.5  thorpej 
     69  1.7.4.5  thorpej /* from amd7930intr.s: */
     70  1.7.4.5  thorpej void	amd7930_trap(void);
     71  1.7.4.2  nathanw 
     72  1.7.4.2  nathanw /*
     73  1.7.4.2  nathanw  * interrupt-handler status
     74  1.7.4.2  nathanw  */
     75  1.7.4.2  nathanw struct am7930_intrhand {
     76  1.7.4.2  nathanw 	int	(*ih_fun) __P((void *));
     77  1.7.4.2  nathanw 	void	*ih_arg;
     78  1.7.4.2  nathanw };
     79  1.7.4.2  nathanw 
     80  1.7.4.2  nathanw struct audioamd_softc {
     81  1.7.4.2  nathanw 	struct am7930_softc sc_am7930;	/* glue to MI code */
     82  1.7.4.2  nathanw 
     83  1.7.4.2  nathanw 	bus_space_tag_t sc_bt;		/* bus cookie */
     84  1.7.4.2  nathanw 	bus_space_handle_t sc_bh;	/* device registers */
     85  1.7.4.2  nathanw 
     86  1.7.4.2  nathanw 	struct am7930_intrhand	sc_ih;	/* interrupt vector (hw or sw)  */
     87  1.7.4.2  nathanw 	void	(*sc_rintr)(void*);	/* input completion intr handler */
     88  1.7.4.2  nathanw 	void	*sc_rarg;		/* arg for sc_rintr() */
     89  1.7.4.2  nathanw 	void	(*sc_pintr)(void*);	/* output completion intr handler */
     90  1.7.4.2  nathanw 	void	*sc_parg;		/* arg for sc_pintr() */
     91  1.7.4.2  nathanw 
     92  1.7.4.2  nathanw 	/* sc_au is special in that the hardware interrupt handler uses it */
     93  1.7.4.2  nathanw 	struct  auio sc_au;		/* recv and xmit buffers, etc */
     94  1.7.4.2  nathanw #define sc_intrcnt	sc_au.au_intrcnt	/* statistics */
     95  1.7.4.5  thorpej 	void	*sc_sicookie;		/* softintr(9) cookie */
     96  1.7.4.2  nathanw };
     97  1.7.4.2  nathanw 
     98  1.7.4.2  nathanw void	audioamd_mainbus_attach __P((struct device *,
     99  1.7.4.2  nathanw 		struct device *, void *));
    100  1.7.4.2  nathanw int	audioamd_mainbus_match __P((struct device *, struct cfdata *, void *));
    101  1.7.4.4  nathanw void	audioamd_obio_attach __P((struct device *, struct device *, void *));
    102  1.7.4.4  nathanw int	audioamd_obio_match __P((struct device *, struct cfdata *, void *));
    103  1.7.4.2  nathanw void	audioamd_sbus_attach __P((struct device *, struct device *, void *));
    104  1.7.4.2  nathanw int	audioamd_sbus_match __P((struct device *, struct cfdata *, void *));
    105  1.7.4.2  nathanw void	audioamd_attach(struct audioamd_softc *sc, int);
    106  1.7.4.2  nathanw 
    107  1.7.4.4  nathanw CFATTACH_DECL(audioamd_mainbus, sizeof(struct audioamd_softc),
    108  1.7.4.4  nathanw     audioamd_mainbus_match, audioamd_mainbus_attach, NULL, NULL);
    109  1.7.4.2  nathanw 
    110  1.7.4.4  nathanw CFATTACH_DECL(audioamd_obio, sizeof(struct audioamd_softc),
    111  1.7.4.4  nathanw     audioamd_obio_match, audioamd_obio_attach, NULL, NULL);
    112  1.7.4.4  nathanw 
    113  1.7.4.4  nathanw CFATTACH_DECL(audioamd_sbus, sizeof(struct audioamd_softc),
    114  1.7.4.4  nathanw     audioamd_sbus_match, audioamd_sbus_attach, NULL, NULL);
    115  1.7.4.2  nathanw 
    116  1.7.4.2  nathanw /*
    117  1.7.4.2  nathanw  * Define our interface into the am7930 MI driver.
    118  1.7.4.2  nathanw  */
    119  1.7.4.2  nathanw 
    120  1.7.4.2  nathanw u_int8_t	audioamd_codec_iread __P((struct am7930_softc *, int));
    121  1.7.4.2  nathanw u_int16_t	audioamd_codec_iread16 __P((struct am7930_softc *, int));
    122  1.7.4.2  nathanw u_int8_t	audioamd_codec_dread __P((struct audioamd_softc *, int));
    123  1.7.4.2  nathanw void	audioamd_codec_iwrite __P((struct am7930_softc *, int, u_int8_t));
    124  1.7.4.2  nathanw void	audioamd_codec_iwrite16 __P((struct am7930_softc *, int, u_int16_t));
    125  1.7.4.2  nathanw void	audioamd_codec_dwrite __P((struct audioamd_softc *, int, u_int8_t));
    126  1.7.4.2  nathanw void	audioamd_onopen __P((struct am7930_softc *sc));
    127  1.7.4.2  nathanw void	audioamd_onclose __P((struct am7930_softc *sc));
    128  1.7.4.2  nathanw 
    129  1.7.4.2  nathanw struct am7930_glue audioamd_glue = {
    130  1.7.4.2  nathanw 	audioamd_codec_iread,
    131  1.7.4.2  nathanw 	audioamd_codec_iwrite,
    132  1.7.4.2  nathanw 	audioamd_codec_iread16,
    133  1.7.4.2  nathanw 	audioamd_codec_iwrite16,
    134  1.7.4.2  nathanw 	audioamd_onopen,
    135  1.7.4.2  nathanw 	audioamd_onclose,
    136  1.7.4.2  nathanw 	0,
    137  1.7.4.2  nathanw 	0,
    138  1.7.4.2  nathanw 	0,
    139  1.7.4.2  nathanw };
    140  1.7.4.2  nathanw 
    141  1.7.4.2  nathanw /*
    142  1.7.4.2  nathanw  * Define our interface to the higher level audio driver.
    143  1.7.4.2  nathanw  */
    144  1.7.4.2  nathanw int	audioamd_start_output __P((void *, void *, int, void (*)(void *),
    145  1.7.4.2  nathanw 				  void *));
    146  1.7.4.2  nathanw int	audioamd_start_input __P((void *, void *, int, void (*)(void *),
    147  1.7.4.2  nathanw 				 void *));
    148  1.7.4.2  nathanw int	audioamd_getdev __P((void *, struct audio_device *));
    149  1.7.4.2  nathanw 
    150  1.7.4.2  nathanw struct audio_hw_if sa_hw_if = {
    151  1.7.4.2  nathanw 	am7930_open,
    152  1.7.4.2  nathanw 	am7930_close,
    153  1.7.4.2  nathanw 	0,
    154  1.7.4.2  nathanw 	am7930_query_encoding,
    155  1.7.4.2  nathanw 	am7930_set_params,
    156  1.7.4.2  nathanw 	am7930_round_blocksize,
    157  1.7.4.2  nathanw 	am7930_commit_settings,
    158  1.7.4.2  nathanw 	0,
    159  1.7.4.2  nathanw 	0,
    160  1.7.4.2  nathanw 	audioamd_start_output,		/* md */
    161  1.7.4.2  nathanw 	audioamd_start_input,		/* md */
    162  1.7.4.2  nathanw 	am7930_halt_output,
    163  1.7.4.2  nathanw 	am7930_halt_input,
    164  1.7.4.2  nathanw 	0,
    165  1.7.4.2  nathanw 	audioamd_getdev,
    166  1.7.4.2  nathanw 	0,
    167  1.7.4.2  nathanw 	am7930_set_port,
    168  1.7.4.2  nathanw 	am7930_get_port,
    169  1.7.4.2  nathanw 	am7930_query_devinfo,
    170  1.7.4.2  nathanw 	0,
    171  1.7.4.2  nathanw 	0,
    172  1.7.4.2  nathanw 	0,
    173  1.7.4.2  nathanw         0,
    174  1.7.4.2  nathanw 	am7930_get_props,
    175  1.7.4.2  nathanw 	0,
    176  1.7.4.2  nathanw 	0,
    177  1.7.4.2  nathanw         0,
    178  1.7.4.2  nathanw };
    179  1.7.4.2  nathanw 
    180  1.7.4.2  nathanw struct audio_device audioamd_device = {
    181  1.7.4.2  nathanw 	"am7930",
    182  1.7.4.2  nathanw 	"x",
    183  1.7.4.2  nathanw 	"audioamd"
    184  1.7.4.2  nathanw };
    185  1.7.4.2  nathanw 
    186  1.7.4.2  nathanw 
    187  1.7.4.2  nathanw int
    188  1.7.4.2  nathanw audioamd_mainbus_match(parent, cf, aux)
    189  1.7.4.2  nathanw 	struct device *parent;
    190  1.7.4.2  nathanw 	struct cfdata *cf;
    191  1.7.4.2  nathanw 	void *aux;
    192  1.7.4.2  nathanw {
    193  1.7.4.2  nathanw 	struct mainbus_attach_args *ma = aux;
    194  1.7.4.2  nathanw 
    195  1.7.4.2  nathanw 	if (CPU_ISSUN4)
    196  1.7.4.2  nathanw 		return (0);
    197  1.7.4.2  nathanw 	return (strcmp(AUDIO_ROM_NAME, ma->ma_name) == 0);
    198  1.7.4.2  nathanw }
    199  1.7.4.2  nathanw 
    200  1.7.4.2  nathanw int
    201  1.7.4.4  nathanw audioamd_obio_match(parent, cf, aux)
    202  1.7.4.4  nathanw 	struct device *parent;
    203  1.7.4.4  nathanw 	struct cfdata *cf;
    204  1.7.4.4  nathanw 	void *aux;
    205  1.7.4.4  nathanw {
    206  1.7.4.4  nathanw 	union obio_attach_args *uoba = aux;
    207  1.7.4.4  nathanw 
    208  1.7.4.4  nathanw 	if (uoba->uoba_isobio4 != 0)
    209  1.7.4.4  nathanw 		return (0);
    210  1.7.4.4  nathanw 
    211  1.7.4.4  nathanw 	return (strcmp("audio", uoba->uoba_sbus.sa_name) == 0);
    212  1.7.4.4  nathanw }
    213  1.7.4.4  nathanw 
    214  1.7.4.4  nathanw int
    215  1.7.4.2  nathanw audioamd_sbus_match(parent, cf, aux)
    216  1.7.4.2  nathanw 	struct device *parent;
    217  1.7.4.2  nathanw 	struct cfdata *cf;
    218  1.7.4.2  nathanw 	void *aux;
    219  1.7.4.2  nathanw {
    220  1.7.4.2  nathanw 	struct sbus_attach_args *sa = aux;
    221  1.7.4.2  nathanw 
    222  1.7.4.2  nathanw 	return (strcmp(AUDIO_ROM_NAME, sa->sa_name) == 0);
    223  1.7.4.2  nathanw }
    224  1.7.4.2  nathanw 
    225  1.7.4.2  nathanw void
    226  1.7.4.2  nathanw audioamd_mainbus_attach(parent, self, aux)
    227  1.7.4.2  nathanw 	struct device *parent, *self;
    228  1.7.4.2  nathanw 	void *aux;
    229  1.7.4.2  nathanw {
    230  1.7.4.2  nathanw 	struct mainbus_attach_args *ma = aux;
    231  1.7.4.2  nathanw 	struct audioamd_softc *sc = (struct audioamd_softc *)self;
    232  1.7.4.2  nathanw 	bus_space_handle_t bh;
    233  1.7.4.2  nathanw 
    234  1.7.4.2  nathanw 	sc->sc_bt = ma->ma_bustag;
    235  1.7.4.2  nathanw 
    236  1.7.4.2  nathanw 	if (bus_space_map(
    237  1.7.4.2  nathanw 			ma->ma_bustag,
    238  1.7.4.2  nathanw 			ma->ma_paddr,
    239  1.7.4.2  nathanw 			AM7930_DREG_SIZE,
    240  1.7.4.2  nathanw 			BUS_SPACE_MAP_LINEAR,
    241  1.7.4.2  nathanw 			&bh) != 0) {
    242  1.7.4.2  nathanw 		printf("%s: cannot map registers\n", self->dv_xname);
    243  1.7.4.2  nathanw 		return;
    244  1.7.4.2  nathanw 	}
    245  1.7.4.2  nathanw 	sc->sc_bh = bh;
    246  1.7.4.2  nathanw 	audioamd_attach(sc, ma->ma_pri);
    247  1.7.4.2  nathanw }
    248  1.7.4.2  nathanw 
    249  1.7.4.4  nathanw void
    250  1.7.4.4  nathanw audioamd_obio_attach(parent, self, aux)
    251  1.7.4.4  nathanw 	struct device *parent, *self;
    252  1.7.4.4  nathanw 	void *aux;
    253  1.7.4.4  nathanw {
    254  1.7.4.4  nathanw 	union obio_attach_args *uoba = aux;
    255  1.7.4.4  nathanw 	struct sbus_attach_args *sa = &uoba->uoba_sbus;
    256  1.7.4.4  nathanw 	struct audioamd_softc *sc = (struct audioamd_softc *)self;
    257  1.7.4.4  nathanw 	bus_space_handle_t bh;
    258  1.7.4.4  nathanw 
    259  1.7.4.4  nathanw 	sc->sc_bt = sa->sa_bustag;
    260  1.7.4.4  nathanw 
    261  1.7.4.4  nathanw 	if (sbus_bus_map(sa->sa_bustag,
    262  1.7.4.4  nathanw 			 sa->sa_slot, sa->sa_offset,
    263  1.7.4.4  nathanw 			 AM7930_DREG_SIZE,
    264  1.7.4.4  nathanw 			 0, &bh) != 0) {
    265  1.7.4.4  nathanw 		printf("%s: cannot map registers\n", self->dv_xname);
    266  1.7.4.4  nathanw 		return;
    267  1.7.4.4  nathanw 	}
    268  1.7.4.4  nathanw 	sc->sc_bh = bh;
    269  1.7.4.4  nathanw 	audioamd_attach(sc, sa->sa_pri);
    270  1.7.4.4  nathanw }
    271  1.7.4.2  nathanw 
    272  1.7.4.2  nathanw void
    273  1.7.4.2  nathanw audioamd_sbus_attach(parent, self, aux)
    274  1.7.4.2  nathanw 	struct device *parent, *self;
    275  1.7.4.2  nathanw 	void *aux;
    276  1.7.4.2  nathanw {
    277  1.7.4.2  nathanw 	struct sbus_attach_args *sa = aux;
    278  1.7.4.2  nathanw 	struct audioamd_softc *sc = (struct audioamd_softc *)self;
    279  1.7.4.2  nathanw 	bus_space_handle_t bh;
    280  1.7.4.2  nathanw 
    281  1.7.4.2  nathanw 	sc->sc_bt = sa->sa_bustag;
    282  1.7.4.2  nathanw 
    283  1.7.4.2  nathanw 	if (sbus_bus_map(sa->sa_bustag,
    284  1.7.4.2  nathanw 			 sa->sa_slot, sa->sa_offset,
    285  1.7.4.2  nathanw 			 AM7930_DREG_SIZE,
    286  1.7.4.2  nathanw 			 0, &bh) != 0) {
    287  1.7.4.2  nathanw 		printf("%s: cannot map registers\n", self->dv_xname);
    288  1.7.4.2  nathanw 		return;
    289  1.7.4.2  nathanw 	}
    290  1.7.4.2  nathanw 	sc->sc_bh = bh;
    291  1.7.4.2  nathanw 	audioamd_attach(sc, sa->sa_pri);
    292  1.7.4.2  nathanw }
    293  1.7.4.2  nathanw 
    294  1.7.4.2  nathanw void
    295  1.7.4.2  nathanw audioamd_attach(sc, pri)
    296  1.7.4.2  nathanw 	struct audioamd_softc *sc;
    297  1.7.4.2  nathanw 	int pri;
    298  1.7.4.2  nathanw {
    299  1.7.4.2  nathanw 
    300  1.7.4.2  nathanw 	/*
    301  1.7.4.2  nathanw 	 * Set up glue for MI code early; we use some of it here.
    302  1.7.4.2  nathanw 	 */
    303  1.7.4.2  nathanw 	sc->sc_am7930.sc_glue = &audioamd_glue;
    304  1.7.4.2  nathanw 
    305  1.7.4.2  nathanw 	am7930_init(&sc->sc_am7930, AUDIOAMD_POLL_MODE);
    306  1.7.4.2  nathanw 
    307  1.7.4.2  nathanw 	auiop = &sc->sc_au;
    308  1.7.4.5  thorpej 
    309  1.7.4.5  thorpej 	/* Copy bus tag & handle for use by am7930_trap */
    310  1.7.4.5  thorpej 	sc->sc_au.au_bt = sc->sc_bt;
    311  1.7.4.5  thorpej 	sc->sc_au.au_bh = sc->sc_bh;
    312  1.7.4.5  thorpej 	(void)bus_intr_establish2(sc->sc_bt, pri, IPL_AUDIO,
    313  1.7.4.5  thorpej 				  am7930hwintr, sc, amd7930_trap);
    314  1.7.4.5  thorpej 
    315  1.7.4.5  thorpej 	sc->sc_sicookie = softintr_establish(IPL_SOFTAUDIO, am7930swintr, sc);
    316  1.7.4.5  thorpej 	if (sc->sc_sicookie == NULL) {
    317  1.7.4.5  thorpej 		printf("\n%s: cannot establish software interrupt\n",
    318  1.7.4.5  thorpej 			sc->sc_am7930.sc_dev.dv_xname);
    319  1.7.4.5  thorpej 		return;
    320  1.7.4.5  thorpej 	}
    321  1.7.4.5  thorpej 
    322  1.7.4.5  thorpej 	printf(" softpri %d\n", IPL_SOFTAUDIO);
    323  1.7.4.5  thorpej 
    324  1.7.4.2  nathanw 
    325  1.7.4.2  nathanw 	evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
    326  1.7.4.2  nathanw 	    sc->sc_am7930.sc_dev.dv_xname, "intr");
    327  1.7.4.2  nathanw 
    328  1.7.4.2  nathanw 	audio_attach_mi(&sa_hw_if, sc, &sc->sc_am7930.sc_dev);
    329  1.7.4.2  nathanw }
    330  1.7.4.2  nathanw 
    331  1.7.4.2  nathanw 
    332  1.7.4.2  nathanw void
    333  1.7.4.2  nathanw audioamd_onopen(sc)
    334  1.7.4.2  nathanw 	struct am7930_softc *sc;
    335  1.7.4.2  nathanw {
    336  1.7.4.2  nathanw 	struct audioamd_softc *mdsc = (struct audioamd_softc *)sc;
    337  1.7.4.2  nathanw 
    338  1.7.4.2  nathanw 	/* reset pdma state */
    339  1.7.4.2  nathanw 	mdsc->sc_rintr = 0;
    340  1.7.4.2  nathanw 	mdsc->sc_rarg = 0;
    341  1.7.4.2  nathanw 	mdsc->sc_pintr = 0;
    342  1.7.4.2  nathanw 	mdsc->sc_parg = 0;
    343  1.7.4.2  nathanw 
    344  1.7.4.2  nathanw 	mdsc->sc_au.au_rdata = 0;
    345  1.7.4.2  nathanw 	mdsc->sc_au.au_pdata = 0;
    346  1.7.4.2  nathanw }
    347  1.7.4.2  nathanw 
    348  1.7.4.2  nathanw 
    349  1.7.4.2  nathanw void
    350  1.7.4.2  nathanw audioamd_onclose(sc)
    351  1.7.4.2  nathanw 	struct am7930_softc *sc;
    352  1.7.4.2  nathanw {
    353  1.7.4.2  nathanw 	/* On sparc, just do the chipset-level halt. */
    354  1.7.4.2  nathanw 	am7930_halt_input(sc);
    355  1.7.4.2  nathanw 	am7930_halt_output(sc);
    356  1.7.4.2  nathanw }
    357  1.7.4.2  nathanw 
    358  1.7.4.2  nathanw int
    359  1.7.4.2  nathanw audioamd_start_output(addr, p, cc, intr, arg)
    360  1.7.4.2  nathanw 	void *addr;
    361  1.7.4.2  nathanw 	void *p;
    362  1.7.4.2  nathanw 	int cc;
    363  1.7.4.2  nathanw 	void (*intr) __P((void *));
    364  1.7.4.2  nathanw 	void *arg;
    365  1.7.4.2  nathanw {
    366  1.7.4.2  nathanw 	struct audioamd_softc *sc = addr;
    367  1.7.4.2  nathanw 
    368  1.7.4.2  nathanw 	DPRINTFN(1, ("sa_start_output: cc=%d %p (%p)\n", cc, intr, arg));
    369  1.7.4.2  nathanw 
    370  1.7.4.2  nathanw 	if (!sc->sc_am7930.sc_locked) {
    371  1.7.4.2  nathanw 		audioamd_codec_iwrite(&sc->sc_am7930,
    372  1.7.4.2  nathanw 			AM7930_IREG_INIT, AM7930_INIT_PMS_ACTIVE);
    373  1.7.4.2  nathanw 		sc->sc_am7930.sc_locked = 1;
    374  1.7.4.2  nathanw 		DPRINTF(("sa_start_output: started intrs.\n"));
    375  1.7.4.2  nathanw 	}
    376  1.7.4.2  nathanw 	sc->sc_pintr = intr;
    377  1.7.4.2  nathanw 	sc->sc_parg = arg;
    378  1.7.4.2  nathanw 	sc->sc_au.au_pdata = p;
    379  1.7.4.2  nathanw 	sc->sc_au.au_pend = (char *)p + cc - 1;
    380  1.7.4.2  nathanw 	return(0);
    381  1.7.4.2  nathanw }
    382  1.7.4.2  nathanw 
    383  1.7.4.2  nathanw int
    384  1.7.4.2  nathanw audioamd_start_input(addr, p, cc, intr, arg)
    385  1.7.4.2  nathanw 	void *addr;
    386  1.7.4.2  nathanw 	void *p;
    387  1.7.4.2  nathanw 	int cc;
    388  1.7.4.2  nathanw 	void (*intr) __P((void *));
    389  1.7.4.2  nathanw 	void *arg;
    390  1.7.4.2  nathanw {
    391  1.7.4.2  nathanw 	struct audioamd_softc *sc = addr;
    392  1.7.4.2  nathanw 
    393  1.7.4.2  nathanw 	DPRINTFN(1, ("sa_start_input: cc=%d %p (%p)\n", cc, intr, arg));
    394  1.7.4.2  nathanw 
    395  1.7.4.2  nathanw 	if (!sc->sc_am7930.sc_locked) {
    396  1.7.4.2  nathanw 		audioamd_codec_iwrite(&sc->sc_am7930,
    397  1.7.4.2  nathanw 			AM7930_IREG_INIT, AM7930_INIT_PMS_ACTIVE);
    398  1.7.4.2  nathanw 		sc->sc_am7930.sc_locked = 1;
    399  1.7.4.2  nathanw 		DPRINTF(("sa_start_input: started intrs.\n"));
    400  1.7.4.2  nathanw 	}
    401  1.7.4.2  nathanw 	sc->sc_rintr = intr;
    402  1.7.4.2  nathanw 	sc->sc_rarg = arg;
    403  1.7.4.2  nathanw 	sc->sc_au.au_rdata = p;
    404  1.7.4.2  nathanw 	sc->sc_au.au_rend = (char *)p + cc -1;
    405  1.7.4.2  nathanw 	return(0);
    406  1.7.4.2  nathanw }
    407  1.7.4.2  nathanw 
    408  1.7.4.2  nathanw 
    409  1.7.4.2  nathanw /*
    410  1.7.4.2  nathanw  * Pseudo-DMA support: either C or locore assember.
    411  1.7.4.2  nathanw  */
    412  1.7.4.2  nathanw 
    413  1.7.4.2  nathanw int
    414  1.7.4.3  nathanw am7930hwintr(v)
    415  1.7.4.3  nathanw 	void *v;
    416  1.7.4.2  nathanw {
    417  1.7.4.3  nathanw 	struct audioamd_softc *sc = v;
    418  1.7.4.2  nathanw 	struct auio *au = &sc->sc_au;
    419  1.7.4.2  nathanw 	u_int8_t *d, *e;
    420  1.7.4.2  nathanw 	int k;
    421  1.7.4.2  nathanw 
    422  1.7.4.2  nathanw 	/* clear interrupt */
    423  1.7.4.2  nathanw 	k = audioamd_codec_dread(sc, AM7930_DREG_IR);
    424  1.7.4.5  thorpej 	if ((k & (AM7930_IR_DTTHRSH|AM7930_IR_DRTHRSH|AM7930_IR_DSRI|
    425  1.7.4.5  thorpej 		  AM7930_IR_DERI|AM7930_IR_BBUFF)) == 0)
    426  1.7.4.5  thorpej 		return (0);
    427  1.7.4.2  nathanw 
    428  1.7.4.2  nathanw 	/* receive incoming data */
    429  1.7.4.2  nathanw 	d = au->au_rdata;
    430  1.7.4.2  nathanw 	e = au->au_rend;
    431  1.7.4.2  nathanw 	if (d && d <= e) {
    432  1.7.4.2  nathanw 		*d = audioamd_codec_dread(sc, AM7930_DREG_BBRB);
    433  1.7.4.2  nathanw 		au->au_rdata++;
    434  1.7.4.2  nathanw 		if (d == e) {
    435  1.7.4.2  nathanw 			DPRINTFN(1, ("am7930hwintr: swintr(r) requested"));
    436  1.7.4.5  thorpej 			softintr_schedule(sc->sc_sicookie);
    437  1.7.4.2  nathanw 		}
    438  1.7.4.2  nathanw 	}
    439  1.7.4.2  nathanw 
    440  1.7.4.2  nathanw 	/* send outgoing data */
    441  1.7.4.2  nathanw 	d = au->au_pdata;
    442  1.7.4.2  nathanw 	e = au->au_pend;
    443  1.7.4.2  nathanw 	if (d && d <= e) {
    444  1.7.4.2  nathanw 		audioamd_codec_dwrite(sc, AM7930_DREG_BBTB, *d);
    445  1.7.4.2  nathanw 		au->au_pdata++;
    446  1.7.4.2  nathanw 		if (d == e) {
    447  1.7.4.2  nathanw 			DPRINTFN(1, ("am7930hwintr: swintr(p) requested"));
    448  1.7.4.5  thorpej 			softintr_schedule(sc->sc_sicookie);
    449  1.7.4.2  nathanw 		}
    450  1.7.4.2  nathanw 	}
    451  1.7.4.2  nathanw 
    452  1.7.4.3  nathanw 	au->au_intrcnt.ev_count++;
    453  1.7.4.2  nathanw 	return (1);
    454  1.7.4.2  nathanw }
    455  1.7.4.2  nathanw 
    456  1.7.4.5  thorpej void
    457  1.7.4.2  nathanw am7930swintr(sc0)
    458  1.7.4.2  nathanw 	void *sc0;
    459  1.7.4.2  nathanw {
    460  1.7.4.2  nathanw 	struct audioamd_softc *sc = sc0;
    461  1.7.4.2  nathanw 	struct auio *au;
    462  1.7.4.5  thorpej 	int s;
    463  1.7.4.2  nathanw 
    464  1.7.4.2  nathanw 	DPRINTFN(1, ("audiointr: sc=%p\n", sc););
    465  1.7.4.2  nathanw 
    466  1.7.4.2  nathanw 	au = &sc->sc_au;
    467  1.7.4.2  nathanw 	s = splaudio();
    468  1.7.4.2  nathanw 	if (au->au_rdata > au->au_rend && sc->sc_rintr != NULL) {
    469  1.7.4.2  nathanw 		splx(s);
    470  1.7.4.2  nathanw 		(*sc->sc_rintr)(sc->sc_rarg);
    471  1.7.4.2  nathanw 		s = splaudio();
    472  1.7.4.2  nathanw 	}
    473  1.7.4.2  nathanw 	if (au->au_pdata > au->au_pend && sc->sc_pintr != NULL) {
    474  1.7.4.2  nathanw 		splx(s);
    475  1.7.4.2  nathanw 		(*sc->sc_pintr)(sc->sc_parg);
    476  1.7.4.2  nathanw 	} else
    477  1.7.4.2  nathanw 		splx(s);
    478  1.7.4.2  nathanw }
    479  1.7.4.2  nathanw 
    480  1.7.4.2  nathanw 
    481  1.7.4.2  nathanw /* indirect write */
    482  1.7.4.2  nathanw void
    483  1.7.4.2  nathanw audioamd_codec_iwrite(sc, reg, val)
    484  1.7.4.2  nathanw 	struct am7930_softc *sc;
    485  1.7.4.2  nathanw 	int reg;
    486  1.7.4.2  nathanw 	u_int8_t val;
    487  1.7.4.2  nathanw {
    488  1.7.4.2  nathanw 	struct audioamd_softc *mdsc = (struct audioamd_softc *)sc;
    489  1.7.4.2  nathanw 
    490  1.7.4.2  nathanw 	audioamd_codec_dwrite(mdsc, AM7930_DREG_CR, reg);
    491  1.7.4.2  nathanw 	audioamd_codec_dwrite(mdsc, AM7930_DREG_DR, val);
    492  1.7.4.2  nathanw }
    493  1.7.4.2  nathanw 
    494  1.7.4.2  nathanw void
    495  1.7.4.2  nathanw audioamd_codec_iwrite16(sc, reg, val)
    496  1.7.4.2  nathanw 	struct am7930_softc *sc;
    497  1.7.4.2  nathanw 	int reg;
    498  1.7.4.2  nathanw 	u_int16_t val;
    499  1.7.4.2  nathanw {
    500  1.7.4.2  nathanw 	struct audioamd_softc *mdsc = (struct audioamd_softc *)sc;
    501  1.7.4.2  nathanw 
    502  1.7.4.2  nathanw 	audioamd_codec_dwrite(mdsc, AM7930_DREG_CR, reg);
    503  1.7.4.2  nathanw 	audioamd_codec_dwrite(mdsc, AM7930_DREG_DR, val);
    504  1.7.4.2  nathanw 	audioamd_codec_dwrite(mdsc, AM7930_DREG_DR, val>>8);
    505  1.7.4.2  nathanw }
    506  1.7.4.2  nathanw 
    507  1.7.4.2  nathanw 
    508  1.7.4.2  nathanw /* indirect read */
    509  1.7.4.2  nathanw u_int8_t
    510  1.7.4.2  nathanw audioamd_codec_iread(sc, reg)
    511  1.7.4.2  nathanw 	struct am7930_softc *sc;
    512  1.7.4.2  nathanw 	int reg;
    513  1.7.4.2  nathanw {
    514  1.7.4.2  nathanw 	struct audioamd_softc *mdsc = (struct audioamd_softc *)sc;
    515  1.7.4.2  nathanw 
    516  1.7.4.2  nathanw 	audioamd_codec_dwrite(mdsc, AM7930_DREG_CR, reg);
    517  1.7.4.2  nathanw 	return (audioamd_codec_dread(mdsc, AM7930_DREG_DR));
    518  1.7.4.2  nathanw }
    519  1.7.4.2  nathanw 
    520  1.7.4.2  nathanw u_int16_t
    521  1.7.4.2  nathanw audioamd_codec_iread16(sc, reg)
    522  1.7.4.2  nathanw 	struct am7930_softc *sc;
    523  1.7.4.2  nathanw 	int reg;
    524  1.7.4.2  nathanw {
    525  1.7.4.2  nathanw 	struct audioamd_softc *mdsc = (struct audioamd_softc *)sc;
    526  1.7.4.2  nathanw 	u_int8_t lo, hi;
    527  1.7.4.2  nathanw 
    528  1.7.4.2  nathanw 	audioamd_codec_dwrite(mdsc, AM7930_DREG_CR, reg);
    529  1.7.4.2  nathanw 	lo = audioamd_codec_dread(mdsc, AM7930_DREG_DR);
    530  1.7.4.2  nathanw 	hi = audioamd_codec_dread(mdsc, AM7930_DREG_DR);
    531  1.7.4.2  nathanw 	return ((hi << 8) | lo);
    532  1.7.4.2  nathanw }
    533  1.7.4.2  nathanw 
    534  1.7.4.2  nathanw /* direct read */
    535  1.7.4.2  nathanw u_int8_t
    536  1.7.4.2  nathanw audioamd_codec_dread(sc, reg)
    537  1.7.4.2  nathanw 	struct audioamd_softc *sc;
    538  1.7.4.2  nathanw 	int reg;
    539  1.7.4.2  nathanw {
    540  1.7.4.2  nathanw 	return (bus_space_read_1(sc->sc_bt, sc->sc_bh, reg));
    541  1.7.4.2  nathanw }
    542  1.7.4.2  nathanw 
    543  1.7.4.2  nathanw /* direct write */
    544  1.7.4.2  nathanw void
    545  1.7.4.2  nathanw audioamd_codec_dwrite(sc, reg, val)
    546  1.7.4.2  nathanw 	struct audioamd_softc *sc;
    547  1.7.4.2  nathanw 	int reg;
    548  1.7.4.2  nathanw 	u_int8_t val;
    549  1.7.4.2  nathanw {
    550  1.7.4.2  nathanw 	bus_space_write_1(sc->sc_bt, sc->sc_bh, reg, val);
    551  1.7.4.2  nathanw }
    552  1.7.4.2  nathanw 
    553  1.7.4.2  nathanw int
    554  1.7.4.2  nathanw audioamd_getdev(addr, retp)
    555  1.7.4.2  nathanw 	void *addr;
    556  1.7.4.2  nathanw 	struct audio_device *retp;
    557  1.7.4.2  nathanw {
    558  1.7.4.2  nathanw 
    559  1.7.4.2  nathanw 	*retp = audioamd_device;
    560  1.7.4.2  nathanw 	return (0);
    561  1.7.4.2  nathanw }
    562  1.7.4.2  nathanw 
    563  1.7.4.2  nathanw #endif /* NAUDIO > 0 */
    564