Home | History | Annotate | Line # | Download | only in pnpbios
ess_pnpbios.c revision 1.21
      1 /*	$NetBSD: ess_pnpbios.c,v 1.21 2010/05/22 16:35:00 tsutsui 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.21 2010/05/22 16:35:00 tsutsui 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_NEW(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, void *aux)
     66 {
     67 	struct pnpbiosdev_attach_args *aa = aux;
     68 
     69 	if (strcmp(aa->idstr, "ESS0104") && /* 1788 */
     70 	    strcmp(aa->idstr, "ESS0114") && /* 1788 */
     71 	    strcmp(aa->idstr, "CPQAE27") && /* 1788 */
     72 	    strcmp(aa->idstr, "ESS1869") && /* 1869 */
     73 	    strcmp(aa->idstr, "CPQB0AB") && /* 1869 */
     74 	    strcmp(aa->idstr, "CPQB0AC") && /* 1869 */
     75 	    strcmp(aa->idstr, "CPQB0AD") && /* 1869 */
     76 	    strcmp(aa->idstr, "CPQB0F1") && /* 1869 */
     77 	    strcmp(aa->idstr, "ESS1878") && /* 1878 */
     78 	    strcmp(aa->idstr, "ESS1879"))   /* 1879 */
     79 		return (0);
     80 
     81 	return (1);
     82 }
     83 
     84 void
     85 ess_pnpbios_attach(device_t parent, device_t self, void *aux)
     86 {
     87 	struct ess_softc *sc = device_private(self);
     88 	struct pnpbiosdev_attach_args *aa = aux;
     89 
     90 	sc->sc_dev = self;
     91 
     92 	if (pnpbios_io_map(aa->pbt, aa->resc, 0, &sc->sc_iot, &sc->sc_ioh)) {
     93 		aprint_error(": 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 		aprint_error(": 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 		aprint_error(": 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 	aprint_naive("\n");
    124 	aprint_normal("\n");
    125 	pnpbios_print_devres(self, aa);
    126 
    127 	aprint_normal_dev(self, "");
    128 
    129 	if (!essmatch(sc)) {
    130 		aprint_error_dev(self, "essmatch failed\n");
    131 		pnpbios_io_unmap(aa->pbt, aa->resc, 0, sc->sc_iot, sc->sc_ioh);
    132 		return;
    133 	}
    134 
    135 	essattach(sc, 0);
    136 }
    137