xref: /netbsd-src/sys/arch/i386/pnpbios/ess_pnpbios.c (revision 274254cdae52594c1aa480a736aef78313d15c9c)
1 /*	$NetBSD: ess_pnpbios.c,v 1.17 2008/04/28 20:23:25 martin 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 2008/04/28 20:23:25 martin 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(struct device *, struct cfdata *, void *);
59 void ess_pnpbios_attach(struct device *, struct device *, 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(struct device *parent, struct cfdata *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, "ESS1879"))   /* 1879 */
79 		return (0);
80 
81 	return (1);
82 }
83 
84 void
85 ess_pnpbios_attach(struct device *parent, struct device *self,
86     void *aux)
87 {
88 	struct ess_softc *sc = (void *)self;
89 	struct pnpbiosdev_attach_args *aa = aux;
90 
91 	if (pnpbios_io_map(aa->pbt, aa->resc, 0, &sc->sc_iot, &sc->sc_ioh)) {
92 		printf(": can't map i/o space\n");
93 		return;
94 	}
95 
96 	sc->sc_ic = aa->ic;
97 
98 	/* XXX These are only for setting chip configuration registers. */
99 	pnpbios_getiobase(aa->pbt, aa->resc, 0, 0, &sc->sc_iobase);
100 
101 	sc->sc_audio1.ist = IST_EDGE;
102 	sc->sc_audio2.ist = IST_EDGE;
103 
104 	if (pnpbios_getirqnum(aa->pbt, aa->resc, 0, &sc->sc_audio1.irq,
105 	    NULL)) {
106 		printf(": can't get IRQ\n");
107 		return;
108 	}
109 
110 	if (pnpbios_getirqnum(aa->pbt, aa->resc, 1, &sc->sc_audio2.irq,
111 	    NULL))
112 		sc->sc_audio2.irq = -1;
113 
114 	if (pnpbios_getdmachan(aa->pbt, aa->resc, 0, &sc->sc_audio1.drq)) {
115 		printf(": can't get DMA channel\n");
116 		return;
117 	}
118 
119 	if (pnpbios_getdmachan(aa->pbt, aa->resc, 1, &sc->sc_audio2.drq))
120 		sc->sc_audio2.drq = -1;
121 
122 	printf("\n");
123 	pnpbios_print_devres(self, aa);
124 
125 	printf("%s", device_xname(self));
126 
127 	if (!essmatch(sc)) {
128 		aprint_error_dev(&sc->sc_dev, "essmatch failed\n");
129 		pnpbios_io_unmap(aa->pbt, aa->resc, 0, sc->sc_iot, sc->sc_ioh);
130 		return;
131 	}
132 
133 	essattach(sc, 0);
134 }
135