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