Home | History | Annotate | Line # | Download | only in pnpbios
ess_pnpbios.c revision 1.17.14.2
      1 /*	$NetBSD: ess_pnpbios.c,v 1.17.14.2 2009/07/23 23:31:36 jym Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Nathan J. Williams.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 __KERNEL_RCSID(0, "$NetBSD: ess_pnpbios.c,v 1.17.14.2 2009/07/23 23:31:36 jym Exp $");
     34 
     35 #include <sys/param.h>
     36 #include <sys/systm.h>
     37 #include <sys/errno.h>
     38 #include <sys/ioctl.h>
     39 #include <sys/syslog.h>
     40 #include <sys/device.h>
     41 #include <sys/proc.h>
     42 
     43 #include <machine/bus.h>
     44 
     45 #include <sys/audioio.h>
     46 #include <dev/audio_if.h>
     47 #include <dev/midi_if.h>
     48 #include <dev/mulaw.h>
     49 
     50 #include <dev/isa/isavar.h>
     51 #include <dev/isa/isadmavar.h>
     52 
     53 #include <i386/pnpbios/pnpbiosvar.h>
     54 
     55 #include <dev/isa/essreg.h>
     56 #include <dev/isa/essvar.h>
     57 
     58 int ess_pnpbios_match(device_t, cfdata_t, void *);
     59 void ess_pnpbios_attach(device_t, device_t, void *);
     60 
     61 CFATTACH_DECL(ess_pnpbios, sizeof(struct ess_softc),
     62     ess_pnpbios_match, ess_pnpbios_attach, NULL, NULL);
     63 
     64 int
     65 ess_pnpbios_match(device_t parent, cfdata_t match,
     66     void *aux)
     67 {
     68 	struct pnpbiosdev_attach_args *aa = aux;
     69 
     70 	if (strcmp(aa->idstr, "ESS0104") && /* 1788 */
     71 	    strcmp(aa->idstr, "ESS0114") && /* 1788 */
     72 	    strcmp(aa->idstr, "CPQAE27") && /* 1788 */
     73 	    strcmp(aa->idstr, "ESS1869") && /* 1869 */
     74 	    strcmp(aa->idstr, "CPQB0AB") && /* 1869 */
     75 	    strcmp(aa->idstr, "CPQB0AC") && /* 1869 */
     76 	    strcmp(aa->idstr, "CPQB0AD") && /* 1869 */
     77 	    strcmp(aa->idstr, "CPQB0F1") && /* 1869 */
     78 	    strcmp(aa->idstr, "ESS1878") && /* 1878 */
     79 	    strcmp(aa->idstr, "ESS1879"))   /* 1879 */
     80 		return (0);
     81 
     82 	return (1);
     83 }
     84 
     85 void
     86 ess_pnpbios_attach(device_t parent, device_t self,
     87     void *aux)
     88 {
     89 	struct ess_softc *sc = device_private(self);
     90 	struct pnpbiosdev_attach_args *aa = aux;
     91 
     92 	if (pnpbios_io_map(aa->pbt, aa->resc, 0, &sc->sc_iot, &sc->sc_ioh)) {
     93 		printf(": can't map i/o space\n");
     94 		return;
     95 	}
     96 
     97 	sc->sc_ic = aa->ic;
     98 
     99 	/* XXX These are only for setting chip configuration registers. */
    100 	pnpbios_getiobase(aa->pbt, aa->resc, 0, 0, &sc->sc_iobase);
    101 
    102 	sc->sc_audio1.ist = IST_EDGE;
    103 	sc->sc_audio2.ist = IST_EDGE;
    104 
    105 	if (pnpbios_getirqnum(aa->pbt, aa->resc, 0, &sc->sc_audio1.irq,
    106 	    NULL)) {
    107 		printf(": can't get IRQ\n");
    108 		return;
    109 	}
    110 
    111 	if (pnpbios_getirqnum(aa->pbt, aa->resc, 1, &sc->sc_audio2.irq,
    112 	    NULL))
    113 		sc->sc_audio2.irq = -1;
    114 
    115 	if (pnpbios_getdmachan(aa->pbt, aa->resc, 0, &sc->sc_audio1.drq)) {
    116 		printf(": can't get DMA channel\n");
    117 		return;
    118 	}
    119 
    120 	if (pnpbios_getdmachan(aa->pbt, aa->resc, 1, &sc->sc_audio2.drq))
    121 		sc->sc_audio2.drq = -1;
    122 
    123 	printf("\n");
    124 	pnpbios_print_devres(self, aa);
    125 
    126 	printf("%s", device_xname(self));
    127 
    128 	if (!essmatch(sc)) {
    129 		aprint_error_dev(&sc->sc_dev, "essmatch failed\n");
    130 		pnpbios_io_unmap(aa->pbt, aa->resc, 0, sc->sc_iot, sc->sc_ioh);
    131 		return;
    132 	}
    133 
    134 	essattach(sc, 0);
    135 }
    136