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