Home | History | Annotate | Line # | Download | only in isa
ad1848_isa.c revision 1.6
      1  1.6  mycroft /*	$NetBSD: ad1848_isa.c,v 1.6 1999/02/17 23:05:28 mycroft Exp $	*/
      2  1.1       pk 
      3  1.1       pk /*
      4  1.1       pk  * Copyright (c) 1994 John Brezak
      5  1.1       pk  * Copyright (c) 1991-1993 Regents of the University of California.
      6  1.1       pk  * All rights reserved.
      7  1.1       pk  *
      8  1.1       pk  * Redistribution and use in source and binary forms, with or without
      9  1.1       pk  * modification, are permitted provided that the following conditions
     10  1.1       pk  * are met:
     11  1.1       pk  * 1. Redistributions of source code must retain the above copyright
     12  1.1       pk  *    notice, this list of conditions and the following disclaimer.
     13  1.1       pk  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.1       pk  *    notice, this list of conditions and the following disclaimer in the
     15  1.1       pk  *    documentation and/or other materials provided with the distribution.
     16  1.1       pk  * 3. All advertising materials mentioning features or use of this software
     17  1.1       pk  *    must display the following acknowledgement:
     18  1.1       pk  *	This product includes software developed by the Computer Systems
     19  1.1       pk  *	Engineering Group at Lawrence Berkeley Laboratory.
     20  1.1       pk  * 4. Neither the name of the University nor of the Laboratory may be used
     21  1.1       pk  *    to endorse or promote products derived from this software without
     22  1.1       pk  *    specific prior written permission.
     23  1.1       pk  *
     24  1.1       pk  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25  1.1       pk  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26  1.1       pk  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27  1.1       pk  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28  1.1       pk  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29  1.1       pk  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30  1.1       pk  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31  1.1       pk  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32  1.1       pk  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33  1.1       pk  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34  1.1       pk  * SUCH DAMAGE.
     35  1.1       pk  *
     36  1.1       pk  */
     37  1.1       pk 
     38  1.1       pk /*
     39  1.1       pk  * Copyright by Hannu Savolainen 1994
     40  1.1       pk  *
     41  1.1       pk  * Redistribution and use in source and binary forms, with or without
     42  1.1       pk  * modification, are permitted provided that the following conditions are
     43  1.1       pk  * met: 1. Redistributions of source code must retain the above copyright
     44  1.1       pk  * notice, this list of conditions and the following disclaimer. 2.
     45  1.1       pk  * Redistributions in binary form must reproduce the above copyright notice,
     46  1.1       pk  * this list of conditions and the following disclaimer in the documentation
     47  1.1       pk  * and/or other materials provided with the distribution.
     48  1.1       pk  *
     49  1.1       pk  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
     50  1.1       pk  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     51  1.1       pk  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     52  1.1       pk  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
     53  1.1       pk  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     54  1.1       pk  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     55  1.1       pk  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
     56  1.1       pk  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     57  1.1       pk  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     58  1.1       pk  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     59  1.1       pk  * SUCH DAMAGE.
     60  1.1       pk  *
     61  1.1       pk  */
     62  1.1       pk /*
     63  1.1       pk  * Portions of this code are from the VOXware support for the ad1848
     64  1.1       pk  * by Hannu Savolainen <hannu (at) voxware.pp.fi>
     65  1.1       pk  *
     66  1.1       pk  * Portions also supplied from the SoundBlaster driver for NetBSD.
     67  1.1       pk  */
     68  1.1       pk 
     69  1.1       pk #include <sys/param.h>
     70  1.1       pk #include <sys/systm.h>
     71  1.1       pk #include <sys/errno.h>
     72  1.1       pk #include <sys/ioctl.h>
     73  1.1       pk #include <sys/syslog.h>
     74  1.1       pk #include <sys/device.h>
     75  1.1       pk #include <sys/proc.h>
     76  1.1       pk #include <sys/buf.h>
     77  1.1       pk 
     78  1.1       pk #include <machine/cpu.h>
     79  1.1       pk #include <machine/bus.h>
     80  1.1       pk 
     81  1.1       pk #include <sys/audioio.h>
     82  1.1       pk #include <vm/vm.h>
     83  1.1       pk 
     84  1.1       pk #include <dev/audio_if.h>
     85  1.1       pk #include <dev/auconv.h>
     86  1.1       pk 
     87  1.1       pk #include <dev/isa/isavar.h>
     88  1.1       pk #include <dev/isa/isadmavar.h>
     89  1.1       pk 
     90  1.1       pk #include <dev/ic/ad1848reg.h>
     91  1.1       pk #include <dev/ic/cs4231reg.h>
     92  1.1       pk #include <dev/isa/ad1848var.h>
     93  1.1       pk #include <dev/isa/cs4231var.h>
     94  1.1       pk 
     95  1.1       pk #ifdef AUDIO_DEBUG
     96  1.1       pk #define DPRINTF(x)	if (ad1848debug) printf x
     97  1.1       pk extern int	ad1848debug;
     98  1.1       pk #else
     99  1.1       pk #define DPRINTF(x)
    100  1.1       pk #endif
    101  1.1       pk 
    102  1.1       pk static int ad1848_isa_read __P(( struct ad1848_softc *, int));
    103  1.1       pk static void ad1848_isa_write __P(( struct ad1848_softc *, int, int));
    104  1.1       pk 
    105  1.1       pk int
    106  1.1       pk ad1848_isa_read(sc, index)
    107  1.1       pk 	struct ad1848_softc *sc;
    108  1.1       pk 	int index;
    109  1.1       pk {
    110  1.1       pk 	struct ad1848_isa_softc *isc = (struct ad1848_isa_softc *)sc;
    111  1.1       pk 	return (bus_space_read_1((sc)->sc_iot, (sc)->sc_ioh,
    112  1.1       pk 				 (isc)->sc_iooffs+(index)));
    113  1.1       pk }
    114  1.1       pk 
    115  1.1       pk void
    116  1.1       pk ad1848_isa_write(sc, index, value)
    117  1.1       pk 	struct ad1848_softc *sc;
    118  1.1       pk 	int index;
    119  1.1       pk 	int value;
    120  1.1       pk {
    121  1.1       pk 	struct ad1848_isa_softc *isc = (struct ad1848_isa_softc *)sc;
    122  1.1       pk 	bus_space_write_1((sc)->sc_iot, (sc)->sc_ioh,
    123  1.1       pk 			  (isc)->sc_iooffs+(index), value);
    124  1.1       pk }
    125  1.1       pk 
    126  1.1       pk /*
    127  1.1       pk  * Map and probe for the ad1848 chip
    128  1.1       pk  */
    129  1.1       pk int
    130  1.1       pk ad1848_isa_mapprobe(isc, iobase)
    131  1.1       pk 	struct ad1848_isa_softc *isc;
    132  1.1       pk 	int iobase;
    133  1.1       pk {
    134  1.1       pk 	struct ad1848_softc *sc = (struct ad1848_softc *)&isc->sc_ad1848;
    135  1.1       pk 
    136  1.1       pk 	if (!AD1848_BASE_VALID(iobase)) {
    137  1.1       pk #ifdef AUDIO_DEBUG
    138  1.1       pk 		printf("ad1848: configured iobase %04x invalid\n", iobase);
    139  1.1       pk #endif
    140  1.1       pk 		return 0;
    141  1.1       pk 	}
    142  1.1       pk 
    143  1.1       pk 	isc->sc_iooffs = 0;
    144  1.1       pk 	/* Map the AD1848 ports */
    145  1.1       pk 	if (bus_space_map(sc->sc_iot, iobase, AD1848_NPORT, 0, &sc->sc_ioh))
    146  1.1       pk 		return 0;
    147  1.1       pk 
    148  1.1       pk 	if (!ad1848_isa_probe(isc)) {
    149  1.1       pk 		bus_space_unmap(sc->sc_iot, sc->sc_ioh, AD1848_NPORT);
    150  1.1       pk 		return 0;
    151  1.1       pk 	} else
    152  1.1       pk 		return 1;
    153  1.1       pk }
    154  1.1       pk 
    155  1.1       pk /*
    156  1.1       pk  * Probe for the ad1848 chip
    157  1.1       pk  */
    158  1.1       pk int
    159  1.1       pk ad1848_isa_probe(isc)
    160  1.1       pk 	struct ad1848_isa_softc *isc;
    161  1.1       pk {
    162  1.1       pk 	struct ad1848_softc *sc = (struct ad1848_softc *)&isc->sc_ad1848;
    163  1.1       pk 	u_char tmp, tmp1 = 0xff, tmp2 = 0xff;
    164  1.1       pk 	int i;
    165  1.1       pk 
    166  1.1       pk 	sc->sc_readreg = ad1848_isa_read;
    167  1.1       pk 	sc->sc_writereg = ad1848_isa_write;
    168  1.1       pk 
    169  1.1       pk 	/* Is there an ad1848 chip ? */
    170  1.1       pk 	sc->MCE_bit = MODE_CHANGE_ENABLE;
    171  1.1       pk 	sc->mode = 1;	/* MODE 1 = original ad1848/ad1846/cs4248 */
    172  1.1       pk 
    173  1.1       pk 	/*
    174  1.1       pk 	 * Check that the I/O address is in use.
    175  1.1       pk 	 *
    176  1.1       pk 	 * The SP_IN_INIT bit of the base I/O port is known to be 0 after the
    177  1.1       pk 	 * chip has performed its power-on initialization. Just assume
    178  1.1       pk 	 * this has happened before the OS is starting.
    179  1.1       pk 	 *
    180  1.1       pk 	 * If the I/O address is unused, inb() typically returns 0xff.
    181  1.1       pk 	 */
    182  1.1       pk 	tmp = ADREAD(sc, AD1848_IADDR);
    183  1.1       pk 	if (tmp & SP_IN_INIT) { /* Not a AD1848 */
    184  1.1       pk #if 0
    185  1.1       pk 		DPRINTF(("ad_detect_A %x\n", tmp));
    186  1.1       pk #endif
    187  1.1       pk 		goto bad;
    188  1.1       pk 	}
    189  1.1       pk 
    190  1.1       pk 	/*
    191  1.1       pk 	 * Test if it's possible to change contents of the indirect registers.
    192  1.1       pk 	 * Registers 0 and 1 are ADC volume registers. The bit 0x10 is read
    193  1.1       pk 	 * only so try to avoid using it.
    194  1.1       pk 	 */
    195  1.1       pk 	ad_write(sc, 0, 0xaa);
    196  1.1       pk 	ad_write(sc, 1, 0x45);	/* 0x55 with bit 0x10 clear */
    197  1.1       pk 
    198  1.1       pk 	if ((tmp1 = ad_read(sc, 0)) != 0xaa ||
    199  1.1       pk 	    (tmp2 = ad_read(sc, 1)) != 0x45) {
    200  1.1       pk 		DPRINTF(("ad_detect_B (%x/%x)\n", tmp1, tmp2));
    201  1.1       pk 		goto bad;
    202  1.1       pk 	}
    203  1.1       pk 
    204  1.1       pk 	ad_write(sc, 0, 0x45);
    205  1.1       pk 	ad_write(sc, 1, 0xaa);
    206  1.1       pk 
    207  1.1       pk 	if ((tmp1 = ad_read(sc, 0)) != 0x45 ||
    208  1.1       pk 	    (tmp2 = ad_read(sc, 1)) != 0xaa) {
    209  1.1       pk 		DPRINTF(("ad_detect_C (%x/%x)\n", tmp1, tmp2));
    210  1.1       pk 		goto bad;
    211  1.1       pk 	}
    212  1.1       pk 
    213  1.1       pk 	/*
    214  1.1       pk 	 * The indirect register I12 has some read only bits. Lets
    215  1.1       pk 	 * try to change them.
    216  1.1       pk 	 */
    217  1.1       pk 	tmp = ad_read(sc, SP_MISC_INFO);
    218  1.1       pk 	ad_write(sc, SP_MISC_INFO, (~tmp) & 0x0f);
    219  1.1       pk 
    220  1.1       pk 	if ((tmp & 0x0f) != ((tmp1 = ad_read(sc, SP_MISC_INFO)) & 0x0f)) {
    221  1.1       pk 		DPRINTF(("ad_detect_D (%x)\n", tmp1));
    222  1.1       pk 		goto bad;
    223  1.1       pk 	}
    224  1.1       pk 
    225  1.1       pk 	/*
    226  1.1       pk 	 * MSB and 4 LSBs of the reg I12 tell the chip revision.
    227  1.1       pk 	 *
    228  1.1       pk 	 * A preliminary version of the AD1846 data sheet stated that it
    229  1.1       pk 	 * used an ID field of 0x0B.  The current version, however,
    230  1.1       pk 	 * states that the AD1846 uses ID 0x0A, just like the AD1848K.
    231  1.1       pk 	 *
    232  1.1       pk 	 * this switch statement will need updating as newer clones arrive....
    233  1.1       pk 	 */
    234  1.1       pk 	switch (tmp1 & 0x8f) {
    235  1.1       pk 	case 0x09:
    236  1.1       pk 		sc->chip_name = "AD1848J";
    237  1.1       pk 		break;
    238  1.1       pk 	case 0x0A:
    239  1.1       pk 		sc->chip_name = "AD1848K";
    240  1.1       pk 		break;
    241  1.1       pk #if 0	/* See above */
    242  1.1       pk 	case 0x0B:
    243  1.1       pk 		sc->chip_name = "AD1846";
    244  1.1       pk 		break;
    245  1.1       pk #endif
    246  1.1       pk 	case 0x81:
    247  1.1       pk 		sc->chip_name = "CS4248revB"; /* or CS4231 rev B; see below */
    248  1.1       pk 		break;
    249  1.1       pk 	case 0x89:
    250  1.1       pk 		sc->chip_name = "CS4248";
    251  1.1       pk 		break;
    252  1.1       pk 	case 0x8A:
    253  1.1       pk 		sc->chip_name = "broken"; /* CS4231/AD1845; see below */
    254  1.1       pk 		break;
    255  1.1       pk 	default:
    256  1.1       pk 		sc->chip_name = "unknown";
    257  1.1       pk 		DPRINTF(("ad1848: unknown codec version 0x%02x\n",
    258  1.1       pk 			 tmp1 & 0x8f));
    259  1.1       pk 		break;
    260  1.1       pk 	}
    261  1.1       pk 
    262  1.1       pk 	/*
    263  1.1       pk 	 * The original AD1848/CS4248 has just 16 indirect registers. This
    264  1.1       pk 	 * means that I0 and I16 should return the same value (etc.).
    265  1.1       pk 	 * Ensure that the Mode2 enable bit of I12 is 0. Otherwise this test
    266  1.1       pk 	 * fails with CS4231, AD1845, etc.
    267  1.1       pk 	 */
    268  1.1       pk 	ad_write(sc, SP_MISC_INFO, 0);	/* Mode2 = disabled */
    269  1.1       pk 
    270  1.1       pk 	for (i = 0; i < 16; i++)
    271  1.1       pk 		if ((tmp1 = ad_read(sc, i)) != (tmp2 = ad_read(sc, i + 16))) {
    272  1.1       pk 			DPRINTF(("ad_detect_F(%d/%x/%x)\n", i, tmp1, tmp2));
    273  1.1       pk 			if (i != SP_TEST_AND_INIT) goto bad;
    274  1.1       pk 		}
    275  1.1       pk 
    276  1.1       pk 	/*
    277  1.1       pk 	 * Try to switch the chip to mode2 (CS4231) by setting the MODE2 bit
    278  1.1       pk 	 * The bit 0x80 is always 1 in CS4248, CS4231, and AD1845.
    279  1.1       pk 	 */
    280  1.1       pk 	ad_write(sc, SP_MISC_INFO, MODE2);	/* Set mode2, clear 0x80 */
    281  1.1       pk 
    282  1.1       pk 	tmp1 = ad_read(sc, SP_MISC_INFO);
    283  1.1       pk 	if ((tmp1 & 0xc0) == (0x80 | MODE2)) {
    284  1.1       pk 		/*
    285  1.1       pk 		 *      CS4231 or AD1845 detected - is it?
    286  1.1       pk 		 *
    287  1.1       pk 		 *	Verify that setting I2 doesn't change I18.
    288  1.1       pk 		 */
    289  1.1       pk 		ad_write(sc, 18, 0x88); /* Set I18 to known value */
    290  1.1       pk 
    291  1.1       pk 		ad_write(sc, 2, 0x45);
    292  1.1       pk 		if ((tmp2 = ad_read(sc, 18)) != 0x45) { /* No change -> CS4231? */
    293  1.1       pk 			ad_write(sc, 2, 0xaa);
    294  1.1       pk 			if ((tmp2 = ad_read(sc, 18)) == 0xaa) {     /* Rotten bits? */
    295  1.1       pk 				DPRINTF(("ad_detect_H(%x)\n", tmp2));
    296  1.1       pk 				goto bad;
    297  1.1       pk 			}
    298  1.1       pk 
    299  1.1       pk 			/*
    300  1.1       pk 			 *  It's a CS4231, or another clone with 32 registers.
    301  1.1       pk 			 *  Let's find out which by checking I25.
    302  1.1       pk 			 */
    303  1.1       pk 			if ((tmp1 & 0x8f) == 0x8a) {
    304  1.1       pk 				tmp1 = ad_read(sc, CS_VERSION_ID);
    305  1.1       pk 				switch (tmp1 & 0xe7) {
    306  1.1       pk 				case 0xA0:
    307  1.1       pk 					sc->chip_name = "CS4231A";
    308  1.1       pk 					break;
    309  1.1       pk 				case 0x80:
    310  1.1       pk 					/*  XXX I25 no good, AD1845 same as CS4231 */
    311  1.1       pk 					sc->chip_name = "CS4231 or AD1845";
    312  1.1       pk 					break;
    313  1.1       pk 				case 0x82:
    314  1.1       pk 					sc->chip_name = "CS4232";
    315  1.1       pk 					break;
    316  1.1       pk 				case 0x03:
    317  1.4  hannken 				case 0x83:
    318  1.1       pk 					sc->chip_name = "CS4236/CS4236B";
    319  1.1       pk 					break;
    320  1.1       pk 				}
    321  1.1       pk 			}
    322  1.1       pk 			sc->mode = 2;
    323  1.1       pk 		}
    324  1.1       pk 	}
    325  1.1       pk 
    326  1.1       pk 	/* Wait for 1848 to init */
    327  1.1       pk 	while(ADREAD(sc, AD1848_IADDR) & SP_IN_INIT)
    328  1.1       pk 		;
    329  1.1       pk 
    330  1.1       pk 	/* Wait for 1848 to autocal */
    331  1.1       pk 	ADWRITE(sc, AD1848_IADDR, SP_TEST_AND_INIT);
    332  1.1       pk 	while(ADREAD(sc, AD1848_IDATA) & AUTO_CAL_IN_PROG)
    333  1.1       pk 		;
    334  1.1       pk 
    335  1.1       pk 	return 1;
    336  1.1       pk  bad:
    337  1.1       pk 	return 0;
    338  1.1       pk }
    339  1.1       pk 
    340  1.1       pk /* Unmap the I/O ports */
    341  1.1       pk void
    342  1.1       pk ad1848_isa_unmap(isc)
    343  1.1       pk 	struct ad1848_isa_softc *isc;
    344  1.1       pk {
    345  1.1       pk 	struct ad1848_softc *sc = (struct ad1848_softc *)&isc->sc_ad1848;
    346  1.1       pk 	bus_space_unmap(sc->sc_iot, sc->sc_ioh, AD1848_NPORT);
    347  1.1       pk }
    348  1.1       pk 
    349  1.1       pk /*
    350  1.1       pk  * Attach hardware to driver, attach hardware driver to audio
    351  1.1       pk  * pseudo-device driver .
    352  1.1       pk  */
    353  1.1       pk void
    354  1.1       pk ad1848_isa_attach(isc)
    355  1.1       pk 	struct ad1848_isa_softc *isc;
    356  1.1       pk {
    357  1.1       pk 	struct ad1848_softc *sc = (struct ad1848_softc *)&isc->sc_ad1848;
    358  1.1       pk 
    359  1.1       pk 	sc->sc_readreg = ad1848_isa_read;
    360  1.1       pk 	sc->sc_writereg = ad1848_isa_write;
    361  1.1       pk 
    362  1.6  mycroft 	isc->sc_playrun = 0;
    363  1.6  mycroft 	isc->sc_recrun = 0;
    364  1.1       pk 
    365  1.6  mycroft 	if (isc->sc_playdrq != -1) {
    366  1.6  mycroft 		if (isa_dmamap_create(isc->sc_ic, isc->sc_playdrq, MAX_ISADMA,
    367  1.1       pk 				      BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
    368  1.1       pk 			printf("ad1848_attach: can't create map for drq %d\n",
    369  1.6  mycroft 			       isc->sc_playdrq);
    370  1.1       pk 			return;
    371  1.1       pk 		}
    372  1.1       pk 	}
    373  1.6  mycroft 	if (isc->sc_recdrq != -1 && isc->sc_recdrq != isc->sc_playdrq) {
    374  1.1       pk 		if (isa_dmamap_create(isc->sc_ic, isc->sc_recdrq, MAX_ISADMA,
    375  1.1       pk 				      BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
    376  1.1       pk 			printf("ad1848_attach: can't create map for drq %d\n",
    377  1.1       pk 			       isc->sc_recdrq);
    378  1.1       pk 			return;
    379  1.1       pk 		}
    380  1.1       pk 	}
    381  1.1       pk 
    382  1.1       pk 	ad1848_attach(sc);
    383  1.1       pk }
    384  1.1       pk 
    385  1.1       pk int
    386  1.1       pk ad1848_isa_open(addr, flags)
    387  1.1       pk 	void *addr;
    388  1.1       pk 	int flags;
    389  1.1       pk {
    390  1.1       pk 	struct ad1848_isa_softc *sc = addr;
    391  1.1       pk 
    392  1.3       pk 	DPRINTF(("ad1848_isa_open: sc=%p\n", sc));
    393  1.1       pk 
    394  1.1       pk 	sc->sc_intr = 0;
    395  1.1       pk 
    396  1.1       pk 	return (ad1848_open(&sc->sc_ad1848, flags));
    397  1.1       pk }
    398  1.1       pk 
    399  1.1       pk /*
    400  1.1       pk  * Close function is called at splaudio().
    401  1.1       pk  */
    402  1.1       pk void
    403  1.1       pk ad1848_isa_close(addr)
    404  1.1       pk 	void *addr;
    405  1.1       pk {
    406  1.1       pk 	struct ad1848_isa_softc *sc = addr;
    407  1.1       pk 
    408  1.1       pk 	sc->sc_intr = 0;
    409  1.1       pk 
    410  1.1       pk 	DPRINTF(("ad1848_isa_close: stop DMA\n"));
    411  1.6  mycroft 	if (sc->sc_playrun) {
    412  1.6  mycroft 		isa_dmaabort(sc->sc_ic, sc->sc_playdrq);
    413  1.6  mycroft 		sc->sc_playrun = 0;
    414  1.1       pk 	}
    415  1.6  mycroft 	if (sc->sc_recrun) {
    416  1.1       pk 		isa_dmaabort(sc->sc_ic, sc->sc_recdrq);
    417  1.6  mycroft 		sc->sc_recrun = 0;
    418  1.1       pk 	}
    419  1.1       pk 	ad1848_close(&sc->sc_ad1848);
    420  1.1       pk }
    421  1.1       pk 
    422  1.1       pk int
    423  1.6  mycroft ad1848_isa_trigger_input(addr, start, end, blksize, intr, arg, param)
    424  1.1       pk 	void *addr;
    425  1.6  mycroft 	void *start, *end;
    426  1.6  mycroft 	int blksize;
    427  1.1       pk 	void (*intr) __P((void *));
    428  1.1       pk 	void *arg;
    429  1.6  mycroft 	struct audio_params *param;
    430  1.1       pk {
    431  1.1       pk 	struct ad1848_isa_softc *isc = addr;
    432  1.1       pk 	struct ad1848_softc *sc = (struct ad1848_softc *)&isc->sc_ad1848;
    433  1.6  mycroft 	u_int8_t reg;
    434  1.1       pk 
    435  1.6  mycroft 	isa_dmastart(isc->sc_ic, isc->sc_recdrq, start,
    436  1.6  mycroft 	    (char *)end - (char *)start, NULL, DMAMODE_READ | DMAMODE_LOOP,
    437  1.6  mycroft 	    BUS_DMA_NOWAIT);
    438  1.1       pk 
    439  1.6  mycroft 	isc->sc_recrun = 1;
    440  1.1       pk 	isc->sc_intr = intr;
    441  1.1       pk 	isc->sc_arg = arg;
    442  1.1       pk 
    443  1.6  mycroft 	blksize = (blksize * 8) / (param->precision * param->factor * param->channels) - 1;
    444  1.1       pk 
    445  1.6  mycroft 	if (sc->mode == 2) {
    446  1.6  mycroft 		ad_write(sc, CS_LOWER_REC_CNT, blksize & 0xff);
    447  1.6  mycroft 		ad_write(sc, CS_UPPER_REC_CNT, blksize >> 8);
    448  1.6  mycroft 	} else {
    449  1.6  mycroft 		ad_write(sc, SP_LOWER_BASE_COUNT, blksize & 0xff);
    450  1.6  mycroft 		ad_write(sc, SP_UPPER_BASE_COUNT, blksize >> 8);
    451  1.1       pk 	}
    452  1.1       pk 
    453  1.6  mycroft 	reg = ad_read(sc, SP_INTERFACE_CONFIG);
    454  1.6  mycroft 	ad_write(sc, SP_INTERFACE_CONFIG, CAPTURE_ENABLE|reg);
    455  1.1       pk 
    456  1.6  mycroft 	return (0);
    457  1.1       pk }
    458  1.1       pk 
    459  1.1       pk int
    460  1.6  mycroft ad1848_isa_trigger_output(addr, start, end, blksize, intr, arg, param)
    461  1.1       pk 	void *addr;
    462  1.6  mycroft 	void *start, *end;
    463  1.6  mycroft 	int blksize;
    464  1.1       pk 	void (*intr) __P((void *));
    465  1.1       pk 	void *arg;
    466  1.6  mycroft 	struct audio_params *param;
    467  1.1       pk {
    468  1.1       pk 	struct ad1848_isa_softc *isc = addr;
    469  1.1       pk 	struct ad1848_softc *sc = (struct ad1848_softc *)&isc->sc_ad1848;
    470  1.6  mycroft 	u_int8_t reg;
    471  1.1       pk 
    472  1.6  mycroft 	isa_dmastart(isc->sc_ic, isc->sc_playdrq, start,
    473  1.6  mycroft 	    (char *)end - (char *)start, NULL, DMAMODE_WRITE | DMAMODE_LOOP,
    474  1.6  mycroft 	    BUS_DMA_NOWAIT);
    475  1.1       pk 
    476  1.6  mycroft 	isc->sc_playrun = 1;
    477  1.1       pk 	isc->sc_intr = intr;
    478  1.1       pk 	isc->sc_arg = arg;
    479  1.1       pk 
    480  1.6  mycroft 	blksize = (blksize * 8) / (param->precision * param->factor * param->channels) - 1;
    481  1.1       pk 
    482  1.6  mycroft 	ad_write(sc, SP_LOWER_BASE_COUNT, blksize & 0xff);
    483  1.6  mycroft 	ad_write(sc, SP_UPPER_BASE_COUNT, blksize >> 8);
    484  1.1       pk 
    485  1.6  mycroft 	reg = ad_read(sc, SP_INTERFACE_CONFIG);
    486  1.6  mycroft 	ad_write(sc, SP_INTERFACE_CONFIG, PLAYBACK_ENABLE|reg);
    487  1.1       pk 
    488  1.6  mycroft 	return (0);
    489  1.1       pk }
    490  1.1       pk 
    491  1.1       pk int
    492  1.1       pk ad1848_isa_intr(arg)
    493  1.1       pk 	void *arg;
    494  1.1       pk {
    495  1.1       pk 	struct ad1848_isa_softc *isc = arg;
    496  1.1       pk 	struct ad1848_softc *sc = (struct ad1848_softc *)&isc->sc_ad1848;
    497  1.1       pk 	int retval = 0;
    498  1.1       pk 	u_char status;
    499  1.1       pk 
    500  1.1       pk 	/* Get intr status */
    501  1.1       pk 	status = ADREAD(sc, AD1848_STATUS);
    502  1.1       pk 
    503  1.1       pk #ifdef AUDIO_DEBUG
    504  1.1       pk 	if (ad1848debug > 1)
    505  1.2      jtk 		printf("ad1848_isa_intr: intr=%p status=%x\n", isc->sc_intr, status);
    506  1.1       pk #endif
    507  1.1       pk 	isc->sc_interrupts++;
    508  1.1       pk 
    509  1.1       pk 	/* Handle interrupt */
    510  1.1       pk 	if (isc->sc_intr && (status & INTERRUPT_STATUS)) {
    511  1.1       pk 		(*isc->sc_intr)(isc->sc_arg);
    512  1.1       pk 		retval = 1;
    513  1.1       pk 	}
    514  1.1       pk 
    515  1.1       pk 	/* clear interrupt */
    516  1.1       pk 	if (status & INTERRUPT_STATUS)
    517  1.1       pk 		ADWRITE(sc, AD1848_STATUS, 0);
    518  1.1       pk 
    519  1.1       pk 	return(retval);
    520  1.1       pk }
    521  1.1       pk 
    522  1.1       pk void *
    523  1.5  mycroft ad1848_isa_malloc(addr, direction, size, pool, flags)
    524  1.1       pk 	void *addr;
    525  1.5  mycroft 	int direction;
    526  1.5  mycroft 	size_t size;
    527  1.5  mycroft 	int pool, flags;
    528  1.1       pk {
    529  1.1       pk 	struct ad1848_isa_softc *isc = addr;
    530  1.5  mycroft 	int drq;
    531  1.1       pk 
    532  1.5  mycroft 	if (direction == AUMODE_PLAY)
    533  1.6  mycroft 		drq = isc->sc_playdrq;
    534  1.5  mycroft 	else
    535  1.5  mycroft 		drq = isc->sc_recdrq;
    536  1.5  mycroft 	return (isa_malloc(isc->sc_ic, drq, size, pool, flags));
    537  1.1       pk }
    538  1.1       pk 
    539  1.1       pk void
    540  1.1       pk ad1848_isa_free(addr, ptr, pool)
    541  1.1       pk 	void *addr;
    542  1.1       pk 	void *ptr;
    543  1.1       pk 	int pool;
    544  1.1       pk {
    545  1.1       pk 	isa_free(ptr, pool);
    546  1.1       pk }
    547  1.1       pk 
    548  1.5  mycroft size_t
    549  1.5  mycroft ad1848_isa_round_buffersize(addr, direction, size)
    550  1.1       pk 	void *addr;
    551  1.5  mycroft 	int direction;
    552  1.5  mycroft 	size_t size;
    553  1.1       pk {
    554  1.1       pk 	if (size > MAX_ISADMA)
    555  1.1       pk 		size = MAX_ISADMA;
    556  1.5  mycroft 	return (size);
    557  1.1       pk }
    558  1.1       pk 
    559  1.1       pk int
    560  1.1       pk ad1848_isa_mappage(addr, mem, off, prot)
    561  1.1       pk 	void *addr;
    562  1.1       pk         void *mem;
    563  1.1       pk         int off;
    564  1.1       pk 	int prot;
    565  1.1       pk {
    566  1.1       pk 	return isa_mappage(mem, off, prot);
    567  1.1       pk }
    568  1.1       pk 
    569  1.1       pk int
    570  1.1       pk ad1848_isa_get_props(addr)
    571  1.1       pk 	void *addr;
    572  1.1       pk {
    573  1.1       pk 	struct ad1848_isa_softc *isc = addr;
    574  1.1       pk 
    575  1.1       pk 	return (AUDIO_PROP_MMAP |
    576  1.6  mycroft 		(isc->sc_playdrq != isc->sc_recdrq ? AUDIO_PROP_FULLDUPLEX : 0));
    577  1.1       pk }
    578