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