Home | History | Annotate | Line # | Download | only in pci
auvia.c revision 1.63
      1  1.63    dyoung /*	$NetBSD: auvia.c,v 1.63 2008/02/23 01:54:44 dyoung Exp $	*/
      2   1.1    tsarna 
      3   1.1    tsarna /*-
      4   1.1    tsarna  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      5   1.1    tsarna  * All rights reserved.
      6   1.1    tsarna  *
      7   1.1    tsarna  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1    tsarna  * by Tyler C. Sarna
      9   1.1    tsarna  *
     10   1.1    tsarna  * Redistribution and use in source and binary forms, with or without
     11   1.1    tsarna  * modification, are permitted provided that the following conditions
     12   1.1    tsarna  * are met:
     13   1.1    tsarna  * 1. Redistributions of source code must retain the above copyright
     14   1.1    tsarna  *    notice, this list of conditions and the following disclaimer.
     15   1.1    tsarna  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1    tsarna  *    notice, this list of conditions and the following disclaimer in the
     17   1.1    tsarna  *    documentation and/or other materials provided with the distribution.
     18   1.1    tsarna  * 3. All advertising materials mentioning features or use of this software
     19   1.1    tsarna  *    must display the following acknowledgement:
     20   1.1    tsarna  *	This product includes software developed by the NetBSD
     21   1.1    tsarna  *	Foundation, Inc. and its contributors.
     22   1.1    tsarna  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23   1.1    tsarna  *    contributors may be used to endorse or promote products derived
     24   1.1    tsarna  *    from this software without specific prior written permission.
     25   1.1    tsarna  *
     26   1.1    tsarna  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27   1.1    tsarna  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28   1.1    tsarna  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29   1.1    tsarna  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30   1.1    tsarna  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31   1.1    tsarna  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32   1.1    tsarna  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33   1.1    tsarna  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34   1.1    tsarna  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35   1.1    tsarna  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36   1.1    tsarna  * POSSIBILITY OF SUCH DAMAGE.
     37   1.1    tsarna  */
     38   1.1    tsarna 
     39   1.1    tsarna /*
     40  1.22      kent  * VIA Technologies VT82C686A / VT8233 / VT8235 Southbridge Audio Driver
     41   1.1    tsarna  *
     42   1.1    tsarna  * Documentation links:
     43   1.1    tsarna  *
     44   1.1    tsarna  * ftp://ftp.alsa-project.org/pub/manuals/via/686a.pdf
     45   1.1    tsarna  * ftp://ftp.alsa-project.org/pub/manuals/general/ac97r21.pdf
     46   1.1    tsarna  * ftp://ftp.alsa-project.org/pub/manuals/ad/AD1881_0.pdf (example AC'97 codec)
     47   1.1    tsarna  */
     48  1.14     lukem 
     49  1.14     lukem #include <sys/cdefs.h>
     50  1.63    dyoung __KERNEL_RCSID(0, "$NetBSD: auvia.c,v 1.63 2008/02/23 01:54:44 dyoung Exp $");
     51   1.1    tsarna 
     52   1.1    tsarna #include <sys/param.h>
     53   1.1    tsarna #include <sys/systm.h>
     54   1.1    tsarna #include <sys/malloc.h>
     55   1.1    tsarna #include <sys/device.h>
     56   1.1    tsarna #include <sys/audioio.h>
     57   1.1    tsarna 
     58   1.6   thorpej #include <uvm/uvm_extern.h>
     59   1.6   thorpej 
     60   1.1    tsarna #include <dev/pci/pcidevs.h>
     61   1.1    tsarna #include <dev/pci/pcivar.h>
     62   1.1    tsarna 
     63   1.1    tsarna #include <dev/audio_if.h>
     64   1.1    tsarna #include <dev/mulaw.h>
     65   1.1    tsarna #include <dev/auconv.h>
     66   1.1    tsarna 
     67  1.10  augustss #include <dev/ic/ac97reg.h>
     68   1.3   thorpej #include <dev/ic/ac97var.h>
     69   1.1    tsarna 
     70   1.1    tsarna #include <dev/pci/auviavar.h>
     71   1.1    tsarna 
     72   1.1    tsarna struct auvia_dma {
     73   1.1    tsarna 	struct auvia_dma *next;
     74  1.60  christos 	void *addr;
     75   1.1    tsarna 	size_t size;
     76   1.1    tsarna 	bus_dmamap_t map;
     77   1.1    tsarna 	bus_dma_segment_t seg;
     78   1.1    tsarna };
     79   1.1    tsarna 
     80   1.1    tsarna struct auvia_dma_op {
     81  1.51      kent 	uint32_t ptr;
     82  1.51      kent 	uint32_t flags;
     83   1.1    tsarna #define AUVIA_DMAOP_EOL		0x80000000
     84   1.1    tsarna #define AUVIA_DMAOP_FLAG	0x40000000
     85   1.1    tsarna #define AUVIA_DMAOP_STOP	0x20000000
     86   1.1    tsarna #define AUVIA_DMAOP_COUNT(x)	((x)&0x00FFFFFF)
     87   1.1    tsarna };
     88   1.1    tsarna 
     89  1.63    dyoung static int	auvia_match(device_t, struct cfdata *, void *);
     90  1.63    dyoung static void	auvia_attach(device_t, device_t, void *);
     91  1.63    dyoung static int	auvia_detach(device_t, int);
     92  1.63    dyoung static void	auvia_childdet(device_t, device_t);
     93  1.54      kent static int	auvia_open(void *, int);
     94  1.54      kent static void	auvia_close(void *);
     95  1.52   thorpej static int	auvia_query_encoding(void *, struct audio_encoding *);
     96  1.52   thorpej static void	auvia_set_params_sub(struct auvia_softc *,
     97  1.52   thorpej 				     struct auvia_softc_chan *,
     98  1.52   thorpej 				     const audio_params_t *);
     99  1.52   thorpej static int	auvia_set_params(void *, int, int, audio_params_t *,
    100  1.52   thorpej 				 audio_params_t *, stream_filter_list_t *,
    101  1.52   thorpej 				 stream_filter_list_t *);
    102  1.52   thorpej static int	auvia_round_blocksize(void *, int, int, const audio_params_t *);
    103  1.52   thorpej static int	auvia_halt_output(void *);
    104  1.52   thorpej static int	auvia_halt_input(void *);
    105  1.52   thorpej static int	auvia_getdev(void *, struct audio_device *);
    106  1.52   thorpej static int	auvia_set_port(void *, mixer_ctrl_t *);
    107  1.52   thorpej static int	auvia_get_port(void *, mixer_ctrl_t *);
    108  1.52   thorpej static int	auvia_query_devinfo(void *, mixer_devinfo_t *);
    109  1.52   thorpej static void *	auvia_malloc(void *, int, size_t, struct malloc_type *, int);
    110  1.52   thorpej static void	auvia_free(void *, void *, struct malloc_type *);
    111  1.52   thorpej static size_t	auvia_round_buffersize(void *, int, size_t);
    112  1.52   thorpej static paddr_t	auvia_mappage(void *, void *, off_t, int);
    113  1.52   thorpej static int	auvia_get_props(void *);
    114  1.52   thorpej static int	auvia_build_dma_ops(struct auvia_softc *,
    115  1.52   thorpej 				    struct auvia_softc_chan *,
    116  1.52   thorpej 				    struct auvia_dma *, void *, void *, int);
    117  1.52   thorpej static int	auvia_trigger_output(void *, void *, void *, int,
    118  1.52   thorpej 				     void (*)(void *), void *,
    119  1.52   thorpej 				     const audio_params_t *);
    120  1.52   thorpej static int	auvia_trigger_input(void *, void *, void *, int,
    121  1.52   thorpej 				    void (*)(void *), void *,
    122  1.52   thorpej 				    const audio_params_t *);
    123  1.63    dyoung static bool	auvia_resume(device_t PMF_FN_PROTO);
    124  1.52   thorpej static int	auvia_intr(void *);
    125   1.1    tsarna 
    126  1.54      kent static int	auvia_attach_codec(void *, struct ac97_codec_if *);
    127  1.54      kent static int	auvia_write_codec(void *, uint8_t, uint16_t);
    128  1.54      kent static int	auvia_read_codec(void *, uint8_t, uint16_t *);
    129  1.54      kent static int	auvia_reset_codec(void *);
    130  1.54      kent static int	auvia_waitready_codec(struct auvia_softc *);
    131  1.54      kent static int	auvia_waitvalid_codec(struct auvia_softc *);
    132  1.59   thorpej static void	auvia_spdif_event(void *, bool);
    133  1.54      kent 
    134  1.63    dyoung CFATTACH_DECL2(auvia, sizeof (struct auvia_softc),
    135  1.63    dyoung     auvia_match, auvia_attach, auvia_detach, NULL, NULL, auvia_childdet);
    136   1.1    tsarna 
    137  1.34    martin /* VIA VT823xx revision number */
    138  1.53    rpaulo #define VIA_REV_8233PRE	0x10
    139  1.34    martin #define VIA_REV_8233C	0x20
    140  1.34    martin #define VIA_REV_8233	0x30
    141  1.34    martin #define VIA_REV_8233A	0x40
    142  1.34    martin #define VIA_REV_8235	0x50
    143  1.45      kent #define VIA_REV_8237	0x60
    144  1.34    martin 
    145   1.1    tsarna #define AUVIA_PCICONF_JUNK	0x40
    146   1.1    tsarna #define		AUVIA_PCICONF_ENABLES	 0x00FF0000	/* reg 42 mask */
    147   1.1    tsarna #define		AUVIA_PCICONF_ACLINKENAB 0x00008000	/* ac link enab */
    148   1.1    tsarna #define		AUVIA_PCICONF_ACNOTRST	 0x00004000	/* ~(ac reset) */
    149   1.1    tsarna #define		AUVIA_PCICONF_ACSYNC	 0x00002000	/* ac sync */
    150   1.1    tsarna #define		AUVIA_PCICONF_ACVSR	 0x00000800	/* var. samp. rate */
    151   1.1    tsarna #define		AUVIA_PCICONF_ACSGD	 0x00000400	/* SGD enab */
    152   1.1    tsarna #define		AUVIA_PCICONF_ACFM	 0x00000200	/* FM enab */
    153   1.1    tsarna #define		AUVIA_PCICONF_ACSB	 0x00000100	/* SB enab */
    154  1.32      jmmv #define		AUVIA_PCICONF_PRIVALID	 0x00000001	/* primary codec rdy */
    155   1.1    tsarna 
    156  1.24      kent #define	AUVIA_PLAY_BASE			0x00
    157  1.24      kent #define	AUVIA_RECORD_BASE		0x10
    158  1.22      kent 
    159  1.27      kent /* *_RP_* are offsets from AUVIA_PLAY_BASE or AUVIA_RECORD_BASE */
    160  1.24      kent #define	AUVIA_RP_STAT			0x00
    161   1.1    tsarna #define		AUVIA_RPSTAT_INTR		0x03
    162  1.24      kent #define	AUVIA_RP_CONTROL		0x01
    163   1.1    tsarna #define		AUVIA_RPCTRL_START		0x80
    164   1.1    tsarna #define		AUVIA_RPCTRL_TERMINATE		0x40
    165  1.22      kent #define		AUVIA_RPCTRL_AUTOSTART		0x20
    166  1.22      kent /* The following are 8233 specific */
    167  1.22      kent #define		AUVIA_RPCTRL_STOP		0x04
    168  1.22      kent #define		AUVIA_RPCTRL_EOL		0x02
    169  1.22      kent #define		AUVIA_RPCTRL_FLAG		0x01
    170  1.27      kent #define	AUVIA_RP_MODE			0x02		/* 82c686 specific */
    171   1.1    tsarna #define		AUVIA_RPMODE_INTR_FLAG		0x01
    172   1.1    tsarna #define		AUVIA_RPMODE_INTR_EOL		0x02
    173   1.1    tsarna #define		AUVIA_RPMODE_STEREO		0x10
    174   1.1    tsarna #define		AUVIA_RPMODE_16BIT		0x20
    175   1.1    tsarna #define		AUVIA_RPMODE_AUTOSTART		0x80
    176  1.24      kent #define	AUVIA_RP_DMAOPS_BASE		0x04
    177  1.22      kent 
    178  1.24      kent #define	VIA8233_RP_DXS_LVOL		0x02
    179  1.24      kent #define	VIA8233_RP_DXS_RVOL		0x03
    180  1.24      kent #define	VIA8233_RP_RATEFMT		0x08
    181  1.22      kent #define		VIA8233_RATEFMT_48K		0xfffff
    182  1.22      kent #define		VIA8233_RATEFMT_STEREO		0x00100000
    183  1.22      kent #define		VIA8233_RATEFMT_16BIT		0x00200000
    184  1.22      kent 
    185  1.24      kent #define	VIA_RP_DMAOPS_COUNT		0x0c
    186   1.1    tsarna 
    187  1.27      kent #define VIA8233_MP_BASE			0x40
    188  1.27      kent 	/* STAT, CONTROL, DMAOPS_BASE, DMAOPS_COUNT are valid */
    189  1.27      kent #define VIA8233_OFF_MP_FORMAT		0x02
    190  1.27      kent #define		VIA8233_MP_FORMAT_8BIT		0x00
    191  1.27      kent #define		VIA8233_MP_FORMAT_16BIT		0x80
    192  1.27      kent #define		VIA8233_MP_FORMAT_CHANNLE_MASK	0x70 /* 1, 2, 4, 6 */
    193  1.27      kent #define VIA8233_OFF_MP_SCRATCH		0x03
    194  1.27      kent #define VIA8233_OFF_MP_STOP		0x08
    195  1.27      kent 
    196   1.1    tsarna #define	AUVIA_CODEC_CTL			0x80
    197   1.1    tsarna #define		AUVIA_CODEC_READ		0x00800000
    198   1.1    tsarna #define		AUVIA_CODEC_BUSY		0x01000000
    199   1.1    tsarna #define		AUVIA_CODEC_PRIVALID		0x02000000
    200   1.1    tsarna #define		AUVIA_CODEC_INDEX(x)		((x)<<16)
    201   1.1    tsarna 
    202  1.27      kent #define CH_WRITE1(sc, ch, off, v)	\
    203  1.27      kent 	bus_space_write_1((sc)->sc_iot,	(sc)->sc_ioh, (ch)->sc_base + (off), v)
    204  1.27      kent #define CH_WRITE4(sc, ch, off, v)	\
    205  1.27      kent 	bus_space_write_4((sc)->sc_iot,	(sc)->sc_ioh, (ch)->sc_base + (off), v)
    206  1.27      kent #define CH_READ1(sc, ch, off)		\
    207  1.27      kent 	bus_space_read_1((sc)->sc_iot, (sc)->sc_ioh, (ch)->sc_base + (off))
    208  1.27      kent #define CH_READ4(sc, ch, off)		\
    209  1.27      kent 	bus_space_read_4((sc)->sc_iot, (sc)->sc_ioh, (ch)->sc_base + (off))
    210  1.27      kent 
    211   1.1    tsarna #define TIMEOUT	50
    212   1.1    tsarna 
    213  1.52   thorpej static const struct audio_hw_if auvia_hw_if = {
    214  1.54      kent 	auvia_open,
    215  1.54      kent 	auvia_close,
    216   1.1    tsarna 	NULL, /* drain */
    217   1.1    tsarna 	auvia_query_encoding,
    218   1.1    tsarna 	auvia_set_params,
    219   1.1    tsarna 	auvia_round_blocksize,
    220   1.1    tsarna 	NULL, /* commit_settings */
    221   1.1    tsarna 	NULL, /* init_output */
    222   1.1    tsarna 	NULL, /* init_input */
    223   1.1    tsarna 	NULL, /* start_output */
    224   1.1    tsarna 	NULL, /* start_input */
    225   1.1    tsarna 	auvia_halt_output,
    226   1.1    tsarna 	auvia_halt_input,
    227   1.1    tsarna 	NULL, /* speaker_ctl */
    228   1.1    tsarna 	auvia_getdev,
    229   1.1    tsarna 	NULL, /* setfd */
    230   1.1    tsarna 	auvia_set_port,
    231   1.1    tsarna 	auvia_get_port,
    232   1.1    tsarna 	auvia_query_devinfo,
    233   1.1    tsarna 	auvia_malloc,
    234   1.1    tsarna 	auvia_free,
    235   1.1    tsarna 	auvia_round_buffersize,
    236   1.1    tsarna 	auvia_mappage,
    237   1.1    tsarna 	auvia_get_props,
    238   1.1    tsarna 	auvia_trigger_output,
    239   1.1    tsarna 	auvia_trigger_input,
    240  1.13  augustss 	NULL, /* dev_ioctl */
    241  1.55  christos 	NULL, /* powerstate */
    242   1.1    tsarna };
    243   1.1    tsarna 
    244  1.48      kent #define AUVIA_FORMATS_4CH_16	2
    245  1.48      kent #define AUVIA_FORMATS_6CH_16	3
    246  1.48      kent #define AUVIA_FORMATS_4CH_8	6
    247  1.48      kent #define AUVIA_FORMATS_6CH_8	7
    248  1.48      kent static const struct audio_format auvia_formats[AUVIA_NFORMATS] = {
    249  1.48      kent 	{NULL, AUMODE_PLAY | AUMODE_RECORD, AUDIO_ENCODING_SLINEAR_LE, 16, 16,
    250  1.48      kent 	 1, AUFMT_MONAURAL, 0, {8000, 48000}},
    251  1.48      kent 	{NULL, AUMODE_PLAY | AUMODE_RECORD, AUDIO_ENCODING_SLINEAR_LE, 16, 16,
    252  1.48      kent 	 2, AUFMT_STEREO, 0, {8000, 48000}},
    253  1.48      kent 	{NULL, AUMODE_PLAY, AUDIO_ENCODING_SLINEAR_LE, 16, 16,
    254  1.48      kent 	 4, AUFMT_SURROUND4, 0, {8000, 48000}},
    255  1.48      kent 	{NULL, AUMODE_PLAY, AUDIO_ENCODING_SLINEAR_LE, 16, 16,
    256  1.48      kent 	 6, AUFMT_DOLBY_5_1, 0, {8000, 48000}},
    257  1.48      kent 	{NULL, AUMODE_PLAY | AUMODE_RECORD, AUDIO_ENCODING_ULINEAR_LE, 8, 8,
    258  1.48      kent 	 1, AUFMT_MONAURAL, 0, {8000, 48000}},
    259  1.48      kent 	{NULL, AUMODE_PLAY | AUMODE_RECORD, AUDIO_ENCODING_ULINEAR_LE, 8, 8,
    260  1.48      kent 	 2, AUFMT_STEREO, 0, {8000, 48000}},
    261  1.48      kent 	{NULL, AUMODE_PLAY, AUDIO_ENCODING_ULINEAR_LE, 8, 8,
    262  1.48      kent 	 4, AUFMT_SURROUND4, 0, {8000, 48000}},
    263  1.48      kent 	{NULL, AUMODE_PLAY, AUDIO_ENCODING_SLINEAR_LE, 8, 8,
    264  1.48      kent 	 6, AUFMT_DOLBY_5_1, 0, {8000, 48000}},
    265  1.48      kent };
    266  1.48      kent 
    267  1.54      kent #define	AUVIA_SPDIF_NFORMATS	1
    268  1.54      kent static const struct audio_format auvia_spdif_formats[AUVIA_SPDIF_NFORMATS] = {
    269  1.54      kent 	{NULL, AUMODE_PLAY | AUMODE_RECORD, AUDIO_ENCODING_SLINEAR_LE, 16, 16,
    270  1.54      kent 	 2, AUFMT_STEREO, 1, {48000}},
    271  1.54      kent };
    272   1.1    tsarna 
    273   1.1    tsarna 
    274  1.52   thorpej static int
    275  1.63    dyoung auvia_match(device_t parent, struct cfdata *match, void *aux)
    276   1.1    tsarna {
    277  1.51      kent 	struct pci_attach_args *pa;
    278   1.1    tsarna 
    279  1.51      kent 	pa = (struct pci_attach_args *) aux;
    280   1.1    tsarna 	if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_VIATECH)
    281   1.1    tsarna 		return 0;
    282  1.15  jmcneill 	switch (PCI_PRODUCT(pa->pa_id)) {
    283  1.15  jmcneill 	case PCI_PRODUCT_VIATECH_VT82C686A_AC97:
    284  1.22      kent 	case PCI_PRODUCT_VIATECH_VT8233_AC97:
    285  1.15  jmcneill 		break;
    286  1.15  jmcneill 	default:
    287   1.1    tsarna 		return 0;
    288  1.15  jmcneill 	}
    289   1.1    tsarna 
    290   1.1    tsarna 	return 1;
    291   1.1    tsarna }
    292   1.1    tsarna 
    293  1.52   thorpej static void
    294  1.63    dyoung auvia_childdet(device_t self, device_t child)
    295  1.63    dyoung {
    296  1.63    dyoung 	/* we hold no child references, so do nothing */
    297  1.63    dyoung }
    298  1.63    dyoung 
    299  1.63    dyoung static int
    300  1.63    dyoung auvia_detach(device_t self, int flags)
    301  1.63    dyoung {
    302  1.63    dyoung 	int rc;
    303  1.63    dyoung 	struct auvia_softc *sc = device_private(self);
    304  1.63    dyoung 
    305  1.63    dyoung 	if ((rc = config_detach_children(self, flags)) != 0)
    306  1.63    dyoung 		return rc;
    307  1.63    dyoung 
    308  1.63    dyoung 	pmf_device_deregister(self);
    309  1.63    dyoung 
    310  1.63    dyoung 	auconv_delete_encodings(sc->sc_encodings);
    311  1.63    dyoung 	auconv_delete_encodings(sc->sc_spdif_encodings);
    312  1.63    dyoung 
    313  1.63    dyoung 	if (sc->codec_if != NULL)
    314  1.63    dyoung 		sc->codec_if->vtbl->detach(sc->codec_if);
    315  1.63    dyoung 
    316  1.63    dyoung 	/* XXX restore compatibility? */
    317  1.63    dyoung 
    318  1.63    dyoung 	if (sc->sc_ih != NULL)
    319  1.63    dyoung 		pci_intr_disestablish(sc->sc_pc, sc->sc_ih);
    320  1.63    dyoung 
    321  1.63    dyoung 	bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_iosize);
    322  1.63    dyoung 
    323  1.63    dyoung 	return 0;
    324  1.63    dyoung }
    325  1.63    dyoung 
    326  1.63    dyoung static void
    327  1.63    dyoung auvia_attach(device_t parent, device_t self, void *aux)
    328   1.1    tsarna {
    329  1.51      kent 	struct pci_attach_args *pa;
    330  1.51      kent 	struct auvia_softc *sc;
    331  1.51      kent 	const char *intrstr;
    332  1.51      kent 	pci_chipset_tag_t pc;
    333  1.51      kent 	pcitag_t pt;
    334  1.22      kent 	pci_intr_handle_t ih;
    335   1.1    tsarna 	pcireg_t pr;
    336  1.27      kent 	int r;
    337  1.51      kent 	const char *revnum;	/* VT823xx revision number */
    338  1.51      kent 
    339  1.51      kent 	pa = aux;
    340  1.63    dyoung 	sc = device_private(self);
    341  1.51      kent 	intrstr = NULL;
    342  1.51      kent 	pc = pa->pa_pc;
    343  1.51      kent 	pt = pa->pa_tag;
    344  1.51      kent 	revnum = NULL;
    345  1.22      kent 
    346  1.29   thorpej 	aprint_naive(": Audio controller\n");
    347  1.29   thorpej 
    348  1.27      kent 	sc->sc_play.sc_base = AUVIA_PLAY_BASE;
    349  1.27      kent 	sc->sc_record.sc_base = AUVIA_RECORD_BASE;
    350  1.27      kent 	if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_VIATECH_VT8233_AC97) {
    351  1.22      kent 		sc->sc_flags |= AUVIA_FLAGS_VT8233;
    352  1.27      kent 		sc->sc_play.sc_base = VIA8233_MP_BASE;
    353  1.27      kent 	}
    354  1.22      kent 
    355  1.22      kent 	if (pci_mapreg_map(pa, 0x10, PCI_MAPREG_TYPE_IO, 0, &sc->sc_iot,
    356  1.63    dyoung 		&sc->sc_ioh, NULL, &sc->sc_iosize)) {
    357  1.29   thorpej 		aprint_error(": can't map i/o space\n");
    358  1.22      kent 		return;
    359  1.22      kent 	}
    360  1.22      kent 
    361  1.22      kent 	sc->sc_dmat = pa->pa_dmat;
    362  1.22      kent 	sc->sc_pc = pc;
    363  1.22      kent 	sc->sc_pt = pt;
    364   1.1    tsarna 
    365   1.1    tsarna 	r = PCI_REVISION(pa->pa_class);
    366  1.22      kent 	if (sc->sc_flags & AUVIA_FLAGS_VT8233) {
    367  1.39    itojun 		snprintf(sc->sc_revision, sizeof(sc->sc_revision), "0x%02X", r);
    368  1.34    martin 		switch(r) {
    369  1.53    rpaulo 		case VIA_REV_8233PRE:
    370  1.53    rpaulo 			/* same as 8233, but should not be in the market */
    371  1.53    rpaulo 			revnum = "3-Pre";
    372  1.53    rpaulo 			break;
    373  1.34    martin 		case VIA_REV_8233C:
    374  1.34    martin 			/* 2 rec, 4 pb, 1 multi-pb */
    375  1.34    martin 			revnum = "3C";
    376  1.34    martin 			break;
    377  1.34    martin 		case VIA_REV_8233:
    378  1.34    martin 			/* 2 rec, 4 pb, 1 multi-pb, spdif */
    379  1.34    martin 			revnum = "3";
    380  1.34    martin 			break;
    381  1.34    martin 		case VIA_REV_8233A:
    382  1.34    martin 			/* 1 rec, 1 multi-pb, spdif */
    383  1.34    martin 			revnum = "3A";
    384  1.34    martin 			break;
    385  1.34    martin 		default:
    386  1.36   xtraeme 			break;
    387  1.22      kent 		}
    388  1.49   xtraeme 		if (r >= VIA_REV_8237)
    389  1.45      kent 			revnum = "7";
    390  1.45      kent 		else if (r >= VIA_REV_8235) /* 2 rec, 4 pb, 1 multi-pb, spdif */
    391  1.35   xtraeme 			revnum = "5";
    392  1.38      jmmv 		aprint_normal(": VIA Technologies VT823%s AC'97 Audio "
    393  1.38      jmmv 		    "(rev %s)\n", revnum, sc->sc_revision);
    394   1.1    tsarna 	} else {
    395  1.22      kent 		sc->sc_revision[1] = '\0';
    396  1.22      kent 		if (r == 0x20) {
    397  1.22      kent 			sc->sc_revision[0] = 'H';
    398  1.22      kent 		} else if ((r >= 0x10) && (r <= 0x14)) {
    399  1.22      kent 			sc->sc_revision[0] = 'A' + (r - 0x10);
    400  1.22      kent 		} else {
    401  1.39    itojun 			snprintf(sc->sc_revision, sizeof(sc->sc_revision),
    402  1.39    itojun 			    "0x%02X", r);
    403  1.22      kent 		}
    404  1.22      kent 
    405  1.38      jmmv 		aprint_normal(": VIA Technologies VT82C686A AC'97 Audio "
    406  1.38      jmmv 		    "(rev %s)\n", sc->sc_revision);
    407   1.1    tsarna 	}
    408   1.1    tsarna 
    409   1.9  sommerfe 	if (pci_intr_map(pa, &ih)) {
    410  1.29   thorpej 		aprint_error(": couldn't map interrupt\n");
    411  1.63    dyoung 		bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_iosize);
    412   1.1    tsarna 		return;
    413   1.1    tsarna 	}
    414   1.1    tsarna 	intrstr = pci_intr_string(pc, ih);
    415   1.1    tsarna 
    416   1.1    tsarna 	sc->sc_ih = pci_intr_establish(pc, ih, IPL_AUDIO, auvia_intr, sc);
    417   1.1    tsarna 	if (sc->sc_ih == NULL) {
    418  1.29   thorpej 		aprint_error("%s: couldn't establish interrupt",
    419  1.29   thorpej 		    sc->sc_dev.dv_xname);
    420   1.1    tsarna 		if (intrstr != NULL)
    421  1.29   thorpej 			aprint_normal(" at %s", intrstr);
    422  1.29   thorpej 		aprint_normal("\n");
    423  1.63    dyoung 		bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_iosize);
    424   1.1    tsarna 		return;
    425   1.1    tsarna 	}
    426   1.1    tsarna 
    427  1.29   thorpej 	aprint_normal("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
    428   1.1    tsarna 
    429   1.1    tsarna 	/* disable SBPro compat & others */
    430   1.1    tsarna 	pr = pci_conf_read(pc, pt, AUVIA_PCICONF_JUNK);
    431   1.1    tsarna 
    432   1.1    tsarna 	pr &= ~AUVIA_PCICONF_ENABLES; /* clear compat function enables */
    433   1.1    tsarna 	/* XXX what to do about MIDI, FM, joystick? */
    434   1.1    tsarna 
    435   1.1    tsarna 	pr |= (AUVIA_PCICONF_ACLINKENAB | AUVIA_PCICONF_ACNOTRST
    436   1.1    tsarna 		| AUVIA_PCICONF_ACVSR | AUVIA_PCICONF_ACSGD);
    437   1.1    tsarna 
    438   1.1    tsarna 	pr &= ~(AUVIA_PCICONF_ACFM | AUVIA_PCICONF_ACSB);
    439   1.1    tsarna 
    440   1.1    tsarna 	pci_conf_write(pc, pt, AUVIA_PCICONF_JUNK, pr);
    441   1.1    tsarna 
    442   1.1    tsarna 	sc->host_if.arg = sc;
    443   1.1    tsarna 	sc->host_if.attach = auvia_attach_codec;
    444   1.1    tsarna 	sc->host_if.read = auvia_read_codec;
    445   1.1    tsarna 	sc->host_if.write = auvia_write_codec;
    446   1.1    tsarna 	sc->host_if.reset = auvia_reset_codec;
    447  1.54      kent 	sc->host_if.spdif_event = auvia_spdif_event;
    448   1.1    tsarna 
    449  1.50      kent 	if ((r = ac97_attach(&sc->host_if, self)) != 0) {
    450  1.29   thorpej 		aprint_error("%s: can't attach codec (error 0x%X)\n",
    451   1.1    tsarna 			sc->sc_dev.dv_xname, r);
    452  1.22      kent 		pci_intr_disestablish(pc, sc->sc_ih);
    453  1.63    dyoung 		bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_iosize);
    454   1.1    tsarna 		return;
    455   1.1    tsarna 	}
    456   1.1    tsarna 
    457  1.48      kent 	/* setup audio_format */
    458  1.48      kent 	memcpy(sc->sc_formats, auvia_formats, sizeof(auvia_formats));
    459  1.48      kent 	if (sc->sc_play.sc_base != VIA8233_MP_BASE || !AC97_IS_4CH(sc->codec_if)) {
    460  1.48      kent 		AUFMT_INVALIDATE(&sc->sc_formats[AUVIA_FORMATS_4CH_8]);
    461  1.48      kent 		AUFMT_INVALIDATE(&sc->sc_formats[AUVIA_FORMATS_4CH_16]);
    462  1.48      kent 	}
    463  1.48      kent 	if (sc->sc_play.sc_base != VIA8233_MP_BASE || !AC97_IS_6CH(sc->codec_if)) {
    464  1.48      kent 		AUFMT_INVALIDATE(&sc->sc_formats[AUVIA_FORMATS_6CH_8]);
    465  1.48      kent 		AUFMT_INVALIDATE(&sc->sc_formats[AUVIA_FORMATS_6CH_16]);
    466  1.48      kent 	}
    467  1.48      kent 	if (AC97_IS_FIXED_RATE(sc->codec_if)) {
    468  1.48      kent 		for (r = 0; r < AUVIA_NFORMATS; r++) {
    469  1.48      kent 			sc->sc_formats[r].frequency_type = 1;
    470  1.48      kent 			sc->sc_formats[r].frequency[0] = 48000;
    471  1.48      kent 		}
    472  1.48      kent 	}
    473  1.48      kent 
    474  1.48      kent 	if (0 != auconv_create_encodings(sc->sc_formats, AUVIA_NFORMATS,
    475  1.48      kent 					 &sc->sc_encodings)) {
    476  1.48      kent 		sc->codec_if->vtbl->detach(sc->codec_if);
    477  1.48      kent 		pci_intr_disestablish(pc, sc->sc_ih);
    478  1.63    dyoung 		bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_iosize);
    479  1.48      kent 		return;
    480  1.48      kent 	}
    481  1.54      kent 	if (0 != auconv_create_encodings(auvia_spdif_formats,
    482  1.54      kent 	    AUVIA_SPDIF_NFORMATS, &sc->sc_spdif_encodings)) {
    483  1.54      kent 		sc->codec_if->vtbl->detach(sc->codec_if);
    484  1.54      kent 		pci_intr_disestablish(pc, sc->sc_ih);
    485  1.63    dyoung 		bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_iosize);
    486  1.54      kent 		return;
    487  1.54      kent 	}
    488  1.48      kent 
    489  1.61  jmcneill 	if (!pmf_device_register(self, NULL, auvia_resume))
    490  1.61  jmcneill 		aprint_error_dev(self, "couldn't establish power handler\n");
    491  1.43      kent 
    492  1.22      kent 	audio_attach_mi(&auvia_hw_if, sc, &sc->sc_dev);
    493  1.54      kent 	sc->codec_if->vtbl->unlock(sc->codec_if);
    494  1.48      kent 	return;
    495   1.1    tsarna }
    496   1.1    tsarna 
    497  1.52   thorpej static int
    498   1.1    tsarna auvia_attach_codec(void *addr, struct ac97_codec_if *cif)
    499   1.1    tsarna {
    500  1.51      kent 	struct auvia_softc *sc;
    501   1.1    tsarna 
    502  1.51      kent 	sc = addr;
    503   1.1    tsarna 	sc->codec_if = cif;
    504   1.1    tsarna 	return 0;
    505   1.1    tsarna }
    506   1.1    tsarna 
    507  1.52   thorpej static int
    508   1.1    tsarna auvia_reset_codec(void *addr)
    509   1.1    tsarna {
    510  1.51      kent 	struct auvia_softc *sc;
    511  1.51      kent 	pcireg_t r;
    512  1.32      jmmv 	int i;
    513   1.1    tsarna 
    514   1.1    tsarna 	/* perform a codec cold reset */
    515  1.51      kent 	sc = addr;
    516   1.1    tsarna 	r = pci_conf_read(sc->sc_pc, sc->sc_pt, AUVIA_PCICONF_JUNK);
    517   1.1    tsarna 
    518   1.1    tsarna 	r &= ~AUVIA_PCICONF_ACNOTRST;	/* enable RESET (active low) */
    519   1.1    tsarna 	pci_conf_write(sc->sc_pc, sc->sc_pt, AUVIA_PCICONF_JUNK, r);
    520   1.1    tsarna 	delay(2);
    521   1.1    tsarna 
    522  1.22      kent 	r |= AUVIA_PCICONF_ACNOTRST;	/* disable RESET (inactive high) */
    523   1.1    tsarna 	pci_conf_write(sc->sc_pc, sc->sc_pt, AUVIA_PCICONF_JUNK, r);
    524   1.1    tsarna 	delay(200);
    525   1.1    tsarna 
    526  1.32      jmmv 	for (i = 500000; i != 0 && !(pci_conf_read(sc->sc_pc, sc->sc_pt,
    527  1.32      jmmv 		AUVIA_PCICONF_JUNK) & AUVIA_PCICONF_PRIVALID); i--)
    528  1.32      jmmv 		DELAY(1);
    529  1.42      kent 	if (i == 0) {
    530  1.32      jmmv 		printf("%s: codec reset timed out\n", sc->sc_dev.dv_xname);
    531  1.42      kent 		return ETIMEDOUT;
    532  1.42      kent 	}
    533  1.42      kent 	return 0;
    534   1.1    tsarna }
    535   1.1    tsarna 
    536  1.52   thorpej static int
    537   1.1    tsarna auvia_waitready_codec(struct auvia_softc *sc)
    538   1.1    tsarna {
    539   1.1    tsarna 	int i;
    540   1.1    tsarna 
    541   1.1    tsarna 	/* poll until codec not busy */
    542   1.1    tsarna 	for (i = 0; (i < TIMEOUT) && (bus_space_read_4(sc->sc_iot, sc->sc_ioh,
    543   1.1    tsarna 		AUVIA_CODEC_CTL) & AUVIA_CODEC_BUSY); i++)
    544   1.1    tsarna 		delay(1);
    545   1.1    tsarna 	if (i >= TIMEOUT) {
    546   1.1    tsarna 		printf("%s: codec busy\n", sc->sc_dev.dv_xname);
    547   1.1    tsarna 		return 1;
    548   1.1    tsarna 	}
    549   1.1    tsarna 
    550   1.1    tsarna 	return 0;
    551   1.1    tsarna }
    552   1.1    tsarna 
    553  1.52   thorpej static int
    554   1.1    tsarna auvia_waitvalid_codec(struct auvia_softc *sc)
    555   1.1    tsarna {
    556   1.1    tsarna 	int i;
    557   1.1    tsarna 
    558   1.1    tsarna 	/* poll until codec valid */
    559   1.1    tsarna 	for (i = 0; (i < TIMEOUT) && !(bus_space_read_4(sc->sc_iot, sc->sc_ioh,
    560   1.1    tsarna 		AUVIA_CODEC_CTL) & AUVIA_CODEC_PRIVALID); i++)
    561   1.1    tsarna 			delay(1);
    562   1.1    tsarna 	if (i >= TIMEOUT) {
    563   1.1    tsarna 		printf("%s: codec invalid\n", sc->sc_dev.dv_xname);
    564   1.1    tsarna 		return 1;
    565   1.1    tsarna 	}
    566   1.1    tsarna 
    567   1.1    tsarna 	return 0;
    568   1.1    tsarna }
    569   1.1    tsarna 
    570  1.52   thorpej static int
    571   1.1    tsarna auvia_write_codec(void *addr, u_int8_t reg, u_int16_t val)
    572   1.1    tsarna {
    573  1.51      kent 	struct auvia_softc *sc;
    574   1.1    tsarna 
    575  1.51      kent 	sc = addr;
    576   1.1    tsarna 	if (auvia_waitready_codec(sc))
    577   1.1    tsarna 		return 1;
    578   1.1    tsarna 
    579   1.1    tsarna 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, AUVIA_CODEC_CTL,
    580   1.1    tsarna 		AUVIA_CODEC_PRIVALID | AUVIA_CODEC_INDEX(reg) | val);
    581   1.1    tsarna 
    582   1.1    tsarna 	return 0;
    583   1.1    tsarna }
    584   1.1    tsarna 
    585  1.52   thorpej static int
    586   1.1    tsarna auvia_read_codec(void *addr, u_int8_t reg, u_int16_t *val)
    587   1.1    tsarna {
    588  1.51      kent 	struct auvia_softc *sc;
    589   1.1    tsarna 
    590  1.51      kent 	sc = addr;
    591   1.1    tsarna 	if (auvia_waitready_codec(sc))
    592   1.1    tsarna 		return 1;
    593   1.1    tsarna 
    594   1.1    tsarna 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, AUVIA_CODEC_CTL,
    595   1.1    tsarna 		AUVIA_CODEC_PRIVALID | AUVIA_CODEC_READ | AUVIA_CODEC_INDEX(reg));
    596   1.1    tsarna 
    597   1.1    tsarna 	if (auvia_waitready_codec(sc))
    598   1.1    tsarna 		return 1;
    599   1.1    tsarna 
    600   1.1    tsarna 	if (auvia_waitvalid_codec(sc))
    601   1.1    tsarna 		return 1;
    602   1.1    tsarna 
    603   1.1    tsarna 	*val = bus_space_read_2(sc->sc_iot, sc->sc_ioh, AUVIA_CODEC_CTL);
    604   1.1    tsarna 
    605   1.1    tsarna 	return 0;
    606   1.1    tsarna }
    607   1.1    tsarna 
    608  1.54      kent static void
    609  1.59   thorpej auvia_spdif_event(void *addr, bool flag)
    610  1.54      kent {
    611  1.54      kent 	struct auvia_softc *sc;
    612  1.54      kent 
    613  1.54      kent 	sc = addr;
    614  1.54      kent 	sc->sc_spdif = flag;
    615  1.54      kent }
    616  1.54      kent 
    617  1.54      kent static int
    618  1.58  christos auvia_open(void *addr, int flags)
    619  1.54      kent {
    620  1.54      kent 	struct auvia_softc *sc;
    621  1.54      kent 
    622  1.54      kent 	sc = (struct auvia_softc *)addr;
    623  1.54      kent 	sc->codec_if->vtbl->lock(sc->codec_if);
    624  1.54      kent 	return 0;
    625  1.54      kent }
    626  1.54      kent 
    627  1.54      kent static void
    628  1.54      kent auvia_close(void *addr)
    629  1.54      kent {
    630  1.54      kent 	struct auvia_softc *sc;
    631  1.54      kent 
    632  1.54      kent 	sc = (struct auvia_softc *)addr;
    633  1.54      kent 	sc->codec_if->vtbl->unlock(sc->codec_if);
    634  1.54      kent }
    635  1.54      kent 
    636  1.52   thorpej static int
    637   1.1    tsarna auvia_query_encoding(void *addr, struct audio_encoding *fp)
    638   1.1    tsarna {
    639  1.48      kent 	struct auvia_softc *sc;
    640  1.48      kent 
    641  1.48      kent 	sc = (struct auvia_softc *)addr;
    642  1.54      kent 	return auconv_query_encoding(
    643  1.54      kent 	    sc->sc_spdif ? sc->sc_spdif_encodings : sc->sc_encodings, fp);
    644   1.1    tsarna }
    645   1.1    tsarna 
    646  1.52   thorpej static void
    647  1.27      kent auvia_set_params_sub(struct auvia_softc *sc, struct auvia_softc_chan *ch,
    648  1.50      kent 		     const audio_params_t *p)
    649  1.27      kent {
    650  1.51      kent 	uint32_t v;
    651  1.51      kent 	uint16_t regval;
    652  1.27      kent 
    653  1.27      kent 	if (!(sc->sc_flags & AUVIA_FLAGS_VT8233)) {
    654  1.50      kent 		regval = (p->channels == 2 ? AUVIA_RPMODE_STEREO : 0)
    655  1.50      kent 			| (p->precision  == 16 ?
    656  1.27      kent 				AUVIA_RPMODE_16BIT : 0)
    657  1.27      kent 			| AUVIA_RPMODE_INTR_FLAG | AUVIA_RPMODE_INTR_EOL
    658  1.27      kent 			| AUVIA_RPMODE_AUTOSTART;
    659  1.27      kent 		ch->sc_reg = regval;
    660  1.27      kent 	} else if (ch->sc_base != VIA8233_MP_BASE) {
    661  1.27      kent 		v = CH_READ4(sc, ch, VIA8233_RP_RATEFMT);
    662  1.27      kent 		v &= ~(VIA8233_RATEFMT_48K | VIA8233_RATEFMT_STEREO
    663  1.27      kent 			| VIA8233_RATEFMT_16BIT);
    664  1.27      kent 
    665  1.50      kent 		v |= VIA8233_RATEFMT_48K * (p->sample_rate / 20)
    666  1.27      kent 			/ (48000 / 20);
    667  1.50      kent 		if (p->channels == 2)
    668  1.27      kent 			v |= VIA8233_RATEFMT_STEREO;
    669  1.50      kent 		if (p->precision == 16)
    670  1.27      kent 			v |= VIA8233_RATEFMT_16BIT;
    671  1.27      kent 
    672  1.27      kent 		CH_WRITE4(sc, ch, VIA8233_RP_RATEFMT, v);
    673  1.27      kent 	} else {
    674  1.27      kent 		static const u_int32_t slottab[7] =
    675  1.27      kent 			{ 0, 0xff000011, 0xff000021, 0,
    676  1.27      kent 			  0xff004321, 0, 0xff436521};
    677  1.27      kent 
    678  1.50      kent 		regval = (p->precision == 16
    679  1.27      kent 			? VIA8233_MP_FORMAT_16BIT : VIA8233_MP_FORMAT_8BIT)
    680  1.50      kent 			| (p->channels << 4);
    681  1.27      kent 		CH_WRITE1(sc, ch, VIA8233_OFF_MP_FORMAT, regval);
    682  1.50      kent 		CH_WRITE4(sc, ch, VIA8233_OFF_MP_STOP, slottab[p->channels]);
    683  1.27      kent 	}
    684  1.27      kent }
    685   1.1    tsarna 
    686  1.52   thorpej static int
    687  1.58  christos auvia_set_params(void *addr, int setmode, int usemode,
    688  1.57  christos     audio_params_t *play, audio_params_t *rec, stream_filter_list_t *pfil,
    689  1.57  christos     stream_filter_list_t *rfil)
    690   1.1    tsarna {
    691  1.51      kent 	struct auvia_softc *sc;
    692  1.27      kent 	struct auvia_softc_chan *ch;
    693   1.1    tsarna 	struct audio_params *p;
    694  1.27      kent 	struct ac97_codec_if* codec;
    695  1.50      kent 	stream_filter_list_t *fil;
    696  1.27      kent 	int reg, mode;
    697  1.48      kent 	int index;
    698   1.1    tsarna 
    699  1.51      kent 	sc = addr;
    700  1.27      kent 	codec = sc->codec_if;
    701   1.1    tsarna 	/* for mode in (RECORD, PLAY) */
    702  1.22      kent 	for (mode = AUMODE_RECORD; mode != -1;
    703   1.1    tsarna 	     mode = mode == AUMODE_RECORD ? AUMODE_PLAY : -1) {
    704   1.1    tsarna 		if ((setmode & mode) == 0)
    705   1.1    tsarna 			continue;
    706   1.1    tsarna 
    707  1.22      kent 		if (mode == AUMODE_PLAY ) {
    708  1.22      kent 			p = play;
    709  1.27      kent 			ch = &sc->sc_play;
    710  1.28      kent 			reg = AC97_REG_PCM_FRONT_DAC_RATE;
    711  1.50      kent 			fil = pfil;
    712  1.22      kent 		} else {
    713  1.22      kent 			p = rec;
    714  1.27      kent 			ch = &sc->sc_record;
    715  1.28      kent 			reg = AC97_REG_PCM_LR_ADC_RATE;
    716  1.50      kent 			fil = rfil;
    717  1.22      kent 		}
    718  1.22      kent 
    719   1.1    tsarna 		if (p->sample_rate < 4000 || p->sample_rate > 48000 ||
    720  1.27      kent 		    (p->precision != 8 && p->precision != 16))
    721   1.1    tsarna 			return (EINVAL);
    722  1.54      kent 		if (sc->sc_spdif)
    723  1.54      kent 			index = auconv_set_converter(auvia_spdif_formats,
    724  1.54      kent 			    AUVIA_SPDIF_NFORMATS, mode, p, TRUE, fil);
    725  1.54      kent 		else
    726  1.54      kent 			index = auconv_set_converter(sc->sc_formats,
    727  1.54      kent 			    AUVIA_NFORMATS, mode, p, TRUE, fil);
    728  1.48      kent 		if (index < 0)
    729  1.48      kent 			return EINVAL;
    730  1.50      kent 		if (fil->req_size > 0)
    731  1.50      kent 			p = &fil->filters[0].param;
    732  1.48      kent 		if (!AC97_IS_FIXED_RATE(codec)) {
    733  1.50      kent 			if (codec->vtbl->set_rate(codec, reg, &p->sample_rate))
    734  1.48      kent 				return EINVAL;
    735  1.27      kent 			reg = AC97_REG_PCM_SURR_DAC_RATE;
    736  1.50      kent 			if (p->channels >= 4
    737  1.27      kent 			    && codec->vtbl->set_rate(codec, reg,
    738  1.50      kent 						     &p->sample_rate))
    739  1.48      kent 				return EINVAL;
    740  1.27      kent 			reg = AC97_REG_PCM_LFE_DAC_RATE;
    741  1.50      kent 			if (p->channels == 6
    742  1.27      kent 			    && codec->vtbl->set_rate(codec, reg,
    743  1.50      kent 						     &p->sample_rate))
    744  1.48      kent 				return EINVAL;
    745   1.1    tsarna 		}
    746  1.27      kent 		auvia_set_params_sub(sc, ch, p);
    747   1.1    tsarna 	}
    748   1.1    tsarna 
    749   1.1    tsarna 	return 0;
    750   1.1    tsarna }
    751   1.1    tsarna 
    752  1.52   thorpej static int
    753  1.50      kent auvia_round_blocksize(void *addr, int blk,
    754  1.58  christos     int mode, const audio_params_t *param)
    755   1.1    tsarna {
    756  1.51      kent 	struct auvia_softc *sc;
    757  1.37  jmcneill 
    758  1.51      kent 	sc = addr;
    759  1.37  jmcneill 	/* XXX VT823x might have the limitation of dma_ops size */
    760  1.37  jmcneill 	if (sc->sc_flags & AUVIA_FLAGS_VT8233 && blk < 288)
    761  1.37  jmcneill 		blk = 288;
    762  1.37  jmcneill 
    763   1.1    tsarna 	return (blk & -32);
    764   1.1    tsarna }
    765   1.1    tsarna 
    766  1.52   thorpej static int
    767   1.1    tsarna auvia_halt_output(void *addr)
    768   1.1    tsarna {
    769  1.51      kent 	struct auvia_softc *sc;
    770  1.51      kent 	struct auvia_softc_chan *ch;
    771   1.1    tsarna 
    772  1.51      kent 	sc = addr;
    773  1.51      kent 	ch = &(sc->sc_play);
    774  1.27      kent 	CH_WRITE1(sc, ch, AUVIA_RP_CONTROL, AUVIA_RPCTRL_TERMINATE);
    775  1.41   mycroft 	ch->sc_intr = NULL;
    776   1.1    tsarna 	return 0;
    777   1.1    tsarna }
    778   1.1    tsarna 
    779  1.52   thorpej static int
    780   1.1    tsarna auvia_halt_input(void *addr)
    781   1.1    tsarna {
    782  1.51      kent 	struct auvia_softc *sc;
    783  1.51      kent 	struct auvia_softc_chan *ch;
    784   1.1    tsarna 
    785  1.51      kent 	sc = addr;
    786  1.51      kent 	ch = &(sc->sc_record);
    787  1.27      kent 	CH_WRITE1(sc, ch, AUVIA_RP_CONTROL, AUVIA_RPCTRL_TERMINATE);
    788  1.41   mycroft 	ch->sc_intr = NULL;
    789   1.1    tsarna 	return 0;
    790   1.1    tsarna }
    791   1.1    tsarna 
    792  1.52   thorpej static int
    793   1.1    tsarna auvia_getdev(void *addr, struct audio_device *retp)
    794   1.1    tsarna {
    795  1.51      kent 	struct auvia_softc *sc;
    796   1.1    tsarna 
    797   1.1    tsarna 	if (retp) {
    798  1.51      kent 		sc = addr;
    799  1.22      kent 		if (sc->sc_flags & AUVIA_FLAGS_VT8233) {
    800  1.45      kent 			strncpy(retp->name, "VIA VT823x",
    801  1.22      kent 				sizeof(retp->name));
    802  1.22      kent 		} else {
    803  1.22      kent 			strncpy(retp->name, "VIA VT82C686A",
    804  1.22      kent 				sizeof(retp->name));
    805  1.22      kent 		}
    806   1.1    tsarna 		strncpy(retp->version, sc->sc_revision, sizeof(retp->version));
    807   1.1    tsarna 		strncpy(retp->config, "auvia", sizeof(retp->config));
    808   1.1    tsarna 	}
    809   1.1    tsarna 
    810   1.1    tsarna 	return 0;
    811   1.1    tsarna }
    812   1.1    tsarna 
    813  1.52   thorpej static int
    814   1.1    tsarna auvia_set_port(void *addr, mixer_ctrl_t *cp)
    815   1.1    tsarna {
    816  1.51      kent 	struct auvia_softc *sc;
    817   1.1    tsarna 
    818  1.51      kent 	sc = addr;
    819  1.51      kent 	return sc->codec_if->vtbl->mixer_set_port(sc->codec_if, cp);
    820   1.1    tsarna }
    821   1.1    tsarna 
    822  1.52   thorpej static int
    823   1.1    tsarna auvia_get_port(void *addr, mixer_ctrl_t *cp)
    824   1.1    tsarna {
    825  1.51      kent 	struct auvia_softc *sc;
    826   1.1    tsarna 
    827  1.51      kent 	sc = addr;
    828  1.51      kent 	return sc->codec_if->vtbl->mixer_get_port(sc->codec_if, cp);
    829   1.1    tsarna }
    830   1.1    tsarna 
    831  1.52   thorpej static int
    832   1.1    tsarna auvia_query_devinfo(void *addr, mixer_devinfo_t *dip)
    833   1.1    tsarna {
    834  1.51      kent 	struct auvia_softc *sc;
    835   1.1    tsarna 
    836  1.51      kent 	sc = addr;
    837  1.51      kent 	return sc->codec_if->vtbl->query_devinfo(sc->codec_if, dip);
    838   1.1    tsarna }
    839   1.1    tsarna 
    840  1.52   thorpej static void *
    841  1.58  christos auvia_malloc(void *addr, int direction, size_t size,
    842  1.57  christos     struct malloc_type * pool, int flags)
    843   1.1    tsarna {
    844  1.51      kent 	struct auvia_softc *sc;
    845   1.1    tsarna 	struct auvia_dma *p;
    846   1.1    tsarna 	int error;
    847   1.1    tsarna 	int rseg;
    848   1.1    tsarna 
    849   1.1    tsarna 	p = malloc(sizeof(*p), pool, flags);
    850   1.1    tsarna 	if (!p)
    851   1.1    tsarna 		return 0;
    852  1.51      kent 	sc = addr;
    853   1.2    tsarna 	p->size = size;
    854   1.6   thorpej 	if ((error = bus_dmamem_alloc(sc->sc_dmat, size, PAGE_SIZE, 0, &p->seg,
    855   1.6   thorpej 				      1, &rseg, BUS_DMA_NOWAIT)) != 0) {
    856  1.31       wiz 		printf("%s: unable to allocate DMA, error = %d\n",
    857   1.1    tsarna 		       sc->sc_dev.dv_xname, error);
    858   1.1    tsarna 		goto fail_alloc;
    859   1.1    tsarna 	}
    860   1.1    tsarna 
    861   1.1    tsarna 	if ((error = bus_dmamem_map(sc->sc_dmat, &p->seg, rseg, size, &p->addr,
    862   1.1    tsarna 				    BUS_DMA_NOWAIT | BUS_DMA_COHERENT)) != 0) {
    863  1.31       wiz 		printf("%s: unable to map DMA, error = %d\n",
    864   1.1    tsarna 		       sc->sc_dev.dv_xname, error);
    865   1.1    tsarna 		goto fail_map;
    866   1.1    tsarna 	}
    867   1.1    tsarna 
    868  1.22      kent 	if ((error = bus_dmamap_create(sc->sc_dmat, size, 1, size, 0,
    869   1.1    tsarna 				       BUS_DMA_NOWAIT, &p->map)) != 0) {
    870  1.31       wiz 		printf("%s: unable to create DMA map, error = %d\n",
    871   1.1    tsarna 		       sc->sc_dev.dv_xname, error);
    872   1.1    tsarna 		goto fail_create;
    873   1.1    tsarna 	}
    874   1.1    tsarna 
    875   1.1    tsarna 	if ((error = bus_dmamap_load(sc->sc_dmat, p->map, p->addr, size, NULL,
    876   1.1    tsarna 				     BUS_DMA_NOWAIT)) != 0) {
    877  1.31       wiz 		printf("%s: unable to load DMA map, error = %d\n",
    878   1.1    tsarna 		       sc->sc_dev.dv_xname, error);
    879   1.1    tsarna 		goto fail_load;
    880   1.1    tsarna 	}
    881   1.1    tsarna 
    882   1.1    tsarna 	p->next = sc->sc_dmas;
    883   1.1    tsarna 	sc->sc_dmas = p;
    884   1.1    tsarna 
    885   1.1    tsarna 	return p->addr;
    886   1.1    tsarna 
    887   1.1    tsarna 
    888   1.1    tsarna fail_load:
    889   1.1    tsarna 	bus_dmamap_destroy(sc->sc_dmat, p->map);
    890   1.1    tsarna fail_create:
    891   1.1    tsarna 	bus_dmamem_unmap(sc->sc_dmat, p->addr, size);
    892   1.1    tsarna fail_map:
    893   1.1    tsarna 	bus_dmamem_free(sc->sc_dmat, &p->seg, 1);
    894   1.1    tsarna fail_alloc:
    895   1.1    tsarna 	free(p, pool);
    896  1.51      kent 	return NULL;
    897   1.1    tsarna }
    898   1.1    tsarna 
    899  1.52   thorpej static void
    900  1.30   thorpej auvia_free(void *addr, void *ptr, struct malloc_type *pool)
    901   1.1    tsarna {
    902  1.51      kent 	struct auvia_softc *sc;
    903   1.2    tsarna 	struct auvia_dma **pp, *p;
    904   1.1    tsarna 
    905  1.51      kent 	sc = addr;
    906   1.2    tsarna 	for (pp = &(sc->sc_dmas); (p = *pp) != NULL; pp = &p->next)
    907   1.2    tsarna 		if (p->addr == ptr) {
    908   1.2    tsarna 			bus_dmamap_unload(sc->sc_dmat, p->map);
    909   1.2    tsarna 			bus_dmamap_destroy(sc->sc_dmat, p->map);
    910   1.2    tsarna 			bus_dmamem_unmap(sc->sc_dmat, p->addr, p->size);
    911   1.2    tsarna 			bus_dmamem_free(sc->sc_dmat, &p->seg, 1);
    912  1.22      kent 
    913   1.2    tsarna 			*pp = p->next;
    914   1.2    tsarna 			free(p, pool);
    915   1.2    tsarna 			return;
    916   1.2    tsarna 		}
    917   1.1    tsarna 
    918   1.2    tsarna 	panic("auvia_free: trying to free unallocated memory");
    919   1.1    tsarna }
    920   1.1    tsarna 
    921  1.52   thorpej static size_t
    922  1.58  christos auvia_round_buffersize(void *addr, int direction, size_t size)
    923   1.1    tsarna {
    924  1.51      kent 
    925   1.1    tsarna 	return size;
    926   1.1    tsarna }
    927   1.1    tsarna 
    928  1.52   thorpej static paddr_t
    929   1.4    simonb auvia_mappage(void *addr, void *mem, off_t off, int prot)
    930   1.1    tsarna {
    931  1.51      kent 	struct auvia_softc *sc;
    932   1.1    tsarna 	struct auvia_dma *p;
    933   1.1    tsarna 
    934   1.1    tsarna 	if (off < 0)
    935   1.1    tsarna 		return -1;
    936  1.51      kent 	sc = addr;
    937   1.1    tsarna 	for (p = sc->sc_dmas; p && p->addr != mem; p = p->next)
    938  1.51      kent 		continue;
    939   1.1    tsarna 
    940   1.1    tsarna 	if (!p)
    941   1.1    tsarna 		return -1;
    942   1.1    tsarna 
    943  1.22      kent 	return bus_dmamem_mmap(sc->sc_dmat, &p->seg, 1, off, prot,
    944  1.51      kent 	    BUS_DMA_WAITOK);
    945   1.1    tsarna }
    946   1.1    tsarna 
    947  1.52   thorpej static int
    948   1.1    tsarna auvia_get_props(void *addr)
    949   1.1    tsarna {
    950  1.51      kent 	struct auvia_softc *sc;
    951  1.26      kent 	int props;
    952  1.26      kent 
    953  1.26      kent 	props = AUDIO_PROP_INDEPENDENT | AUDIO_PROP_FULLDUPLEX;
    954  1.51      kent 	sc = addr;
    955  1.26      kent 	/*
    956  1.26      kent 	 * Even if the codec is fixed-rate, set_param() succeeds for any sample
    957  1.26      kent 	 * rate because of aurateconv.  Applications can't know what rate the
    958  1.26      kent 	 * device can process in the case of mmap().
    959  1.26      kent 	 */
    960  1.46      kent 	if (!AC97_IS_FIXED_RATE(sc->codec_if))
    961  1.26      kent 		props |= AUDIO_PROP_MMAP;
    962  1.26      kent 	return props;
    963   1.1    tsarna }
    964   1.1    tsarna 
    965  1.52   thorpej static int
    966   1.1    tsarna auvia_build_dma_ops(struct auvia_softc *sc, struct auvia_softc_chan *ch,
    967   1.1    tsarna 	struct auvia_dma *p, void *start, void *end, int blksize)
    968   1.1    tsarna {
    969   1.1    tsarna 	struct auvia_dma_op *op;
    970   1.1    tsarna 	struct auvia_dma *dp;
    971  1.33    simonb 	bus_addr_t s;
    972   1.1    tsarna 	size_t l;
    973   1.1    tsarna 	int segs;
    974   1.1    tsarna 
    975   1.1    tsarna 	s = p->map->dm_segs[0].ds_addr;
    976   1.1    tsarna 	l = ((char *)end - (char *)start);
    977   1.1    tsarna 	segs = (l + blksize - 1) / blksize;
    978   1.1    tsarna 
    979   1.1    tsarna 	if (segs > (ch->sc_dma_op_count)) {
    980   1.1    tsarna 		/* if old list was too small, free it */
    981   1.1    tsarna 		if (ch->sc_dma_ops) {
    982   1.1    tsarna 			auvia_free(sc, ch->sc_dma_ops, M_DEVBUF);
    983   1.1    tsarna 		}
    984   1.1    tsarna 
    985   1.1    tsarna 		ch->sc_dma_ops = auvia_malloc(sc, 0,
    986   1.1    tsarna 			sizeof(struct auvia_dma_op) * segs, M_DEVBUF, M_WAITOK);
    987   1.1    tsarna 
    988   1.1    tsarna 		if (ch->sc_dma_ops == NULL) {
    989   1.1    tsarna 			printf("%s: couldn't build dmaops\n", sc->sc_dev.dv_xname);
    990   1.1    tsarna 			return 1;
    991   1.1    tsarna 		}
    992   1.1    tsarna 
    993   1.1    tsarna 		for (dp = sc->sc_dmas;
    994  1.51      kent 		     dp && dp->addr != (void *)(ch->sc_dma_ops);
    995  1.51      kent 		     dp = dp->next)
    996  1.51      kent 			continue;
    997   1.1    tsarna 
    998   1.1    tsarna 		if (!dp)
    999   1.1    tsarna 			panic("%s: build_dma_ops: where'd my memory go??? "
   1000   1.1    tsarna 				"address (%p)\n", sc->sc_dev.dv_xname,
   1001   1.1    tsarna 				ch->sc_dma_ops);
   1002   1.1    tsarna 
   1003   1.1    tsarna 		ch->sc_dma_op_count = segs;
   1004   1.1    tsarna 		ch->sc_dma_ops_dma = dp;
   1005   1.1    tsarna 	}
   1006   1.1    tsarna 
   1007   1.1    tsarna 	dp = ch->sc_dma_ops_dma;
   1008   1.1    tsarna 	op = ch->sc_dma_ops;
   1009   1.1    tsarna 
   1010   1.1    tsarna 	while (l) {
   1011  1.62   tsutsui 		op->ptr = htole32(s);
   1012   1.1    tsarna 		l = l - blksize;
   1013   1.1    tsarna 		if (!l) {
   1014   1.1    tsarna 			/* if last block */
   1015  1.62   tsutsui 			op->flags = htole32(AUVIA_DMAOP_EOL | blksize);
   1016   1.1    tsarna 		} else {
   1017  1.62   tsutsui 			op->flags = htole32(AUVIA_DMAOP_FLAG | blksize);
   1018   1.1    tsarna 		}
   1019   1.1    tsarna 		s += blksize;
   1020   1.1    tsarna 		op++;
   1021   1.1    tsarna 	}
   1022   1.1    tsarna 
   1023   1.1    tsarna 	return 0;
   1024   1.1    tsarna }
   1025   1.1    tsarna 
   1026   1.1    tsarna 
   1027  1.52   thorpej static int
   1028  1.57  christos auvia_trigger_output(void *addr, void *start, void *end, int blksize,
   1029  1.58  christos     void (*intr)(void *), void *arg, const audio_params_t *param)
   1030   1.1    tsarna {
   1031  1.51      kent 	struct auvia_softc *sc;
   1032  1.51      kent 	struct auvia_softc_chan *ch;
   1033   1.1    tsarna 	struct auvia_dma *p;
   1034   1.1    tsarna 
   1035  1.51      kent 	sc = addr;
   1036  1.51      kent 	ch = &(sc->sc_play);
   1037   1.1    tsarna 	for (p = sc->sc_dmas; p && p->addr != start; p = p->next)
   1038  1.51      kent 		continue;
   1039   1.1    tsarna 
   1040   1.1    tsarna 	if (!p)
   1041   1.1    tsarna 		panic("auvia_trigger_output: request with bad start "
   1042  1.18    provos 			"address (%p)", start);
   1043   1.1    tsarna 
   1044   1.1    tsarna 	if (auvia_build_dma_ops(sc, ch, p, start, end, blksize)) {
   1045   1.1    tsarna 		return 1;
   1046   1.1    tsarna 	}
   1047   1.1    tsarna 
   1048   1.1    tsarna 	ch->sc_intr = intr;
   1049   1.1    tsarna 	ch->sc_arg = arg;
   1050   1.1    tsarna 
   1051  1.27      kent 	CH_WRITE4(sc, ch, AUVIA_RP_DMAOPS_BASE,
   1052   1.1    tsarna 		ch->sc_dma_ops_dma->map->dm_segs[0].ds_addr);
   1053   1.1    tsarna 
   1054  1.22      kent 	if (sc->sc_flags & AUVIA_FLAGS_VT8233) {
   1055  1.27      kent 		if (ch->sc_base != VIA8233_MP_BASE) {
   1056  1.27      kent 			CH_WRITE1(sc, ch, VIA8233_RP_DXS_LVOL, 0);
   1057  1.27      kent 			CH_WRITE1(sc, ch, VIA8233_RP_DXS_RVOL, 0);
   1058  1.27      kent 		}
   1059  1.27      kent 		CH_WRITE1(sc, ch, AUVIA_RP_CONTROL,
   1060  1.22      kent 			AUVIA_RPCTRL_START | AUVIA_RPCTRL_AUTOSTART |
   1061  1.22      kent 			AUVIA_RPCTRL_STOP  | AUVIA_RPCTRL_EOL | AUVIA_RPCTRL_FLAG);
   1062  1.24      kent 	} else {
   1063  1.27      kent 		CH_WRITE1(sc, ch, AUVIA_RP_MODE, ch->sc_reg);
   1064  1.27      kent 		CH_WRITE1(sc, ch, AUVIA_RP_CONTROL, AUVIA_RPCTRL_START);
   1065  1.24      kent 	}
   1066   1.1    tsarna 
   1067   1.1    tsarna 	return 0;
   1068   1.1    tsarna }
   1069   1.1    tsarna 
   1070  1.52   thorpej static int
   1071  1.57  christos auvia_trigger_input(void *addr, void *start, void *end, int blksize,
   1072  1.58  christos     void (*intr)(void *), void *arg, const audio_params_t *param)
   1073   1.1    tsarna {
   1074  1.51      kent 	struct auvia_softc *sc;
   1075  1.51      kent 	struct auvia_softc_chan *ch;
   1076   1.1    tsarna 	struct auvia_dma *p;
   1077   1.1    tsarna 
   1078  1.51      kent 	sc = addr;
   1079  1.51      kent 	ch = &(sc->sc_record);
   1080   1.1    tsarna 	for (p = sc->sc_dmas; p && p->addr != start; p = p->next)
   1081  1.51      kent 		continue;
   1082   1.1    tsarna 
   1083   1.1    tsarna 	if (!p)
   1084   1.1    tsarna 		panic("auvia_trigger_input: request with bad start "
   1085  1.18    provos 			"address (%p)", start);
   1086   1.1    tsarna 
   1087   1.1    tsarna 	if (auvia_build_dma_ops(sc, ch, p, start, end, blksize)) {
   1088   1.1    tsarna 		return 1;
   1089   1.1    tsarna 	}
   1090   1.1    tsarna 
   1091   1.1    tsarna 	ch->sc_intr = intr;
   1092   1.1    tsarna 	ch->sc_arg = arg;
   1093   1.1    tsarna 
   1094  1.27      kent 	CH_WRITE4(sc, ch, AUVIA_RP_DMAOPS_BASE,
   1095  1.27      kent 		  ch->sc_dma_ops_dma->map->dm_segs[0].ds_addr);
   1096   1.1    tsarna 
   1097  1.24      kent 	if (sc->sc_flags & AUVIA_FLAGS_VT8233) {
   1098  1.27      kent 		CH_WRITE1(sc, ch, VIA8233_RP_DXS_LVOL, 0);
   1099  1.27      kent 		CH_WRITE1(sc, ch, VIA8233_RP_DXS_RVOL, 0);
   1100  1.27      kent 		CH_WRITE1(sc, ch, AUVIA_RP_CONTROL,
   1101  1.22      kent 			AUVIA_RPCTRL_START | AUVIA_RPCTRL_AUTOSTART |
   1102  1.22      kent 			AUVIA_RPCTRL_STOP  | AUVIA_RPCTRL_EOL | AUVIA_RPCTRL_FLAG);
   1103  1.24      kent 	} else {
   1104  1.27      kent 		CH_WRITE1(sc, ch, AUVIA_RP_MODE, ch->sc_reg);
   1105  1.27      kent 		CH_WRITE1(sc, ch, AUVIA_RP_CONTROL, AUVIA_RPCTRL_START);
   1106  1.24      kent 	}
   1107   1.1    tsarna 
   1108   1.1    tsarna 	return 0;
   1109   1.1    tsarna }
   1110   1.1    tsarna 
   1111  1.52   thorpej static int
   1112   1.1    tsarna auvia_intr(void *arg)
   1113   1.1    tsarna {
   1114  1.51      kent 	struct auvia_softc *sc;
   1115  1.27      kent 	struct auvia_softc_chan *ch;
   1116   1.1    tsarna 	u_int8_t r;
   1117  1.17      fvdl 	int rval;
   1118  1.17      fvdl 
   1119  1.51      kent 	sc = arg;
   1120  1.17      fvdl 	rval = 0;
   1121   1.1    tsarna 
   1122  1.27      kent 	ch = &sc->sc_record;
   1123  1.27      kent 	r = CH_READ1(sc, ch, AUVIA_RP_STAT);
   1124   1.1    tsarna 	if (r & AUVIA_RPSTAT_INTR) {
   1125   1.2    tsarna 		if (sc->sc_record.sc_intr)
   1126   1.2    tsarna 			sc->sc_record.sc_intr(sc->sc_record.sc_arg);
   1127   1.1    tsarna 
   1128   1.1    tsarna 		/* clear interrupts */
   1129  1.27      kent 		CH_WRITE1(sc, ch, AUVIA_RP_STAT, AUVIA_RPSTAT_INTR);
   1130  1.17      fvdl 		rval = 1;
   1131   1.1    tsarna 	}
   1132  1.22      kent 
   1133  1.27      kent 	ch = &sc->sc_play;
   1134  1.27      kent 	r = CH_READ1(sc, ch, AUVIA_RP_STAT);
   1135   1.1    tsarna 	if (r & AUVIA_RPSTAT_INTR) {
   1136   1.2    tsarna 		if (sc->sc_play.sc_intr)
   1137   1.2    tsarna 			sc->sc_play.sc_intr(sc->sc_play.sc_arg);
   1138   1.1    tsarna 
   1139   1.1    tsarna 		/* clear interrupts */
   1140  1.27      kent 		CH_WRITE1(sc, ch, AUVIA_RP_STAT, AUVIA_RPSTAT_INTR);
   1141  1.17      fvdl 		rval = 1;
   1142   1.1    tsarna 	}
   1143   1.1    tsarna 
   1144  1.17      fvdl 	return rval;
   1145   1.1    tsarna }
   1146  1.43      kent 
   1147  1.61  jmcneill static bool
   1148  1.63    dyoung auvia_resume(device_t dv PMF_FN_ARGS)
   1149  1.43      kent {
   1150  1.61  jmcneill 	struct auvia_softc *sc = device_private(dv);
   1151  1.43      kent 
   1152  1.61  jmcneill 	auvia_reset_codec(sc);
   1153  1.61  jmcneill 	DELAY(1000);
   1154  1.61  jmcneill 	(sc->codec_if->vtbl->restore_ports)(sc->codec_if);
   1155  1.43      kent 
   1156  1.61  jmcneill 	return true;
   1157  1.43      kent }
   1158