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