Home | History | Annotate | Line # | Download | only in dev
      1  1.22    andvar /* $NetBSD: toccata.c,v 1.22 2023/08/27 18:36:55 andvar Exp $ */
      2   1.1        is 
      3   1.1        is /*-
      4   1.1        is  * Copyright (c) 1998, 1999, 2001, 2002 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 Paul Kranenburg and 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.2   aymeric 
     32   1.2   aymeric #include <sys/cdefs.h>
     33  1.22    andvar __KERNEL_RCSID(0, "$NetBSD: toccata.c,v 1.22 2023/08/27 18:36:55 andvar 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.10      kent #include <sys/device.h>
     40   1.1        is #include <sys/fcntl.h>		/* FREAD */
     41  1.14    dyoung #include <sys/bus.h>
     42   1.1        is 
     43   1.1        is #include <sys/audioio.h>
     44  1.19     isaki #include <dev/audio/audio_if.h>
     45   1.1        is 
     46   1.1        is #include <dev/ic/ad1848reg.h>
     47   1.1        is #include <dev/ic/ad1848var.h>
     48   1.1        is 
     49   1.1        is #include <amiga/dev/zbusvar.h>
     50   1.1        is #include <amiga/amiga/isr.h>
     51   1.1        is 
     52  1.22    andvar #ifdef AUDIO_DEBUG
     53  1.22    andvar #define DPRINTF(x)	if (ad1848debug) printf x
     54  1.22    andvar extern int	ad1848debug;
     55  1.22    andvar #else
     56  1.22    andvar #define DPRINTF(x)
     57  1.22    andvar #endif
     58   1.1        is 
     59   1.1        is /* Register offsets. XXX All of this is guesswork. */
     60   1.1        is 
     61   1.1        is /*
     62   1.1        is  * The Toccata board consists of: GALs for ZBus AutoConfig(tm) glue, GALs
     63   1.1        is  * that interface the FIFO chips and the audio codec chip to the ZBus,
     64   1.1        is  * an AD1848 (or AD1845), and 2 Integrated Device Technology 7202LA
     65   1.1        is  * (1024x9bit FIFO) chips.
     66   1.1        is  */
     67   1.1        is 
     68  1.10      kent #define TOCC_FIFO_STAT	0x1ffe
     69  1.10      kent #define TOCC_FIFO_DATA	0x2000
     70   1.1        is 
     71   1.1        is /*
     72   1.1        is  * I don't know whether the AD1848 PIO data registers are connected... and
     73   1.1        is  * at 2 or 3 accesses to read or write a data byte in the best case, I better
     74  1.10      kent  * don't even think about it. The AD1848 address/status and data port are
     75   1.1        is  * here:
     76   1.1        is  */
     77   1.1        is #define TOCC_CODEC_ADDR	0x67FF
     78   1.1        is #define TOCC_CODEC_STAT	TOCC_CODEC_ADDR
     79   1.1        is #define TOCC_CODEC_REG	0x6801
     80   1.1        is 
     81   1.1        is /* fifo status bits, read */
     82   1.1        is 
     83   1.1        is #define TOCC_FIFO_INT	0x80	/* active low; together with one of those: */
     84   1.1        is 
     85   1.1        is #define TOCC_FIFO_PBHE	0x08	/* playback fifo is half empty (active high) */
     86   1.1        is #define TOCC_FIFO_CPHF	0x04	/* capture fifo is half full (active high) */
     87   1.1        is 
     88   1.1        is /* fifo status bits, write */
     89   1.1        is 
     90   1.1        is /*
     91   1.1        is  * seems to work like this:
     92   1.1        is  * init: write 2; delay; write 1
     93   1.1        is  *
     94   1.1        is  * capture: write 1; write 1+4+8+0x40	(0x4D)
     95   1.1        is  * capt. int: read 512 bytes out of fifo.
     96   1.1        is  * capt. int off by writing 1+4+8	(0x0D)
     97   1.1        is  *
     98   1.1        is  * playback: write 1; write 1 + 0x10;	(0x11)
     99   1.1        is  * 3/4 fill fifo with silence; init codec;
    100   1.1        is  * write 1+4+0x10+0x80			(0x95)
    101   1.1        is  * pb int: write 512 bytes to fifo
    102   1.1        is  * pb int off by writing 1+4+0x10	(0x15)
    103  1.10      kent  */
    104   1.1        is 
    105   1.1        is #define TOCC_RST	0x02
    106   1.1        is #define TOCC_ACT	0x01
    107   1.1        is #define TOCC_MAGIC	0x04
    108   1.1        is 
    109   1.1        is #define TOCC_PB_INTENA	0x80
    110   1.1        is #define TOCC_PB_FILL	0x10
    111   1.1        is 
    112   1.1        is #define TOCC_PB_PREP	(TOCC_ACT + TOCC_PB_FILL)
    113   1.1        is #define TOCC_PB_TAIL	(TOCC_PB_PREP + TOCC_MAGIC)
    114   1.1        is #define TOCC_PB_MAIN	(TOCC_PB_TAIL + TOCC_PB_INTENA)
    115   1.1        is 
    116   1.1        is #define TOCC_CP_INTENA	0x40
    117   1.1        is #define TOCC_CP_RUN	0x08
    118   1.1        is 
    119   1.1        is #define TOCC_CP_TAIL	(TOCC_ACT + TOCC_CP_RUN)
    120   1.1        is #define TOCC_CP_MAIN	(TOCC_CP_TAIL + TOCC_CP_INTENA + TOCC_MAGIC)
    121   1.1        is 
    122   1.1        is /*
    123   1.1        is  * For the port stuff. Similar to the cs4231 table, but MONO is not wired
    124   1.1        is  * on the Toccata, which was designed for the AD1848. Also we know how
    125   1.1        is  * to handle input.
    126   1.1        is  */
    127   1.1        is 
    128   1.1        is #define TOCCATA_INPUT_CLASS	0
    129   1.1        is #define TOCCATA_OUTPUT_CLASS	1
    130   1.1        is #define TOCCATA_MONITOR_CLASS	2
    131   1.1        is #define TOCCATA_RECORD_CLASS	3
    132   1.1        is 
    133   1.1        is #define TOCCATA_RECORD_SOURCE	4
    134   1.1        is #define TOCCATA_REC_LVL		5
    135   1.1        is 
    136   1.1        is #define TOCCATA_MIC_IN_LVL	6
    137   1.1        is 
    138   1.1        is #define TOCCATA_AUX1_LVL	7
    139   1.1        is #define TOCCATA_AUX1_MUTE	8
    140   1.1        is 
    141   1.1        is #define TOCCATA_AUX2_LVL	9
    142   1.1        is #define TOCCATA_AUX2_MUTE	10
    143   1.1        is 
    144   1.1        is #define TOCCATA_MONITOR_LVL	11
    145   1.1        is #define TOCCATA_MONITOR_MUTE	12
    146   1.1        is #define TOCCATA_OUTPUT_LVL	13
    147   1.1        is 
    148   1.1        is /* only on AD1845 in mode 2 */
    149   1.1        is 
    150   1.1        is #define TOCCATA_LINE_IN_LVL	14
    151   1.1        is #define TOCCATA_LINE_IN_MUTE	15
    152   1.1        is 
    153   1.1        is /* special, need support */
    154   1.1        is #define TOCCATA_MIC_LVL		16
    155   1.1        is #define TOCCATA_MIC_MUTE	17
    156   1.1        is 
    157   1.1        is 
    158   1.1        is 
    159   1.1        is /* prototypes */
    160   1.1        is 
    161   1.1        is int toccata_intr(void *);
    162   1.1        is int toccata_readreg(struct ad1848_softc *, int);
    163   1.1        is void toccata_writereg(struct ad1848_softc *, int, int);
    164   1.1        is 
    165   1.9      kent int toccata_round_blocksize(void *, int, int, const audio_params_t *);
    166   1.1        is size_t toccata_round_buffersize(void *, int, size_t);
    167   1.1        is 
    168   1.1        is int toccata_open(void *, int);
    169   1.1        is void toccata_close(void *);
    170   1.1        is int toccata_getdev(void *, struct audio_device *);
    171   1.1        is int toccata_get_props(void *);
    172   1.1        is 
    173   1.1        is int toccata_halt_input(void *);
    174   1.1        is int toccata_halt_output(void *);
    175   1.1        is int toccata_start_input(void *, void *, int, void (*)(void *), void *);
    176   1.1        is int toccata_start_output(void *, void *, int, void (*)(void *), void *);
    177   1.1        is 
    178   1.1        is /* I suspect  those should be in a shared file */
    179   1.1        is int toccata_set_port(void *, mixer_ctrl_t *);
    180   1.1        is int toccata_get_port(void *, mixer_ctrl_t *);
    181   1.1        is int toccata_query_devinfo(void *, mixer_devinfo_t *);
    182   1.1        is 
    183  1.15  jmcneill void toccata_get_locks(void *, kmutex_t **, kmutex_t **);
    184  1.15  jmcneill 
    185   1.8      yamt const struct audio_hw_if audiocs_hw_if = {
    186  1.18     isaki 	.open			= toccata_open,
    187  1.18     isaki 	.close			= toccata_close,
    188  1.19     isaki 	.query_format		= ad1848_query_format,
    189  1.19     isaki 	.set_format		= ad1848_set_format,
    190  1.18     isaki 	.round_blocksize	= toccata_round_blocksize,
    191  1.18     isaki 	.commit_settings	= ad1848_commit_settings,
    192  1.18     isaki 	.init_output		= NULL,	/* XXX need this to prefill? */
    193  1.18     isaki 	.init_input		= NULL,
    194  1.18     isaki 	.start_output		= toccata_start_output,
    195  1.18     isaki 	.start_input		= toccata_start_input,
    196  1.18     isaki 	.halt_output		= toccata_halt_output,
    197  1.18     isaki 	.halt_input		= toccata_halt_input,
    198  1.18     isaki 	.getdev			= toccata_getdev,
    199  1.18     isaki 	.set_port		= toccata_set_port,
    200  1.18     isaki 	.get_port		= toccata_get_port,
    201  1.18     isaki 	.query_devinfo		= toccata_query_devinfo,
    202  1.18     isaki 	.round_buffersize	= toccata_round_buffersize,
    203  1.18     isaki 	.get_props		= toccata_get_props,
    204  1.18     isaki 	.get_locks		= toccata_get_locks,
    205   1.1        is };
    206   1.1        is 
    207   1.1        is struct toccata_softc {
    208   1.1        is 	struct ad1848_softc	sc_ad;
    209   1.1        is 	struct isr		sc_isr;
    210  1.10      kent 	volatile uint8_t	*sc_boardp; /* only need a few addresses! */
    211   1.1        is 
    212   1.1        is 	void			(*sc_captmore)(void *);
    213   1.1        is 	void			 *sc_captarg;
    214   1.1        is 	void			 *sc_captbuf;
    215   1.1        is 	int			sc_captbufsz;
    216   1.1        is 
    217   1.1        is 	void			(*sc_playmore)(void *);
    218   1.1        is 	void			 *sc_playarg;
    219  1.15  jmcneill 
    220  1.15  jmcneill 	kmutex_t		sc_lock;
    221  1.15  jmcneill 	kmutex_t		sc_intr_lock;
    222   1.1        is };
    223   1.1        is 
    224  1.13   tsutsui int toccata_match(device_t, cfdata_t, void *);
    225  1.13   tsutsui void toccata_attach(device_t, device_t, void *);
    226   1.1        is 
    227  1.13   tsutsui CFATTACH_DECL_NEW(toccata, sizeof(struct toccata_softc),
    228   1.5   thorpej     toccata_match, toccata_attach, NULL, NULL);
    229   1.1        is 
    230   1.1        is int
    231  1.13   tsutsui toccata_match(device_t parent, cfdata_t cfp, void *aux)
    232  1.10      kent {
    233   1.1        is 	struct zbus_args *zap;
    234   1.1        is 
    235   1.1        is 	zap = aux;
    236   1.1        is 
    237   1.1        is 	if (zap->manid != 18260)
    238   1.1        is 		return (0);
    239   1.1        is 
    240   1.1        is 	if (zap->prodid != 12)
    241   1.1        is 		return (0);
    242   1.1        is 
    243   1.1        is 	return (1);
    244   1.1        is }
    245   1.1        is 
    246   1.1        is void
    247  1.13   tsutsui toccata_attach(device_t parent, device_t self, void *aux)
    248  1.10      kent {
    249   1.1        is 	struct toccata_softc *sc;
    250   1.1        is 	struct ad1848_softc *asc;
    251   1.1        is 	struct zbus_args *zap;
    252  1.10      kent 	volatile uint8_t *boardp;
    253   1.1        is 
    254  1.13   tsutsui 	sc = device_private(self);
    255   1.1        is 	asc = &sc->sc_ad;
    256  1.13   tsutsui 	asc->sc_dev = self;
    257   1.1        is 	zap = aux;
    258   1.1        is 
    259  1.10      kent 	boardp = (volatile uint8_t *)zap->va;
    260   1.1        is 	sc->sc_boardp = boardp;
    261   1.1        is 
    262   1.1        is 	*boardp = TOCC_RST;
    263   1.1        is 	delay(500000);		/* look up value */
    264   1.1        is 	*boardp = TOCC_ACT;
    265   1.1        is 
    266   1.1        is 	asc->parent = sc;
    267   1.1        is 	asc->sc_readreg = toccata_readreg;
    268   1.1        is 	asc->sc_writereg = toccata_writereg;
    269   1.1        is 
    270   1.1        is 	asc->chip_name = "ad1848";
    271   1.1        is 	asc->mode = 1;
    272   1.1        is 	ad1848_attach(asc);
    273   1.1        is 	printf("\n");
    274   1.1        is 
    275   1.1        is 	sc->sc_captbuf = 0;
    276   1.1        is 	sc->sc_playmore = 0;
    277  1.10      kent 
    278  1.15  jmcneill 	mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
    279  1.15  jmcneill 	mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_SCHED);
    280  1.15  jmcneill 
    281   1.1        is 	sc->sc_isr.isr_ipl = 6;
    282   1.1        is 	sc->sc_isr.isr_arg = sc;
    283   1.1        is 	sc->sc_isr.isr_intr = toccata_intr;
    284   1.1        is 	add_isr(&sc->sc_isr);
    285   1.1        is 
    286  1.13   tsutsui 	audio_attach_mi(&audiocs_hw_if, sc, self);
    287   1.1        is 
    288   1.1        is }
    289   1.1        is 
    290   1.6       wiz /* interrupt handler */
    291   1.1        is int
    292   1.1        is toccata_intr(void *tag) {
    293   1.1        is 	struct toccata_softc *sc;
    294  1.10      kent 	uint8_t *buf;
    295  1.10      kent 	volatile uint8_t *fifo;
    296  1.10      kent 	uint8_t status;
    297   1.1        is 	int i;
    298   1.1        is 
    299   1.1        is 	sc = tag;
    300  1.15  jmcneill 
    301  1.15  jmcneill 	mutex_spin_enter(&sc->sc_intr_lock);
    302  1.15  jmcneill 
    303   1.1        is 	status = *(sc->sc_boardp);
    304   1.1        is 
    305  1.15  jmcneill 	if (status & TOCC_FIFO_INT) {	/* active low */
    306  1.15  jmcneill 		mutex_spin_exit(&sc->sc_intr_lock);
    307   1.1        is 		return 0;
    308  1.15  jmcneill 	}
    309   1.1        is 
    310   1.1        is 	if (status & TOCC_FIFO_PBHE) {
    311   1.1        is 		if (sc->sc_playmore) {
    312   1.1        is 			(*sc->sc_playmore)(sc->sc_playarg);
    313  1.15  jmcneill 			mutex_spin_exit(&sc->sc_intr_lock);
    314   1.1        is 			return 1;
    315   1.1        is 		}
    316   1.1        is 	} else if (status & TOCC_FIFO_CPHF) {
    317   1.1        is 		if (sc->sc_captbuf) {
    318   1.1        is 			buf = sc->sc_captbuf;
    319   1.1        is 			fifo = sc->sc_boardp + TOCC_FIFO_DATA;
    320   1.1        is 
    321   1.1        is 			for (i = sc->sc_captbufsz/4 - 1; i>=0; --i) {
    322   1.1        is 				*buf++ = *fifo;
    323   1.1        is 				*buf++ = *fifo;
    324   1.1        is 				*buf++ = *fifo;
    325   1.1        is 				*buf++ = *fifo;
    326   1.1        is 			}
    327  1.10      kent 
    328   1.1        is 			/* XXX if (sc->sc_captmore) { */
    329   1.1        is 			(*sc->sc_captmore)(sc->sc_captarg);
    330  1.15  jmcneill 			mutex_spin_exit(&sc->sc_intr_lock);
    331   1.1        is 			return 1;
    332   1.1        is 		}
    333   1.1        is 	}
    334   1.1        is 
    335   1.1        is 	/*
    336   1.6       wiz 	 * Something is wrong; switch interrupts off to avoid wedging the
    337   1.1        is 	 * machine, and notify the alpha tester.
    338  1.10      kent 	 * Normally, the halt_* functions should have switched off the
    339   1.6       wiz 	 * FIFO interrupt.
    340   1.1        is 	 */
    341   1.1        is #ifdef DEBUG
    342  1.13   tsutsui 	printf("%s: got unexpected interrupt %x\n",
    343  1.13   tsutsui 	    device_xname(sc->sc_ad.sc_dev), status);
    344   1.1        is #endif
    345   1.1        is 	*sc->sc_boardp = TOCC_ACT;
    346  1.15  jmcneill 	mutex_spin_exit(&sc->sc_intr_lock);
    347   1.1        is 	return 1;
    348  1.10      kent }
    349   1.1        is 
    350   1.1        is /* support for ad1848 functions */
    351   1.1        is 
    352   1.1        is int
    353  1.10      kent toccata_readreg(struct ad1848_softc *asc, int offset)
    354  1.10      kent {
    355  1.10      kent 	struct toccata_softc *sc;
    356   1.1        is 
    357  1.10      kent 	sc = (struct toccata_softc *)asc;
    358  1.10      kent 	return *(sc->sc_boardp + TOCC_CODEC_ADDR +
    359  1.10      kent 		offset * (TOCC_CODEC_REG - TOCC_CODEC_ADDR));
    360   1.1        is }
    361   1.1        is 
    362   1.1        is void
    363  1.10      kent toccata_writereg(struct ad1848_softc *asc, int offset, int value)
    364  1.10      kent {
    365  1.10      kent 	struct toccata_softc *sc;
    366   1.1        is 
    367  1.10      kent 	sc = (struct toccata_softc *)asc;
    368   1.1        is 	*(sc->sc_boardp + TOCC_CODEC_ADDR +
    369   1.1        is 		offset * (TOCC_CODEC_REG - TOCC_CODEC_ADDR)) = value;
    370   1.1        is }
    371   1.1        is 
    372   1.6       wiz /* our own copy of open/close; we don't ever enable the ad1848 interrupts */
    373   1.1        is int
    374  1.10      kent toccata_open(void *addr, int flags)
    375  1.10      kent {
    376   1.1        is 	struct toccata_softc *sc;
    377   1.1        is 	struct ad1848_softc *asc;
    378   1.1        is 
    379   1.1        is 	sc = addr;
    380   1.1        is 	asc = &sc->sc_ad;
    381   1.1        is 
    382   1.1        is 	asc->open_mode = flags;
    383   1.1        is 	/* If recording && monitoring, the playback part is also used. */
    384   1.1        is 	if (flags & FREAD && asc->mute[AD1848_MONITOR_CHANNEL] == 0)
    385   1.1        is 		ad1848_mute_wave_output(asc, WAVE_UNMUTE1, 1);
    386   1.1        is 
    387   1.1        is #ifdef AUDIO_DEBUG
    388  1.10      kent 	if (ad1848debug)
    389  1.10      kent 		ad1848_dump_regs(asc);
    390  1.10      kent #endif
    391  1.10      kent 
    392  1.10      kent 	return 0;
    393   1.1        is }
    394   1.1        is 
    395   1.1        is void
    396  1.10      kent toccata_close(void *addr)
    397  1.10      kent {
    398  1.10      kent 	struct toccata_softc *sc;
    399  1.10      kent 	struct ad1848_softc *asc;
    400   1.1        is 	unsigned reg;
    401  1.10      kent 
    402  1.10      kent 	sc = addr;
    403  1.10      kent 	asc = &sc->sc_ad;
    404  1.10      kent 	asc->open_mode = 0;
    405  1.10      kent 
    406  1.10      kent 	ad1848_mute_wave_output(asc, WAVE_UNMUTE1, 0);
    407   1.1        is 
    408   1.1        is 	reg = ad_read(&sc->sc_ad, SP_INTERFACE_CONFIG);
    409   1.1        is 	ad_write(&sc->sc_ad, SP_INTERFACE_CONFIG,
    410   1.1        is 		(reg & ~(CAPTURE_ENABLE|PLAYBACK_ENABLE)));
    411   1.1        is 
    412  1.10      kent 	/* Disable interrupts */
    413   1.1        is 	*sc->sc_boardp = TOCC_ACT;
    414   1.1        is #ifdef AUDIO_DEBUG
    415  1.10      kent 	if (ad1848debug)
    416  1.10      kent 		ad1848_dump_regs(asc);
    417   1.1        is #endif
    418   1.1        is }
    419   1.1        is 
    420   1.1        is int
    421   1.9      kent toccata_round_blocksize(void *addr, int blk,
    422   1.9      kent 			int mode, const audio_params_t *param)
    423   1.9      kent {
    424   1.1        is 
    425  1.21     isaki 	if (blk > 512)
    426  1.21     isaki 		blk = 512;
    427  1.21     isaki 	return blk;
    428   1.1        is }
    429   1.1        is 
    430   1.1        is size_t
    431  1.10      kent toccata_round_buffersize(void *addr, int direction, size_t suggested)
    432  1.10      kent {
    433   1.1        is 
    434  1.10      kent 	return suggested & -4;
    435   1.1        is }
    436   1.1        is 
    437   1.1        is struct audio_device toccata_device = {
    438   1.1        is 	"toccata", "x", "audio"
    439   1.1        is };
    440   1.1        is 
    441   1.1        is int
    442  1.10      kent toccata_getdev(void *addr, struct audio_device *retp)
    443  1.10      kent {
    444  1.10      kent 
    445   1.1        is 	*retp = toccata_device;
    446  1.10      kent 	return 0;
    447   1.1        is }
    448   1.1        is 
    449   1.1        is int
    450  1.10      kent toccata_get_props(void *addr)
    451  1.10      kent {
    452  1.20     isaki 
    453  1.20     isaki 	return AUDIO_PROP_PLAYBACK | AUDIO_PROP_CAPTURE;
    454   1.1        is }
    455   1.1        is 
    456  1.15  jmcneill void
    457  1.15  jmcneill toccata_get_locks(void *opaque, kmutex_t **intr, kmutex_t **thread)
    458  1.15  jmcneill {
    459  1.15  jmcneill 	struct toccata_softc *sc = opaque;
    460  1.15  jmcneill 
    461  1.15  jmcneill 	*intr = &sc->sc_intr_lock;
    462  1.15  jmcneill 	*thread = &sc->sc_lock;
    463  1.15  jmcneill }
    464  1.15  jmcneill 
    465   1.1        is int
    466  1.10      kent toccata_halt_input(void *addr)
    467  1.10      kent {
    468   1.1        is 	struct toccata_softc *sc;
    469   1.1        is 	unsigned reg;
    470   1.1        is 
    471   1.1        is 	sc = addr;
    472   1.1        is 
    473   1.1        is 	/* we're half_duplex; be brutal */
    474   1.1        is 	*sc->sc_boardp = TOCC_CP_TAIL;
    475   1.1        is 	sc->sc_captmore = 0;
    476   1.1        is 	sc->sc_captbuf = 0;
    477  1.10      kent 
    478   1.1        is 	reg = ad_read(&sc->sc_ad, SP_INTERFACE_CONFIG);
    479   1.1        is 	ad_write(&sc->sc_ad, SP_INTERFACE_CONFIG, (reg & ~CAPTURE_ENABLE));
    480   1.1        is 
    481   1.1        is 	return 0;
    482   1.1        is }
    483   1.1        is 
    484  1.10      kent int
    485  1.10      kent toccata_start_input(void *addr, void *block, int blksize,
    486  1.10      kent 	void (*intr)(void *), void *intrarg)
    487  1.10      kent {
    488   1.1        is 	struct toccata_softc *sc;
    489  1.10      kent 	unsigned int reg;
    490  1.10      kent 	volatile uint8_t *cmd;
    491   1.1        is 
    492   1.1        is 	sc = addr;
    493   1.1        is 	cmd = sc->sc_boardp;
    494   1.1        is 
    495   1.1        is 	if (sc->sc_captmore == 0) {
    496   1.1        is 
    497   1.1        is 		/* we're half-duplex, be brutal */
    498   1.1        is 		*cmd = TOCC_ACT;
    499   1.1        is 		*cmd = TOCC_CP_MAIN;
    500   1.1        is 
    501   1.1        is 		reg = ad_read(&sc->sc_ad, SP_INTERFACE_CONFIG);
    502   1.1        is 		ad_write(&sc->sc_ad, SP_INTERFACE_CONFIG,
    503   1.1        is 		    (reg | CAPTURE_ENABLE));
    504   1.1        is 
    505   1.1        is 	}
    506   1.1        is 
    507   1.1        is 	sc->sc_captarg = intrarg;
    508   1.1        is 	sc->sc_captmore = intr;
    509  1.10      kent 	sc->sc_captbuf = (uint8_t *)block;
    510   1.1        is 	sc->sc_captbufsz = blksize;
    511   1.1        is 
    512   1.1        is 	return 0;
    513   1.1        is }
    514   1.1        is 
    515   1.1        is int
    516  1.10      kent toccata_halt_output(void *addr)
    517  1.10      kent {
    518   1.1        is 	struct toccata_softc *sc;
    519  1.10      kent 	unsigned int reg;
    520   1.1        is 
    521   1.1        is 	sc = addr;
    522   1.1        is 
    523   1.1        is 	/* we're half_duplex; be brutal */
    524   1.1        is 	*sc->sc_boardp = TOCC_PB_TAIL;
    525   1.1        is 	sc->sc_playmore = 0;
    526  1.10      kent 
    527   1.1        is 	reg = ad_read(&sc->sc_ad, SP_INTERFACE_CONFIG);
    528   1.1        is 	ad_write(&sc->sc_ad, SP_INTERFACE_CONFIG, (reg & ~PLAYBACK_ENABLE));
    529   1.1        is 
    530   1.1        is 	return 0;
    531   1.1        is }
    532   1.1        is 
    533  1.10      kent int
    534  1.10      kent toccata_start_output(void *addr, void *block, int blksize,
    535  1.10      kent 	void (*intr)(void*), void *intrarg)
    536  1.10      kent {
    537   1.1        is 	struct toccata_softc *sc;
    538   1.1        is 	unsigned reg;
    539   1.1        is 	int i;
    540  1.10      kent 	volatile uint8_t *cmd, *fifo;
    541  1.10      kent 	uint8_t *buf;
    542   1.1        is 
    543   1.1        is 	sc = addr;
    544   1.1        is 	buf = block;
    545   1.1        is 
    546   1.1        is 	cmd = sc->sc_boardp;
    547   1.1        is 	fifo = sc->sc_boardp + TOCC_FIFO_DATA;
    548   1.1        is 
    549   1.1        is 	if (sc->sc_playmore == 0) {
    550   1.1        is 		*cmd = TOCC_ACT;
    551   1.1        is 		*cmd = TOCC_PB_PREP;
    552   1.1        is 	}
    553   1.1        is 
    554   1.1        is 	/*
    555   1.1        is 	 * We rounded the blocksize to a multiple of 4 bytes. Modest
    556   1.1        is 	 * unrolling saves 2% of cputime playing 48000 16bit stereo
    557   1.1        is 	 * on 68040/25MHz.
    558   1.1        is 	 */
    559   1.1        is 
    560   1.1        is 	for (i = blksize/4 - 1; i>=0; --i) {
    561   1.1        is 		*fifo = *buf++;
    562   1.1        is 		*fifo = *buf++;
    563   1.1        is 		*fifo = *buf++;
    564   1.1        is 		*fifo = *buf++;
    565   1.1        is 	}
    566  1.10      kent 
    567   1.1        is 	if (sc->sc_playmore == 0) {
    568   1.1        is 		reg = ad_read(&sc->sc_ad, SP_INTERFACE_CONFIG);
    569   1.1        is 		ad_write(&sc->sc_ad, SP_INTERFACE_CONFIG,
    570   1.1        is 		    (reg | PLAYBACK_ENABLE));
    571   1.1        is 
    572   1.1        is 		/* we're half-duplex, be brutal */
    573   1.1        is 		*sc->sc_boardp = TOCC_PB_MAIN;
    574   1.1        is 	}
    575   1.1        is 
    576   1.1        is 	sc->sc_playarg = intrarg;
    577   1.1        is 	sc->sc_playmore = intr;
    578   1.1        is 
    579   1.1        is 	return 0;
    580   1.1        is }
    581   1.1        is 
    582   1.1        is static ad1848_devmap_t csmapping[] = {
    583   1.1        is 	{ TOCCATA_MIC_IN_LVL, AD1848_KIND_MICGAIN, -1 },
    584   1.1        is 	{ TOCCATA_AUX1_LVL, AD1848_KIND_LVL, AD1848_AUX1_CHANNEL },
    585   1.1        is 	{ TOCCATA_AUX1_MUTE, AD1848_KIND_MUTE, AD1848_AUX1_CHANNEL },
    586   1.1        is 	{ TOCCATA_AUX2_LVL, AD1848_KIND_LVL, AD1848_AUX2_CHANNEL },
    587   1.1        is 	{ TOCCATA_AUX2_MUTE, AD1848_KIND_MUTE, AD1848_AUX2_CHANNEL },
    588   1.1        is 	{ TOCCATA_OUTPUT_LVL, AD1848_KIND_LVL, AD1848_DAC_CHANNEL },
    589   1.1        is 	{ TOCCATA_MONITOR_LVL, AD1848_KIND_LVL, AD1848_MONITOR_CHANNEL },
    590   1.1        is 	{ TOCCATA_MONITOR_MUTE, AD1848_KIND_MUTE, AD1848_MONITOR_CHANNEL },
    591   1.1        is 	{ TOCCATA_REC_LVL, AD1848_KIND_RECORDGAIN, -1 },
    592   1.1        is 	{ TOCCATA_RECORD_SOURCE, AD1848_KIND_RECORDSOURCE, -1 },
    593   1.1        is /* only in mode 2: */
    594  1.10      kent 	{ TOCCATA_LINE_IN_LVL, AD1848_KIND_LVL, AD1848_LINE_CHANNEL },
    595   1.1        is 	{ TOCCATA_LINE_IN_MUTE, AD1848_KIND_MUTE, AD1848_LINE_CHANNEL },
    596   1.1        is };
    597   1.1        is 
    598   1.1        is #define nummap (sizeof(csmapping) / sizeof(csmapping[0]))
    599   1.1        is 
    600   1.1        is int
    601  1.10      kent toccata_set_port(void *addr, mixer_ctrl_t *cp)
    602  1.10      kent {
    603  1.10      kent 	struct ad1848_softc *ac;
    604   1.1        is 
    605   1.1        is 	/* printf("set_port(%d)\n", cp->dev); */
    606  1.10      kent 	ac = addr;
    607  1.10      kent 	return ad1848_mixer_set_port(ac, csmapping,
    608  1.10      kent 		ac->mode == 2 ? nummap : nummap - 2, cp);
    609   1.1        is }
    610   1.1        is 
    611   1.1        is int
    612  1.10      kent toccata_get_port(void *addr, mixer_ctrl_t *cp)
    613  1.10      kent {
    614  1.10      kent 	struct ad1848_softc *ac;
    615   1.1        is 
    616   1.1        is 	/* printf("get_port(%d)\n", cp->dev); */
    617  1.10      kent 	ac = addr;
    618  1.10      kent 	return ad1848_mixer_get_port(ac, csmapping,
    619  1.10      kent 		ac->mode == 2 ? nummap : nummap - 2, cp);
    620   1.1        is }
    621   1.1        is 
    622   1.1        is int
    623  1.10      kent toccata_query_devinfo(void *addr, mixer_devinfo_t *dip)
    624  1.10      kent {
    625   1.1        is 
    626   1.1        is 	switch(dip->index) {
    627   1.1        is 	case TOCCATA_MIC_IN_LVL:	/* Microphone */
    628   1.1        is 		dip->type = AUDIO_MIXER_VALUE;
    629   1.1        is 		dip->mixer_class = TOCCATA_INPUT_CLASS;
    630   1.1        is 		dip->prev = dip->next = AUDIO_MIXER_LAST;
    631   1.1        is 		strcpy(dip->label.name, AudioNmicrophone);
    632   1.1        is 		dip->un.v.num_channels = 1;
    633   1.1        is 		strcpy(dip->un.v.units.name, AudioNvolume);
    634   1.1        is 		break;
    635   1.1        is #if 0
    636   1.1        is 
    637   1.1        is 	case TOCCATA_MONO_LVL:	/* mono/microphone mixer */
    638   1.1        is 		dip->type = AUDIO_MIXER_VALUE;
    639   1.1        is 		dip->mixer_class = TOCCATA_INPUT_CLASS;
    640   1.1        is 		dip->prev = AUDIO_MIXER_LAST;
    641   1.1        is 		dip->next = TOCCATA_MONO_MUTE;
    642   1.1        is 		strcpy(dip->label.name, AudioNmicrophone);
    643   1.1        is 		dip->un.v.num_channels = 1;
    644   1.1        is 		strcpy(dip->un.v.units.name, AudioNvolume);
    645   1.1        is 		break;
    646   1.1        is #endif
    647   1.1        is 
    648   1.1        is 	case TOCCATA_AUX1_LVL:		/*  dacout */
    649   1.1        is 		dip->type = AUDIO_MIXER_VALUE;
    650   1.1        is 		dip->mixer_class = TOCCATA_INPUT_CLASS;
    651   1.1        is 		dip->prev = AUDIO_MIXER_LAST;
    652   1.1        is 		dip->next = TOCCATA_AUX1_MUTE;
    653   1.1        is 		strcpy(dip->label.name, "aux1");
    654   1.1        is 		dip->un.v.num_channels = 2;
    655   1.1        is 		strcpy(dip->un.v.units.name, AudioNvolume);
    656   1.1        is 		break;
    657   1.1        is 
    658   1.1        is 	case TOCCATA_AUX1_MUTE:
    659   1.1        is 		dip->mixer_class = TOCCATA_INPUT_CLASS;
    660   1.1        is 		dip->type = AUDIO_MIXER_ENUM;
    661   1.1        is 		dip->prev = TOCCATA_AUX1_LVL;
    662   1.1        is 		dip->next = AUDIO_MIXER_LAST;
    663   1.1        is 		goto mute;
    664   1.1        is 
    665   1.1        is 
    666   1.1        is 
    667   1.1        is 	case TOCCATA_AUX2_LVL:
    668   1.1        is 		dip->type = AUDIO_MIXER_VALUE;
    669   1.1        is 		dip->mixer_class = TOCCATA_INPUT_CLASS;
    670   1.1        is 		dip->prev = AUDIO_MIXER_LAST;
    671   1.1        is 		dip->next = TOCCATA_AUX2_MUTE;
    672   1.1        is 		strcpy(dip->label.name, "aux2");
    673   1.1        is 		dip->un.v.num_channels = 2;
    674   1.1        is 		strcpy(dip->un.v.units.name, AudioNvolume);
    675   1.1        is 		break;
    676   1.1        is 
    677   1.1        is 	case TOCCATA_AUX2_MUTE:
    678   1.1        is 		dip->mixer_class = TOCCATA_INPUT_CLASS;
    679   1.1        is 		dip->type = AUDIO_MIXER_ENUM;
    680   1.1        is 		dip->prev = TOCCATA_AUX2_LVL;
    681   1.1        is 		dip->next = AUDIO_MIXER_LAST;
    682   1.1        is 		goto mute;
    683   1.1        is 
    684   1.1        is 
    685   1.1        is 	case TOCCATA_MONITOR_LVL:	/* monitor level */
    686   1.1        is 		dip->type = AUDIO_MIXER_VALUE;
    687   1.1        is 		dip->mixer_class = TOCCATA_MONITOR_CLASS;
    688   1.1        is 		dip->next = TOCCATA_MONITOR_MUTE;
    689   1.1        is 		dip->prev = AUDIO_MIXER_LAST;
    690   1.1        is 		strcpy(dip->label.name, AudioNmonitor);
    691   1.1        is 		dip->un.v.num_channels = 1;
    692   1.1        is 		strcpy(dip->un.v.units.name, AudioNvolume);
    693   1.1        is 		break;
    694   1.1        is 
    695   1.1        is 	case TOCCATA_OUTPUT_LVL:	/* output volume */
    696   1.1        is 		dip->type = AUDIO_MIXER_VALUE;
    697   1.1        is 		dip->mixer_class = TOCCATA_OUTPUT_CLASS;
    698   1.1        is 		dip->prev = dip->next = AUDIO_MIXER_LAST;
    699   1.1        is 		strcpy(dip->label.name, AudioNmaster);
    700   1.1        is 		dip->un.v.num_channels = 2;
    701   1.1        is 		strcpy(dip->un.v.units.name, AudioNvolume);
    702   1.1        is 		break;
    703   1.1        is #if 0
    704   1.1        is 	case TOCCATA_LINE_IN_LVL:	/* line */
    705   1.1        is 		dip->type = AUDIO_MIXER_VALUE;
    706   1.1        is 		dip->mixer_class = TOCCATA_INPUT_CLASS;
    707   1.1        is 		dip->prev = AUDIO_MIXER_LAST;
    708   1.1        is 		dip->next = TOCCATA_LINE_IN_MUTE;
    709   1.1        is 		strcpy(dip->label.name, AudioNline);
    710   1.1        is 		dip->un.v.num_channels = 2;
    711   1.1        is 		strcpy(dip->un.v.units.name, AudioNvolume);
    712   1.1        is 		break;
    713   1.1        is 
    714   1.1        is 	case TOCCATA_LINE_IN_MUTE:
    715   1.1        is 		dip->mixer_class = TOCCATA_INPUT_CLASS;
    716   1.1        is 		dip->type = AUDIO_MIXER_ENUM;
    717   1.1        is 		dip->prev = TOCCATA_LINE_IN_LVL;
    718   1.1        is 		dip->next = AUDIO_MIXER_LAST;
    719   1.1        is 		goto mute;
    720   1.1        is #endif
    721   1.1        is 	case TOCCATA_MONITOR_MUTE:
    722   1.1        is 		dip->mixer_class = TOCCATA_MONITOR_CLASS;
    723   1.1        is 		dip->type = AUDIO_MIXER_ENUM;
    724   1.1        is 		dip->prev = TOCCATA_MONITOR_LVL;
    725   1.1        is 		dip->next = AUDIO_MIXER_LAST;
    726   1.1        is 	mute:
    727   1.1        is 		strcpy(dip->label.name, AudioNmute);
    728   1.1        is 		dip->un.e.num_mem = 2;
    729   1.1        is 		strcpy(dip->un.e.member[0].label.name, AudioNoff);
    730   1.1        is 		dip->un.e.member[0].ord = 0;
    731   1.1        is 		strcpy(dip->un.e.member[1].label.name, AudioNon);
    732   1.1        is 		dip->un.e.member[1].ord = 1;
    733   1.1        is 		break;
    734  1.10      kent 
    735   1.1        is 	case TOCCATA_REC_LVL:	/* record level */
    736   1.1        is 		dip->type = AUDIO_MIXER_VALUE;
    737   1.1        is 		dip->mixer_class = TOCCATA_INPUT_CLASS;
    738   1.1        is 		dip->prev = AUDIO_MIXER_LAST;
    739   1.1        is 		dip->next = TOCCATA_RECORD_SOURCE;
    740   1.1        is 		strcpy(dip->label.name, AudioNrecord);
    741   1.1        is 		dip->un.v.num_channels = 2;
    742   1.1        is 		strcpy(dip->un.v.units.name, AudioNvolume);
    743   1.1        is 		break;
    744   1.1        is 
    745   1.1        is 	case TOCCATA_RECORD_SOURCE:
    746   1.1        is 		dip->mixer_class = TOCCATA_RECORD_CLASS;
    747   1.1        is 		dip->type = AUDIO_MIXER_ENUM;
    748   1.1        is 		dip->prev = TOCCATA_REC_LVL;
    749   1.1        is 		dip->next = AUDIO_MIXER_LAST;
    750   1.1        is 		strcpy(dip->label.name, AudioNsource);
    751   1.1        is 		dip->un.e.num_mem = 4;
    752   1.1        is 		strcpy(dip->un.e.member[0].label.name, AudioNmicrophone);
    753   1.1        is 		dip->un.e.member[1].ord = MIC_IN_PORT;
    754   1.1        is 		strcpy(dip->un.e.member[1].label.name, AudioNline);
    755   1.1        is 		dip->un.e.member[3].ord = LINE_IN_PORT;
    756   1.1        is 		strcpy(dip->un.e.member[2].label.name, "aux1");
    757   1.1        is 		dip->un.e.member[2].ord = AUX1_IN_PORT;
    758   1.1        is 		strcpy(dip->un.e.member[3].label.name, AudioNoutput);
    759   1.1        is 		dip->un.e.member[0].ord = DAC_IN_PORT;
    760   1.1        is 		break;
    761   1.1        is 
    762   1.1        is 	case TOCCATA_INPUT_CLASS:		/* input class descriptor */
    763   1.1        is 		dip->type = AUDIO_MIXER_CLASS;
    764   1.1        is 		dip->mixer_class = TOCCATA_INPUT_CLASS;
    765   1.1        is 		dip->next = dip->prev = AUDIO_MIXER_LAST;
    766   1.1        is 		strcpy(dip->label.name, AudioCinputs);
    767   1.1        is 		break;
    768   1.1        is 
    769   1.1        is 	case TOCCATA_OUTPUT_CLASS:		/* output class descriptor */
    770   1.1        is 		dip->type = AUDIO_MIXER_CLASS;
    771   1.1        is 		dip->mixer_class = TOCCATA_OUTPUT_CLASS;
    772   1.1        is 		dip->next = dip->prev = AUDIO_MIXER_LAST;
    773   1.1        is 		strcpy(dip->label.name, AudioCoutputs);
    774   1.1        is 		break;
    775   1.1        is 
    776   1.1        is 	case TOCCATA_MONITOR_CLASS:		/* monitor class descriptor */
    777   1.1        is 		dip->type = AUDIO_MIXER_CLASS;
    778   1.1        is 		dip->mixer_class = TOCCATA_MONITOR_CLASS;
    779   1.1        is 		dip->next = dip->prev = AUDIO_MIXER_LAST;
    780   1.1        is 		strcpy(dip->label.name, AudioCmonitor);
    781   1.1        is 		break;
    782  1.10      kent 
    783   1.1        is 	case TOCCATA_RECORD_CLASS:		/* record source class */
    784   1.1        is 		dip->type = AUDIO_MIXER_CLASS;
    785   1.1        is 		dip->mixer_class = TOCCATA_RECORD_CLASS;
    786   1.1        is 		dip->next = dip->prev = AUDIO_MIXER_LAST;
    787   1.1        is 		strcpy(dip->label.name, AudioCrecord);
    788   1.1        is 		break;
    789   1.1        is 
    790   1.1        is 	default:
    791   1.1        is 		return ENXIO;
    792   1.1        is 		/*NOTREACHED*/
    793   1.1        is 	}
    794   1.1        is 
    795  1.10      kent 	return 0;
    796   1.1        is }
    797