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