xref: /netbsd/sys/arch/i386/pnpbios/ym_pnpbios.c (revision c4a72b64)
1 /* $NetBSD: ym_pnpbios.c,v 1.9 2002/10/02 05:47:18 thorpej Exp $ */
2 /*
3  * Copyright (c) 1999
4  *	Matthias Drochner.  All rights reserved.
5  *	Soren S. Jorvang.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions, and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: ym_pnpbios.c,v 1.9 2002/10/02 05:47:18 thorpej Exp $");
31 
32 #include "mpu_ym.h"
33 
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/errno.h>
37 #include <sys/ioctl.h>
38 #include <sys/syslog.h>
39 #include <sys/device.h>
40 #include <sys/proc.h>
41 
42 #include <machine/bus.h>
43 
44 #include <sys/audioio.h>
45 #include <dev/audio_if.h>
46 #include <dev/midi_if.h>
47 #include <dev/mulaw.h>
48 
49 #include <dev/isa/isavar.h>
50 #include <dev/isa/isadmavar.h>
51 
52 #include <i386/pnpbios/pnpbiosvar.h>
53 
54 #include <dev/ic/ad1848reg.h>
55 #include <dev/isa/ad1848var.h>
56 
57 #include <dev/ic/cs4231reg.h>
58 #include <dev/isa/cs4231var.h>
59 
60 #include <dev/ic/opl3sa3reg.h>
61 #include <dev/isa/wssreg.h>
62 #include <dev/isa/ymvar.h>
63 
64 int ym_pnpbios_match __P((struct device *, struct cfdata *, void *));
65 void ym_pnpbios_attach __P((struct device *, struct device *, void *));
66 
67 CFATTACH_DECL(ym_pnpbios, sizeof(struct ym_softc),
68     ym_pnpbios_match, ym_pnpbios_attach, NULL, NULL);
69 
70 int
71 ym_pnpbios_match(parent, match, aux)
72 	struct device *parent;
73 	struct cfdata *match;
74 	void *aux;
75 {
76 	struct pnpbiosdev_attach_args *aa = aux;
77 
78 	if (strcmp(aa->idstr, "YMH0021"))
79 		return 0;
80 
81 	return 1;
82 }
83 
84 void
85 ym_pnpbios_attach(parent, self, aux)
86 	struct device *parent, *self;
87 	void *aux;
88 {
89 	struct ym_softc *sc = (void *)self;
90 	struct ad1848_softc *ac = &sc->sc_ad1848.sc_ad1848;
91 	struct pnpbiosdev_attach_args *aa = aux;
92 
93 	if (pnpbios_io_map(aa->pbt, aa->resc, 0,
94 				&sc->sc_iot, &sc->sc_sb_ioh) != 0) {
95 		printf(": can't map sb i/o space\n");
96 		return;
97 	}
98 	if (pnpbios_io_map(aa->pbt, aa->resc, 1,
99 				&sc->sc_iot, &sc->sc_ioh) != 0) {
100 		printf(": can't map sb i/o space\n");
101 		return;
102 	}
103 	if (pnpbios_io_map(aa->pbt, aa->resc, 2,
104 				&sc->sc_iot, &sc->sc_opl_ioh) != 0) {
105 		printf(": can't map opl i/o space\n");
106 		return;
107 	}
108 #if NMPU_YM > 0
109 	if (pnpbios_io_map(aa->pbt, aa->resc, 3,
110 				&sc->sc_iot, &sc->sc_mpu_ioh) != 0) {
111 		printf(": can't map mpu i/o space\n");
112 		return;
113 	}
114 #endif
115 	if (pnpbios_io_map(aa->pbt, aa->resc, 4,
116 				&sc->sc_iot, &sc->sc_controlioh) != 0) {
117 		printf(": can't map control i/o space\n");
118 		return;
119 	}
120 
121 	sc->sc_ic = aa->ic;
122 
123 	if (pnpbios_getirqnum(aa->pbt, aa->resc, 0, &sc->ym_irq, NULL)) {
124 		printf(": can't get IRQ\n");
125 		return;
126 	}
127 
128 	if (pnpbios_getdmachan(aa->pbt, aa->resc, 0, &sc->ym_playdrq)) {
129 		printf(": can't get DMA channel\n");
130 		return;
131 	}
132 	if (pnpbios_getdmachan(aa->pbt, aa->resc, 1, &sc->ym_recdrq))
133 		sc->ym_recdrq = sc->ym_playdrq;	/* half-duplex mode */
134 
135 	printf("\n");
136 	pnpbios_print_devres(self, aa);
137 
138 	printf("%s", self->dv_xname);
139 
140 	ac->sc_iot = sc->sc_iot;
141 	if (bus_space_subregion(sc->sc_iot, sc->sc_ioh, WSS_CODEC, AD1848_NPORT,
142 	    &ac->sc_ioh)) {
143 		printf("%s: bus_space_subregion failed\n", self->dv_xname);
144 		return;
145 	}
146 	ac->mode = 2;
147 	ac->MCE_bit = MODE_CHANGE_ENABLE;
148 
149 	sc->sc_ad1848.sc_ic  = sc->sc_ic;
150 
151 	ym_attach(sc);
152 }
153