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