Home | History | Annotate | Line # | Download | only in dev
repulse.c revision 1.21
      1  1.21     isaki /*	$NetBSD: repulse.c,v 1.21 2019/03/16 12:09:56 isaki Exp $ */
      2   1.1        is 
      3   1.1        is /*-
      4   1.1        is  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5   1.1        is  * All rights reserved.
      6   1.1        is  *
      7   1.1        is  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1        is  * by Ignatios Souvatzis.
      9   1.1        is  *
     10   1.1        is  * Redistribution and use in source and binary forms, with or without
     11   1.1        is  * modification, are permitted provided that the following conditions
     12   1.1        is  * are met:
     13   1.1        is  * 1. Redistributions of source code must retain the above copyright
     14   1.1        is  *    notice, this list of conditions and the following disclaimer.
     15   1.1        is  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1        is  *    notice, this list of conditions and the following disclaimer in the
     17   1.1        is  *    documentation and/or other materials provided with the distribution.
     18   1.1        is  *
     19   1.1        is  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.1        is  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.1        is  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.1        is  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.1        is  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.1        is  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.1        is  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.1        is  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.1        is  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.1        is  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.1        is  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1        is  */
     31   1.1        is 
     32   1.4   aymeric #include <sys/cdefs.h>
     33  1.21     isaki __KERNEL_RCSID(0, "$NetBSD: repulse.c,v 1.21 2019/03/16 12:09:56 isaki Exp $");
     34   1.1        is 
     35   1.1        is #include <sys/types.h>
     36   1.1        is #include <sys/param.h>
     37   1.1        is #include <sys/systm.h>
     38   1.1        is #include <sys/kernel.h>
     39   1.3   aymeric #include <sys/device.h>
     40   1.1        is #include <sys/fcntl.h>		/* FREAD */
     41  1.17    dyoung #include <sys/bus.h>
     42   1.1        is 
     43   1.1        is #include <sys/audioio.h>
     44   1.1        is #include <dev/audio_if.h>
     45   1.1        is #include <dev/mulaw.h>
     46   1.3   aymeric 
     47   1.1        is #include <dev/ic/ac97reg.h>
     48   1.1        is #include <dev/ic/ac97var.h>
     49   1.1        is 
     50   1.1        is #include <amiga/dev/zbusvar.h>
     51   1.1        is #include <amiga/amiga/isr.h>
     52   1.1        is 
     53   1.1        is #include <amiga/dev/repulse_firmware.h>
     54   1.1        is 
     55   1.1        is #ifndef vu_int8_t
     56  1.13      kent #define vu_int8_t volatile uint8_t
     57   1.1        is #endif
     58   1.1        is #ifndef vu_int16_t
     59  1.13      kent #define vu_int16_t volatile uint16_t
     60   1.1        is #endif
     61   1.1        is #ifndef vu_int32_t
     62  1.13      kent #define vu_int32_t volatile uint32_t
     63   1.1        is #endif
     64   1.1        is 
     65   1.1        is /* ac97 attachment functions */
     66   1.1        is 
     67   1.1        is int repac_attach(void *, struct ac97_codec_if *);
     68  1.13      kent int repac_read(void *, uint8_t, uint16_t *);
     69  1.13      kent int repac_write(void *, uint8_t, uint16_t);
     70   1.9      kent int repac_reset(void *);
     71   1.1        is enum ac97_host_flag repac_flags(void *);
     72   1.1        is 
     73   1.1        is /* audio attachment functions */
     74   1.1        is 
     75   1.1        is void rep_close(void *);
     76   1.1        is int rep_getdev(void *, struct audio_device *);
     77   1.1        is int rep_get_props(void *);
     78   1.1        is int rep_halt_output(void *);
     79   1.1        is int rep_halt_input(void *);
     80   1.1        is int rep_query_encoding(void *, struct audio_encoding *);
     81  1.12      kent int rep_set_params(void *, int, int, audio_params_t *,
     82  1.12      kent     audio_params_t *, stream_filter_list_t *, stream_filter_list_t *);
     83  1.12      kent int rep_round_blocksize(void *, int, int, const audio_params_t *);
     84   1.1        is int rep_set_port(void *, mixer_ctrl_t *);
     85   1.1        is int rep_get_port(void *, mixer_ctrl_t *);
     86   1.1        is int rep_query_devinfo(void *, mixer_devinfo_t *);
     87   1.1        is size_t rep_round_buffersize(void *, int, size_t);
     88  1.18  jmcneill void rep_get_locks(void *, kmutex_t **, kmutex_t **);
     89   1.1        is 
     90   1.1        is int rep_start_input(void *, void *, int, void (*)(void *), void *);
     91   1.1        is int rep_start_output(void *, void *, int, void (*)(void *), void *);
     92   1.1        is 
     93  1.13      kent int rep_intr(void *);
     94   1.1        is 
     95   1.1        is 
     96   1.1        is /* audio attachment */
     97   1.1        is 
     98  1.10      yamt const struct audio_hw_if rep_hw_if = {
     99  1.21     isaki 	.close			= rep_close,
    100  1.21     isaki 	.query_encoding		= rep_query_encoding,
    101  1.21     isaki 	.set_params		= rep_set_params,
    102  1.21     isaki 	.round_blocksize	= rep_round_blocksize,
    103  1.21     isaki 	.start_output		= rep_start_output,
    104  1.21     isaki 	.start_input		= rep_start_input,
    105  1.21     isaki 	.halt_output		= rep_halt_output,
    106  1.21     isaki 	.halt_input		= rep_halt_input,
    107  1.21     isaki 	.getdev			= rep_getdev,
    108  1.21     isaki 	.set_port		= rep_set_port,
    109  1.21     isaki 	.get_port		= rep_get_port,
    110  1.21     isaki 	.query_devinfo		= rep_query_devinfo,
    111  1.21     isaki 	.round_buffersize	= rep_round_buffersize,
    112  1.21     isaki 	.get_props		= rep_get_props,
    113  1.21     isaki 	.get_locks		= rep_get_locks,
    114   1.1        is };
    115   1.1        is 
    116   1.1        is /* hardware registers */
    117   1.1        is 
    118   1.1        is struct repulse_hw {
    119   1.1        is 	vu_int16_t	rhw_status;
    120   1.1        is 	vu_int16_t	rhw_fifostatus;		/* 0xrrrrpppp0000flag */
    121   1.1        is 	vu_int16_t	rhw_reg_address;
    122   1.1        is 	vu_int16_t	rhw_reg_data;
    123   1.1        is /* 0x08 */
    124   1.1        is 	vu_int16_t	rhw_fifo_lh;
    125   1.1        is 	vu_int16_t	rhw_fifo_ll;
    126   1.1        is 	vu_int16_t	rhw_fifo_rh;
    127   1.1        is 	vu_int16_t	rhw_fifo_rl;
    128   1.1        is /* 0x10 */
    129   1.1        is 	vu_int16_t	rhw_fifo_pack;
    130   1.1        is 	vu_int16_t	rhw_play_fifosz;
    131   1.1        is 	vu_int32_t	rhw_spdifin_stat;
    132   1.1        is #define	rhw_spdifout_stat rhw_spdifin_stat;
    133   1.1        is 
    134   1.1        is /* 0x18 */
    135   1.1        is 	vu_int16_t	rhw_capt_fifosz;
    136   1.1        is 	vu_int16_t	rhw_version;
    137   1.1        is 	vu_int16_t	rhw_dummy1;
    138   1.1        is 	vu_int8_t	rhw_firmwareload;
    139   1.1        is /* 0x1F */
    140   1.1        is 	vu_int8_t	rhw_dummy2[66 - 31];
    141   1.1        is /* 0x42 */
    142   1.1        is 	vu_int16_t	rhw_reset;
    143   1.1        is } /* __attribute__((packed)) */;
    144   1.1        is 
    145   1.1        is #define REPSTATUS_PLAY		0x0001
    146   1.1        is #define REPSTATUS_RECORD	0x0002
    147   1.1        is #define REPSTATUS_PLAYFIFORST	0x0004
    148   1.1        is #define REPSTATUS_RECFIFORST	0x0008
    149   1.1        is 
    150   1.1        is #define REPSTATUS_REGSENDBUSY	0x0010
    151   1.1        is #define REPSTATUS_LOOPBACK	0x0020
    152   1.1        is #define REPSTATUS_ENSPDIFIN	0x0040
    153   1.1        is #define REPSTATUS_ENSPDIFOUT	0x0080
    154   1.1        is 
    155   1.1        is #define REPSTATUS_CODECRESET	0x0200
    156   1.1        is #define REPSTATUS_SPDIFOUT24	0x0400
    157   1.1        is #define REPSTATUS_SPDIFIN24	0x0800
    158   1.1        is 
    159   1.1        is #define REPSTATUS_RECIRQENABLE	0x1000
    160   1.1        is #define REPSTATUS_RECIRQACK	0x2000
    161   1.1        is #define REPSTATUS_PLAYIRQENABLE	0x4000
    162   1.1        is #define REPSTATUS_PLAYIRQACK	0x8000
    163   1.1        is 
    164   1.1        is #define REPFIFO_PLAYFIFOFULL	0x0001
    165   1.1        is #define REPFIFO_PLAYFIFOEMPTY	0x0002
    166   1.1        is #define REPFIFO_RECFIFOFULL	0x0004
    167   1.1        is #define REPFIFO_RECFIFOEMPTY	0x0008
    168   1.1        is #define REPFIFO_PLAYFIFOGAUGE(x) ((x << 4) & 0xf000)
    169   1.1        is #define REPFIFO_RECFIFOGAUGE(x)		(x & 0xf000)
    170   1.1        is 
    171   1.1        is /* ac97 data stream transfer functions */
    172  1.13      kent void rep_read_16_stereo(struct repulse_hw *, uint8_t *, int, unsigned);
    173  1.13      kent void rep_read_16_mono(struct repulse_hw *, uint8_t *, int, unsigned);
    174  1.13      kent void rep_write_16_stereo(struct repulse_hw *, uint8_t *, int, unsigned);
    175  1.13      kent void rep_write_16_mono(struct repulse_hw *, uint8_t *, int, unsigned);
    176  1.13      kent void rep_read_8_stereo(struct repulse_hw *, uint8_t *, int, unsigned);
    177  1.13      kent void rep_read_8_mono(struct repulse_hw *, uint8_t *, int, unsigned);
    178  1.13      kent void rep_write_8_stereo(struct repulse_hw *, uint8_t *, int, unsigned);
    179  1.13      kent void rep_write_8_mono(struct repulse_hw *, uint8_t *, int, unsigned);
    180   1.1        is 
    181   1.1        is /* AmigaDOS Delay() ticks */
    182   1.1        is 
    183   1.1        is #define USECPERTICK	(1000000/50)
    184   1.1        is 
    185   1.1        is /* NetBSD device attachment */
    186   1.1        is 
    187   1.1        is struct repulse_softc {
    188  1.19       chs 	device_t		sc_dev;
    189   1.1        is 	struct isr		sc_isr;
    190   1.1        is 	struct ac97_host_if	sc_achost;
    191   1.1        is 	struct ac97_codec_if	*sc_codec_if;
    192   1.1        is 
    193   1.1        is 	struct repulse_hw	*sc_boardp;
    194   1.1        is 
    195   1.1        is 	void	(*sc_captmore)(void *);
    196   1.1        is 	void	 *sc_captarg;
    197   1.1        is 
    198  1.13      kent 	void	(*sc_captfun)(struct repulse_hw *, uint8_t *, int, unsigned);
    199   1.1        is 	void	 *sc_captbuf;
    200   1.1        is 	int	  sc_captscale;
    201   1.1        is 	int	  sc_captbufsz;
    202   1.1        is 	unsigned  sc_captflags;
    203   1.1        is 
    204   1.1        is 
    205   1.1        is 	void	(*sc_playmore)(void *);
    206   1.1        is 	void	 *sc_playarg;
    207  1.13      kent 	void	(*sc_playfun)(struct repulse_hw *, uint8_t *, int, unsigned);
    208   1.1        is 	int	  sc_playscale;
    209   1.1        is 	unsigned  sc_playflags;
    210   1.1        is 
    211  1.18  jmcneill 	kmutex_t  sc_lock;
    212  1.18  jmcneill 	kmutex_t  sc_intr_lock;
    213   1.1        is };
    214   1.1        is 
    215  1.19       chs int repulse_match (device_t, cfdata_t, void *);
    216  1.19       chs void repulse_attach (device_t, device_t, void *);
    217   1.1        is 
    218  1.19       chs CFATTACH_DECL_NEW(repulse, sizeof(struct repulse_softc),
    219   1.6   thorpej     repulse_match, repulse_attach, NULL, NULL);
    220   1.1        is 
    221   1.1        is int
    222  1.19       chs repulse_match(device_t parent, cfdata_t cf, void *aux)
    223  1.13      kent {
    224   1.1        is 	struct zbus_args *zap;
    225   1.1        is 
    226   1.1        is 	zap = aux;
    227   1.1        is 
    228   1.1        is 	if (zap->manid != 0x4144)
    229   1.1        is 		return (0);
    230   1.1        is 
    231   1.1        is 	if (zap->prodid != 0)
    232   1.1        is 		return (0);
    233   1.1        is 
    234   1.1        is 	return (1);
    235   1.1        is }
    236   1.1        is 
    237   1.1        is void
    238  1.19       chs repulse_attach(device_t parent, device_t self, void *aux)
    239  1.13      kent {
    240   1.1        is 	struct repulse_softc *sc;
    241   1.1        is 	struct zbus_args *zap;
    242   1.1        is 	struct repulse_hw *bp;
    243  1.14       jmc 	const uint8_t *fwp;
    244   1.1        is 	int needs_firmware;
    245  1.13      kent 	uint16_t a;
    246   1.1        is 
    247  1.19       chs 	sc = device_private(self);
    248  1.19       chs 	sc->sc_dev = self;
    249   1.1        is 	zap = aux;
    250   1.1        is 	bp = (struct repulse_hw *)zap->va;
    251   1.1        is 	sc->sc_boardp = bp;
    252   1.1        is 
    253   1.1        is 	needs_firmware = 0;
    254   1.1        is 	if (bp->rhw_fifostatus & 0x00f0)
    255   1.1        is 		needs_firmware = 1;
    256   1.1        is 	else {
    257   1.1        is 		bp->rhw_status = 0x000c;
    258   1.1        is 		if (bp->rhw_status != 0 || bp->rhw_fifostatus != 0x0f0a)
    259   1.1        is 			needs_firmware = 1;
    260   1.1        is 	}
    261   1.1        is 
    262   1.1        is 	printf(": ");
    263   1.1        is 	if (needs_firmware) {
    264   1.1        is 		printf("loading ");
    265   1.1        is 		bp->rhw_reset = 0;
    266   1.1        is 
    267   1.1        is 		delay(1 * USECPERTICK);
    268   1.3   aymeric 
    269  1.14       jmc 		for (fwp = (const uint8_t *)repulse_firmware;
    270   1.1        is 		    fwp < (repulse_firmware_size +
    271  1.14       jmc 		    (const uint8_t *)repulse_firmware); fwp++)
    272   1.1        is 			bp->rhw_firmwareload = *fwp;
    273   1.1        is 
    274   1.1        is 		delay(1 * USECPERTICK);
    275   1.1        is 
    276   1.1        is 		if (bp->rhw_fifostatus & 0x00f0)
    277   1.1        is 			goto Initerr;
    278   1.1        is 
    279   1.1        is 		a = /* bp->rhw_status;
    280   1.1        is 		a |= */ REPSTATUS_CODECRESET;
    281   1.1        is 		bp->rhw_status = a;
    282   1.1        is 
    283   1.1        is 		a = bp->rhw_status;
    284   1.1        is 		if ((a & REPSTATUS_CODECRESET) == 0)
    285   1.1        is 			goto Initerr;
    286   1.1        is 
    287   1.1        is 		(void)bp->rhw_status;
    288   1.1        is 		(void)bp->rhw_status;
    289   1.1        is 		(void)bp->rhw_status;
    290   1.1        is 		a = bp->rhw_status;
    291   1.1        is 		a &= ~REPSTATUS_CODECRESET;
    292   1.1        is 		bp->rhw_status = a;
    293   1.1        is 	}
    294   1.1        is 
    295   1.1        is 	printf("firmware version 0x%x\n", bp->rhw_version);
    296   1.1        is 
    297   1.1        is 	sc->sc_achost.arg = sc;
    298   1.1        is 
    299   1.1        is 	sc->sc_achost.reset = repac_reset;
    300   1.1        is 	sc->sc_achost.read = repac_read;
    301   1.1        is 	sc->sc_achost.write = repac_write;
    302   1.1        is 	sc->sc_achost.attach = repac_attach;
    303   1.1        is 	sc->sc_achost.flags = 0;
    304   1.1        is 
    305  1.18  jmcneill 	mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
    306  1.18  jmcneill 	mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_SCHED);
    307  1.18  jmcneill 
    308  1.18  jmcneill 	if (ac97_attach(&sc->sc_achost, self, &sc->sc_lock)) {
    309  1.19       chs 		printf("%s: error attaching codec\n", device_xname(self));
    310   1.1        is 		return;
    311   1.1        is 	}
    312   1.1        is 
    313   1.1        is #ifdef DIAGNOSTIC
    314   1.3   aymeric 	/*
    315   1.1        is 	 * Print a warning if the codec doesn't support hardware variable
    316   1.1        is 	 * rate audio. As the initial incarnations of the Repulse board
    317   1.1        is 	 * are AC'97 2.1, it is epxected that we'll always have VRA.
    318   1.1        is 	 */
    319   1.1        is 	/*
    320   1.1        is 	 * XXX this should be a panic(). OTOH, audio codec speed is not
    321   1.1        is 	 * important enough to do this.
    322   1.1        is 	 */
    323   1.7      kent 	a = sc->sc_codec_if->vtbl->get_extcaps(sc->sc_codec_if);
    324   1.7      kent 	if (!(a & AC97_EXT_AUDIO_VRA)) {
    325   1.1        is 		printf("%s: warning: codec doesn't support "
    326   1.1        is 		    "hardware AC'97 2.0 Variable Rate Audio\n",
    327  1.19       chs 			device_xname(self));
    328   1.1        is 	}
    329   1.1        is #endif
    330   1.1        is 
    331   1.1        is 	sc->sc_isr.isr_ipl = 2;
    332   1.1        is 	sc->sc_isr.isr_arg = sc;
    333   1.1        is 	sc->sc_isr.isr_intr = rep_intr;
    334   1.1        is 	add_isr(&sc->sc_isr);
    335   1.1        is 
    336  1.19       chs 	audio_attach_mi(&rep_hw_if, sc, self);
    337   1.1        is 
    338   1.1        is 	return;
    339   1.1        is 
    340   1.1        is Initerr:
    341  1.19       chs 	printf("\n%s: firmware not successfully loaded\n", device_xname(self));
    342   1.1        is 	return;
    343   1.3   aymeric 
    344   1.1        is }
    345   1.1        is 
    346  1.13      kent int
    347  1.13      kent repac_reset(void *arg)
    348  1.13      kent {
    349  1.13      kent 	struct repulse_softc *sc;
    350  1.13      kent 	struct repulse_hw *bp;
    351  1.13      kent 	uint16_t a;
    352   1.3   aymeric 
    353  1.13      kent 	sc = arg;
    354  1.13      kent 	bp = sc->sc_boardp;
    355   1.1        is 	a = bp->rhw_status;
    356   1.1        is 	a |= REPSTATUS_CODECRESET;
    357   1.1        is 	bp->rhw_status = a;
    358   1.1        is 
    359   1.1        is 	a = bp->rhw_status;
    360   1.1        is #ifdef DIAGNOSTIC
    361   1.1        is 	if ((a & REPSTATUS_CODECRESET) == 0)
    362  1.19       chs 		panic("%s: cannot set reset bit", device_xname(sc->sc_dev));
    363   1.1        is #endif
    364   1.1        is 
    365   1.1        is 	a = bp->rhw_status;
    366   1.1        is 	a = bp->rhw_status;
    367   1.1        is 	a = bp->rhw_status;
    368   1.1        is 	a = bp->rhw_status;
    369   1.1        is 	a &= ~REPSTATUS_CODECRESET;
    370   1.1        is 	bp->rhw_status = a;
    371   1.9      kent 	return 0;
    372   1.1        is }
    373   1.1        is 
    374  1.13      kent int
    375  1.13      kent repac_read(void *arg, u_int8_t reg, u_int16_t *valuep)
    376  1.13      kent {
    377  1.13      kent 	struct repulse_softc *sc;
    378  1.13      kent 	struct repulse_hw *bp;
    379   1.1        is 
    380  1.13      kent 	sc = arg;
    381  1.13      kent 	bp = sc->sc_boardp;
    382  1.13      kent 	while (bp->rhw_status & REPSTATUS_REGSENDBUSY)
    383  1.13      kent 		continue;
    384   1.1        is 	bp->rhw_reg_address = (reg & 0x7F) | 0x80;
    385   1.1        is 
    386  1.13      kent 	while (bp->rhw_status & REPSTATUS_REGSENDBUSY)
    387  1.13      kent 		continue;
    388   1.1        is 
    389   1.1        is 	*valuep = bp->rhw_reg_data;
    390   1.1        is 
    391   1.1        is 	return 0;
    392   1.1        is }
    393   1.1        is 
    394  1.13      kent int
    395  1.13      kent repac_write(void *arg, uint8_t reg, uint16_t value)
    396  1.13      kent {
    397  1.13      kent 	struct repulse_softc *sc;
    398  1.13      kent 	struct repulse_hw *bp;
    399   1.1        is 
    400  1.13      kent 	sc = arg;
    401  1.13      kent 	bp = sc->sc_boardp;
    402   1.1        is 	bp->rhw_reg_data = value;
    403   1.1        is 	bp->rhw_reg_address = reg & 0x7F;
    404   1.1        is 
    405  1.13      kent 	while (bp->rhw_status & REPSTATUS_REGSENDBUSY)
    406  1.13      kent 		continue;
    407   1.1        is 
    408   1.1        is 	return 0;
    409   1.1        is }
    410   1.1        is 
    411  1.13      kent int
    412  1.13      kent repac_attach(void *arg, struct ac97_codec_if *acip)
    413  1.13      kent {
    414   1.1        is 	struct repulse_softc *sc;
    415   1.1        is 
    416   1.1        is 	sc = arg;
    417   1.1        is 	sc->sc_codec_if = acip;
    418   1.1        is 
    419   1.1        is 	return 0;
    420   1.1        is }
    421   1.1        is 
    422   1.1        is /* audio(9) support stuff which is not ac97-constant */
    423   1.1        is 
    424   1.1        is void
    425   1.1        is rep_close(void *arg)
    426   1.1        is {
    427  1.13      kent 	struct repulse_softc *sc;
    428   1.1        is 
    429  1.13      kent 	sc = arg;
    430   1.1        is 	rep_halt_output(sc);
    431   1.1        is 	rep_halt_input(sc);
    432   1.1        is }
    433   1.1        is 
    434   1.1        is int
    435   1.1        is rep_getdev(void *arg, struct audio_device *retp)
    436   1.1        is {
    437  1.13      kent 	struct repulse_softc *sc;
    438  1.13      kent 	struct repulse_hw *bp;
    439   1.1        is 
    440  1.13      kent 	if (retp != NULL) {
    441  1.13      kent 		sc = arg;
    442  1.13      kent 		bp = sc->sc_boardp;
    443   1.1        is 		strncpy(retp->name, "Repulse", sizeof(retp->name));
    444   1.1        is 		snprintf(retp->version, sizeof(retp->version), "0x%x",
    445   1.1        is 			bp->rhw_version);
    446   1.1        is 		strncpy(retp->config, "", sizeof(retp->config));
    447   1.1        is 	}
    448   1.1        is 
    449   1.1        is 	return 0;
    450   1.1        is }
    451   1.1        is 
    452   1.3   aymeric int
    453   1.1        is rep_get_props(void *v)
    454   1.1        is {
    455  1.13      kent 	return AUDIO_PROP_INDEPENDENT | AUDIO_PROP_FULLDUPLEX;
    456   1.3   aymeric }
    457   1.1        is 
    458   1.1        is int
    459   1.1        is rep_halt_output(void *arg)
    460   1.1        is {
    461  1.13      kent 	struct repulse_softc *sc;
    462  1.13      kent 	struct repulse_hw *bp;
    463   1.1        is 
    464  1.13      kent 	sc = arg;
    465  1.13      kent 	bp = sc->sc_boardp;
    466   1.1        is 	bp->rhw_status &= ~(REPSTATUS_PLAYIRQENABLE|REPSTATUS_PLAY);
    467   1.1        is 
    468   1.1        is 
    469   1.1        is 	return 0;
    470   1.1        is }
    471   1.1        is 
    472   1.1        is int
    473   1.1        is rep_halt_input(void *arg)
    474   1.1        is {
    475  1.13      kent 	struct repulse_softc *sc;
    476  1.13      kent 	struct repulse_hw *bp;
    477   1.1        is 
    478  1.13      kent 	sc = arg;
    479  1.13      kent 	bp = sc->sc_boardp;
    480   1.1        is 	bp->rhw_status &= ~(REPSTATUS_RECIRQENABLE|REPSTATUS_RECORD);
    481   1.1        is 
    482   1.1        is 	return 0;
    483   1.1        is }
    484   1.1        is 
    485   1.1        is /*
    486   1.1        is  * Encoding support.
    487   1.1        is  *
    488   1.1        is  * TODO: add 24bit and 32bit modes here and in setparams.
    489   1.1        is  */
    490   1.1        is 
    491   1.1        is const struct repulse_encoding_query {
    492   1.1        is 	const char *name;
    493   1.1        is 	int encoding, precision, flags;
    494   1.1        is } rep_encoding_queries[] = {
    495   1.1        is 	{ AudioEulinear, AUDIO_ENCODING_ULINEAR, 8, 0},
    496   1.1        is 	{ AudioEmulaw,	AUDIO_ENCODING_ULAW, 8, AUDIO_ENCODINGFLAG_EMULATED},
    497   1.1        is 	{ AudioEalaw,	AUDIO_ENCODING_ALAW, 8, AUDIO_ENCODINGFLAG_EMULATED},
    498   1.1        is 	{ AudioEslinear, AUDIO_ENCODING_SLINEAR, 8, 0},
    499   1.1        is 	{ AudioEslinear_le, AUDIO_ENCODING_SLINEAR_LE, 16, 0},
    500   1.1        is 	{ AudioEulinear_le, AUDIO_ENCODING_ULINEAR_LE, 16, 0},
    501   1.1        is 	{ AudioEulinear_be, AUDIO_ENCODING_ULINEAR_BE, 16, 0},
    502   1.1        is 	{ AudioEslinear_be, AUDIO_ENCODING_SLINEAR_BE, 16, 0},
    503   1.1        is };
    504   1.1        is 
    505   1.1        is int
    506   1.1        is rep_query_encoding(void *arg, struct audio_encoding *fp)
    507   1.1        is {
    508   1.1        is 	int i;
    509   1.1        is 	const struct repulse_encoding_query *p;
    510   1.1        is 
    511   1.1        is 	i = fp->index;
    512   1.1        is 
    513   1.1        is 	if (i >= sizeof(rep_encoding_queries) /
    514   1.1        is 	    sizeof(struct repulse_encoding_query))
    515  1.13      kent 		return EINVAL;
    516   1.1        is 
    517   1.1        is 	p = &rep_encoding_queries[i];
    518   1.1        is 
    519   1.1        is 	strncpy (fp->name, p->name, sizeof(fp->name));
    520   1.1        is 	fp->encoding = p->encoding;
    521   1.1        is 	fp->precision = p->precision;
    522   1.1        is 	fp->flags = p->flags;
    523   1.1        is 
    524  1.13      kent 	return 0;
    525   1.1        is }
    526   1.1        is 
    527   1.1        is /*
    528   1.1        is  * XXX the following three functions need to be enhanced for the FPGA s/pdif
    529   1.1        is  * mode. Generic ac97 versions for now.
    530   1.1        is  */
    531   1.1        is 
    532   1.3   aymeric int
    533   1.1        is rep_get_port(void *arg, mixer_ctrl_t *cp)
    534   1.1        is {
    535  1.13      kent 	struct repulse_softc *sc;
    536   1.1        is 
    537  1.13      kent 	sc = arg;
    538  1.13      kent 	return sc->sc_codec_if->vtbl->mixer_get_port(sc->sc_codec_if, cp);
    539   1.1        is }
    540   1.1        is 
    541   1.3   aymeric int
    542   1.1        is rep_set_port(void *arg, mixer_ctrl_t *cp)
    543   1.1        is {
    544  1.13      kent 	struct repulse_softc *sc;
    545   1.1        is 
    546  1.13      kent 	sc = arg;
    547  1.13      kent 	return sc->sc_codec_if->vtbl->mixer_set_port(sc->sc_codec_if, cp);
    548   1.1        is }
    549   1.1        is 
    550   1.1        is int
    551  1.13      kent rep_query_devinfo(void *arg, mixer_devinfo_t *dip)
    552   1.1        is {
    553  1.13      kent 	struct repulse_softc *sc;
    554   1.1        is 
    555  1.13      kent 	sc = arg;
    556  1.13      kent 	return sc->sc_codec_if->vtbl->query_devinfo(sc->sc_codec_if, dip);
    557   1.1        is }
    558   1.1        is 
    559   1.1        is int
    560  1.12      kent rep_round_blocksize(void *arg, int blk, int mode, const audio_params_t *param)
    561   1.1        is {
    562   1.1        is 	int b1;
    563   1.1        is 
    564   1.1        is 	b1 = (blk & -32);
    565   1.1        is 
    566   1.1        is 	if (b1 > 65536 / 2 / 2 /* channels */ / 4 /* bytes per channel */)
    567   1.1        is 		b1 =  65536 / 2 / 2 / 4;
    568  1.13      kent 	return b1;
    569   1.1        is }
    570   1.1        is 
    571   1.3   aymeric size_t
    572   1.1        is rep_round_buffersize(void *arg, int direction, size_t size)
    573   1.1        is {
    574   1.1        is 	return size;
    575   1.1        is }
    576   1.1        is 
    577  1.18  jmcneill void
    578  1.18  jmcneill rep_get_locks(void *opaque, kmutex_t **intr, kmutex_t **thread)
    579  1.18  jmcneill {
    580  1.18  jmcneill 	struct repulse_softc *sc = opaque;
    581  1.18  jmcneill 
    582  1.18  jmcneill 	*intr = &sc->sc_intr_lock;
    583  1.18  jmcneill 	*thread = &sc->sc_lock;
    584  1.18  jmcneill }
    585  1.18  jmcneill 
    586   1.1        is 
    587   1.1        is int
    588   1.1        is rep_set_params(void *addr, int setmode, int usemode,
    589  1.12      kent 	audio_params_t *play, audio_params_t *rec,
    590  1.12      kent 	stream_filter_list_t *pfil, stream_filter_list_t *rfil)
    591   1.1        is {
    592  1.12      kent 	audio_params_t hw;
    593  1.13      kent 	struct repulse_softc *sc;
    594  1.12      kent 	audio_params_t *p;
    595   1.1        is 	int mode, reg;
    596   1.1        is 	unsigned  flags;
    597   1.1        is 	u_int16_t a;
    598   1.1        is 
    599  1.13      kent 	sc = addr;
    600   1.1        is 	/* for mode in (RECORD, PLAY) */
    601   1.1        is 	for (mode = AUMODE_RECORD; mode != -1;
    602   1.1        is 	    mode = mode == AUMODE_RECORD ? AUMODE_PLAY : -1) {
    603   1.1        is 
    604   1.1        is 		if ((setmode & mode) == 0)
    605   1.1        is 		     continue;
    606   1.1        is 
    607   1.1        is 		p = mode == AUMODE_PLAY ? play : rec;
    608   1.1        is 
    609   1.1        is 		/* TODO XXX we can do upto 32bit, 96000 */
    610   1.1        is 		if (p->sample_rate < 4000 || p->sample_rate > 48000 ||
    611   1.1        is 		    (p->precision != 8 && p->precision != 16) ||
    612   1.1        is 		    (p->channels != 1 && p->channels != 2))
    613  1.13      kent 			return EINVAL;
    614   1.1        is 
    615   1.1        is 		reg = mode == AUMODE_PLAY ?
    616   1.1        is 			AC97_REG_PCM_FRONT_DAC_RATE : AC97_REG_PCM_LR_ADC_RATE;
    617   1.1        is 
    618  1.13      kent 		repac_write(sc, reg, (uint16_t) p->sample_rate);
    619   1.1        is 		repac_read(sc, reg, &a);
    620   1.1        is 		p->sample_rate = a;
    621   1.1        is 
    622   1.1        is 		if (mode == AUMODE_PLAY)
    623   1.1        is 			sc->sc_playscale = p->channels * p->precision / 8;
    624   1.1        is 		else
    625   1.1        is 			sc->sc_captscale = p->channels * p->precision / 8;
    626   1.1        is 
    627  1.12      kent 		hw = *p;
    628   1.1        is 
    629   1.1        is 		/* everything else is software, alas... */
    630   1.1        is 		/* XXX TBD signed/unsigned, *law, etc */
    631   1.1        is 
    632   1.1        is 		flags = 0;
    633   1.1        is 		if (p->encoding == AUDIO_ENCODING_ULINEAR_LE ||
    634   1.1        is 		    p->encoding == AUDIO_ENCODING_ULINEAR_BE ||
    635   1.1        is 		    p->encoding == AUDIO_ENCODING_ULINEAR)
    636   1.1        is 			flags |= 1;
    637   1.1        is 
    638   1.1        is 		if (p->encoding == AUDIO_ENCODING_SLINEAR_LE ||
    639   1.1        is 		    p->encoding == AUDIO_ENCODING_ULINEAR_LE)
    640   1.1        is 			flags |= 2;
    641   1.1        is 
    642   1.1        is 		if (mode == AUMODE_PLAY) {
    643   1.1        is 			sc->sc_playflags = flags;
    644   1.1        is 			if (p->encoding == AUDIO_ENCODING_ULAW) {
    645   1.1        is 				sc->sc_playfun = p->channels == 1 ?
    646   1.1        is 					rep_write_16_mono :
    647   1.1        is 					rep_write_16_stereo;
    648   1.1        is 				sc->sc_playflags = 0;
    649   1.1        is 				sc->sc_playscale = p->channels * 2;
    650  1.12      kent 				hw.encoding = AUDIO_ENCODING_SLINEAR_BE;
    651  1.12      kent 				hw.precision = hw.validbits = 16;
    652  1.12      kent 				pfil->append(pfil, mulaw_to_linear16, &hw);
    653   1.1        is 			} else
    654   1.1        is 			if (p->encoding == AUDIO_ENCODING_ALAW) {
    655   1.1        is 				sc->sc_playfun = p->channels == 1 ?
    656   1.1        is 					rep_write_16_mono :
    657   1.1        is 					rep_write_16_stereo;
    658   1.1        is 				sc->sc_playflags = 0;
    659   1.1        is 				sc->sc_playscale = p->channels * 2;
    660  1.12      kent 				hw.encoding = AUDIO_ENCODING_SLINEAR_BE;
    661  1.12      kent 				hw.precision = hw.validbits = 16;
    662  1.12      kent 				pfil->append(pfil, alaw_to_linear16, &hw);
    663   1.1        is 			} else
    664   1.1        is 			if (p->precision == 8 && p->channels == 1)
    665   1.1        is 				sc->sc_playfun = rep_write_8_mono;
    666   1.1        is 			else if (p->precision == 8 && p->channels == 2)
    667   1.1        is 				sc->sc_playfun = rep_write_8_stereo;
    668   1.1        is 			else if (p->precision == 16 && p->channels == 1)
    669   1.1        is 				sc->sc_playfun = rep_write_16_mono;
    670   1.1        is 			else if (p->precision == 16 && p->channels == 2)
    671   1.1        is 				sc->sc_playfun = rep_write_16_stereo;
    672   1.1        is 		} else {
    673   1.1        is 			sc->sc_captflags = flags;
    674   1.1        is 			if (p->encoding == AUDIO_ENCODING_ULAW) {
    675   1.1        is 				sc->sc_captfun = p->channels == 1 ?
    676   1.1        is 					rep_read_8_mono :
    677   1.1        is 					rep_read_8_stereo;
    678   1.1        is 				sc->sc_captflags = 0;
    679  1.12      kent 				hw.encoding = AUDIO_ENCODING_SLINEAR_LE;
    680  1.12      kent 				rfil->append(rfil, linear8_to_mulaw, &hw);
    681   1.1        is 			} else
    682   1.1        is 			if (p->encoding == AUDIO_ENCODING_ALAW) {
    683   1.1        is 				sc->sc_captfun = p->channels == 1 ?
    684   1.1        is 					rep_read_8_mono :
    685   1.1        is 					rep_read_8_stereo;
    686   1.1        is 				sc->sc_captflags = 0;
    687  1.12      kent 				rfil->append(rfil, linear8_to_alaw, &hw);
    688   1.1        is 			} else
    689   1.1        is 			if (p->precision == 8 && p->channels == 1)
    690   1.1        is 				sc->sc_captfun = rep_read_8_mono;
    691   1.1        is 			else if (p->precision == 8 && p->channels == 2)
    692   1.1        is 				sc->sc_captfun = rep_read_8_stereo;
    693   1.1        is 			else if (p->precision == 16 && p->channels == 1)
    694   1.1        is 				sc->sc_captfun = rep_read_16_mono;
    695   1.1        is 			else if (p->precision == 16 && p->channels == 2)
    696   1.1        is 				sc->sc_captfun = rep_read_16_stereo;
    697   1.1        is 		}
    698   1.8       wiz 		/* TBD: mu-law, A-law */
    699   1.1        is 	}
    700   1.3   aymeric 	return 0;
    701   1.1        is }
    702   1.1        is 
    703   1.1        is void
    704  1.13      kent rep_write_8_mono(struct repulse_hw *bp, uint8_t *p, int length, unsigned flags)
    705   1.1        is {
    706  1.13      kent 	uint16_t sample;
    707  1.13      kent 	uint16_t xor;
    708   1.1        is 
    709   1.1        is 	xor = flags & 1 ? 0x8000 : 0;
    710   1.1        is 
    711   1.1        is 	bp->rhw_fifo_pack = 0;
    712   1.1        is 
    713   1.1        is 	while (length-- > 0) {
    714   1.1        is 		sample = ((*p++) << 8) ^ xor;
    715   1.1        is 		bp->rhw_fifo_lh = sample;
    716   1.1        is 		bp->rhw_fifo_rh = sample;
    717   1.1        is 	}
    718   1.1        is }
    719   1.1        is 
    720   1.1        is void
    721  1.13      kent rep_write_8_stereo(struct repulse_hw *bp, uint8_t *p, int length,
    722   1.1        is 	unsigned flags)
    723   1.1        is {
    724  1.13      kent 	uint16_t xor;
    725   1.1        is 
    726   1.1        is 	xor = flags & 1 ? 0x8000 : 0;
    727   1.1        is 
    728   1.1        is 	bp->rhw_fifo_pack = 0;
    729   1.1        is 
    730   1.1        is 	while (length-- > 0) {
    731   1.1        is 		bp->rhw_fifo_lh = ((*p++) << 8) ^ xor;
    732   1.1        is 		bp->rhw_fifo_rh = ((*p++) << 8) ^ xor;
    733   1.1        is 	}
    734   1.1        is }
    735   1.1        is 
    736   1.1        is void
    737  1.13      kent rep_write_16_mono(struct repulse_hw *bp, uint8_t *p, int length,
    738   1.1        is 	unsigned flags)
    739   1.1        is {
    740  1.13      kent 	uint16_t *q;
    741  1.13      kent 	uint16_t sample;
    742  1.13      kent 	uint16_t xor;
    743   1.1        is 
    744  1.13      kent 	q = (uint16_t *)p;
    745   1.1        is 	xor = flags & 1 ? 0x8000 : 0;
    746   1.1        is 
    747   1.1        is 	bp->rhw_fifo_pack = 0;
    748   1.1        is 
    749   1.1        is 	if (flags & 2) {
    750   1.1        is 		while (length > 0) {
    751   1.1        is 			sample = bswap16(*q++) ^ xor;
    752   1.1        is 			bp->rhw_fifo_lh = sample;
    753   1.1        is 			bp->rhw_fifo_rh = sample;
    754   1.1        is 			length -= 2;
    755   1.1        is 		}
    756   1.1        is 		return;
    757   1.1        is 	}
    758   1.1        is 
    759   1.1        is 	while (length > 0) {
    760   1.1        is 		sample = (*q++) ^ xor;
    761   1.1        is 		bp->rhw_fifo_lh = sample;
    762   1.1        is 		bp->rhw_fifo_rh = sample;
    763   1.1        is 		length -= 2;
    764   1.1        is 	}
    765   1.1        is }
    766   1.1        is 
    767   1.1        is void
    768  1.13      kent rep_write_16_stereo(struct repulse_hw *bp, uint8_t *p, int length,
    769   1.1        is 	unsigned flags)
    770   1.1        is {
    771  1.13      kent 	uint16_t *q;
    772  1.13      kent 	uint16_t xor;
    773   1.1        is 
    774  1.13      kent 	q = (uint16_t *)p;
    775   1.1        is 	xor = flags & 1 ? 0x8000 : 0;
    776   1.1        is 
    777   1.1        is 	bp->rhw_fifo_pack = 0;
    778   1.1        is 
    779   1.1        is 	if (flags & 2) {
    780   1.1        is 		while (length > 0) {
    781   1.1        is 			bp->rhw_fifo_lh = bswap16(*q++) ^ xor;
    782   1.1        is 			bp->rhw_fifo_rh = bswap16(*q++) ^ xor;
    783   1.1        is 			length -= 4;
    784   1.1        is 		}
    785   1.1        is 		return;
    786   1.1        is 	}
    787   1.1        is 	while (length > 0) {
    788   1.1        is 		bp->rhw_fifo_lh = (*q++) ^ xor;
    789   1.1        is 		bp->rhw_fifo_rh = (*q++) ^ xor;
    790   1.1        is 		length -= 4;
    791   1.1        is 	}
    792   1.1        is }
    793   1.1        is 
    794   1.1        is void
    795  1.13      kent rep_read_8_mono(struct repulse_hw *bp, uint8_t *p, int length, unsigned flags)
    796   1.1        is {
    797  1.20  christos 	uint16_t v, xor;
    798   1.1        is 
    799   1.1        is 	xor = flags & 1 ? 0x8000 : 0;
    800   1.1        is 
    801   1.1        is 	while (length > 0) {
    802   1.1        is 		*p++ = (bp->rhw_fifo_lh ^ xor) >> 8;
    803   1.1        is 		v    = bp->rhw_fifo_rh;
    804  1.20  christos 		__USE(v);
    805   1.1        is 		length--;
    806   1.1        is 	}
    807   1.1        is }
    808   1.1        is 
    809   1.1        is void
    810  1.13      kent rep_read_16_mono(struct	repulse_hw *bp, uint8_t *p, int length, unsigned flags)
    811   1.1        is {
    812  1.13      kent 	uint16_t *q;
    813  1.13      kent 	uint16_t v;
    814  1.13      kent 	uint16_t xor;
    815   1.1        is 
    816  1.13      kent 	q = (uint16_t *)p;
    817   1.1        is 	xor = flags & 1 ? 0x8000 : 0;
    818   1.1        is 
    819   1.1        is 	if (flags & 2) {
    820   1.1        is 		while (length > 0) {
    821   1.1        is 			*q++ = bswap16(bp->rhw_fifo_lh ^ xor);
    822   1.1        is 			v    = bp->rhw_fifo_rh;
    823  1.20  christos 			__USE(v);
    824   1.1        is 			length -= 2;
    825   1.1        is 		}
    826   1.1        is 		return;
    827   1.1        is 	}
    828   1.1        is 
    829   1.1        is 	while (length > 0) {
    830   1.1        is 		*q++ = bp->rhw_fifo_lh ^ xor;
    831   1.1        is 		v    = bp->rhw_fifo_rh;
    832   1.1        is 		length -= 2;
    833   1.1        is 	}
    834   1.1        is }
    835   1.1        is 
    836   1.1        is void
    837  1.13      kent rep_read_8_stereo(struct repulse_hw *bp, uint8_t *p, int length,
    838   1.1        is 	unsigned flags)
    839   1.1        is {
    840  1.13      kent 	uint16_t xor;
    841   1.1        is 
    842   1.1        is 	xor = flags & 1 ? 0x8000 : 0;
    843   1.1        is 	while (length > 0) {
    844   1.1        is 		*p++ = (bp->rhw_fifo_lh ^ xor) >> 8;
    845   1.1        is 		*p++ = (bp->rhw_fifo_rh ^ xor) >> 8;
    846   1.1        is 		length -= 2;
    847   1.1        is 	}
    848   1.1        is }
    849   1.1        is 
    850   1.1        is void
    851  1.13      kent rep_read_16_stereo(struct repulse_hw *bp, uint8_t *p, int length,
    852   1.1        is 	unsigned flags)
    853   1.1        is {
    854  1.13      kent 	uint16_t *q;
    855  1.13      kent 	uint16_t xor;
    856   1.1        is 
    857  1.13      kent 	q = (uint16_t *)p;
    858   1.1        is 	xor = flags & 1 ? 0x8000 : 0;
    859   1.1        is 
    860   1.1        is 	if (flags & 2) {
    861   1.1        is 		while (length > 0) {
    862   1.1        is 			*q++ = bswap16(bp->rhw_fifo_lh ^ xor);
    863   1.1        is 			*q++ = bswap16(bp->rhw_fifo_rh ^ xor);
    864   1.1        is 			length -= 4;
    865   1.1        is 		}
    866   1.1        is 		return;
    867   1.1        is 	}
    868   1.1        is 	while (length > 0) {
    869   1.1        is 		*q++ = bp->rhw_fifo_lh ^ xor;
    870   1.1        is 		*q++ = bp->rhw_fifo_rh ^ xor;
    871   1.1        is 		length -= 4;
    872   1.1        is 	}
    873   1.1        is }
    874   1.1        is 
    875   1.1        is /*
    876   1.1        is  * At this point the transfer function is set.
    877   1.1        is  */
    878   1.1        is 
    879   1.1        is int
    880   1.1        is rep_start_output(void *addr, void *block, int blksize,
    881  1.13      kent 	void (*intr)(void*), void *intrarg)
    882  1.13      kent {
    883   1.1        is 	struct repulse_softc *sc;
    884  1.13      kent 	uint8_t *buf;
    885   1.1        is 	struct repulse_hw *bp;
    886  1.13      kent 	uint16_t status;
    887   1.1        is 
    888   1.1        is 
    889   1.1        is 	sc = addr;
    890   1.1        is 	bp = sc->sc_boardp;
    891   1.1        is 	buf = block;
    892   1.1        is 
    893   1.1        is 	/* TODO: prepare hw if necessary */
    894   1.1        is 	status = bp->rhw_status;
    895   1.1        is 	if (!(status & REPSTATUS_PLAY))
    896   1.1        is 		bp->rhw_status = status |
    897   1.1        is 		    REPSTATUS_PLAY | REPSTATUS_PLAYFIFORST;
    898   1.1        is 
    899   1.1        is 	/* copy data */
    900   1.1        is 	(*sc->sc_playfun)(bp, buf, blksize, sc->sc_playflags);
    901   1.1        is 
    902   1.1        is 	/* TODO: set hw if necessary */
    903   1.1        is 	if (intr) {
    904   1.1        is 		bp->rhw_status |= REPSTATUS_PLAYIRQENABLE;
    905   1.1        is 		bp->rhw_play_fifosz = blksize / sc->sc_playscale / 2;
    906   1.1        is 		/* /2: give us time to return on the first call */
    907   1.1        is 	}
    908   1.1        is 
    909   1.1        is 	/* save callback function */
    910   1.1        is 	sc->sc_playarg = intrarg;
    911   1.1        is 	sc->sc_playmore = intr;
    912   1.1        is 
    913   1.1        is 	return 0;
    914   1.1        is }
    915   1.1        is 
    916   1.1        is int
    917   1.1        is rep_start_input(void *addr, void *block, int blksize,
    918  1.13      kent 	void (*intr)(void*), void *intrarg)
    919  1.13      kent {
    920   1.1        is 	struct repulse_softc *sc;
    921   1.1        is 	struct repulse_hw *bp;
    922  1.13      kent 	uint16_t status;
    923   1.1        is 
    924   1.1        is 	sc = addr;
    925   1.1        is 	bp = sc->sc_boardp;
    926   1.1        is 
    927   1.1        is 	sc->sc_captbuf = block;
    928   1.1        is 	sc->sc_captbufsz = blksize;
    929   1.1        is 	sc->sc_captarg = intrarg;
    930   1.1        is 	sc->sc_captmore = intr;
    931   1.1        is 
    932   1.1        is 	status = bp->rhw_status;
    933   1.1        is 	if (!(status & REPSTATUS_RECORD))
    934   1.1        is 		bp->rhw_status = status | REPSTATUS_RECORD
    935   1.1        is 			| REPSTATUS_RECFIFORST;
    936   1.1        is 
    937   1.1        is 	bp->rhw_status |= REPSTATUS_RECIRQENABLE;
    938   1.1        is 	bp->rhw_capt_fifosz = blksize / sc->sc_captscale;
    939   1.1        is 
    940   1.1        is 	return 0;
    941   1.1        is }
    942   1.1        is 
    943   1.1        is /* irq handler */
    944   1.1        is 
    945   1.1        is int
    946  1.13      kent rep_intr(void *tag)
    947  1.13      kent {
    948   1.1        is 	struct repulse_softc *sc;
    949   1.1        is 	struct repulse_hw *bp;
    950   1.1        is 	int foundone;
    951  1.13      kent 	uint16_t status;
    952   1.1        is 
    953   1.1        is 	foundone = 0;
    954   1.1        is 
    955   1.1        is 	sc = tag;
    956  1.18  jmcneill 
    957  1.18  jmcneill 	mutex_spin_enter(&sc->sc_intr_lock);
    958  1.18  jmcneill 
    959   1.1        is 	bp = sc->sc_boardp;
    960   1.1        is 	status = bp->rhw_status;
    961   1.1        is 
    962   1.1        is 	if (status & REPSTATUS_PLAYIRQACK) {
    963   1.1        is 		foundone = 1;
    964   1.1        is 		status &= ~REPSTATUS_PLAYIRQENABLE;
    965   1.1        is 		bp->rhw_status = status;
    966   1.1        is 		(*sc->sc_playmore)(sc->sc_playarg);
    967   1.1        is 	}
    968   1.1        is 
    969   1.1        is 	if (status & REPSTATUS_RECIRQACK) {
    970   1.1        is 		foundone = 1;
    971   1.1        is 		status &= ~REPSTATUS_RECIRQENABLE;
    972   1.1        is 		bp->rhw_status = status;
    973   1.1        is 		(*sc->sc_captfun)(bp, sc->sc_captbuf, sc->sc_captbufsz,
    974   1.1        is 			sc->sc_captflags);
    975   1.1        is 		(*sc->sc_captmore)(sc->sc_captarg);
    976   1.1        is 	}
    977   1.1        is 
    978  1.18  jmcneill 	mutex_spin_exit(&sc->sc_intr_lock);
    979  1.18  jmcneill 
    980   1.1        is 	return foundone;
    981   1.1        is }
    982