ess_ofisa.c revision 1.2 1 /* $NetBSD: ess_ofisa.c,v 1.2 1998/07/30 21:22:59 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/device.h>
43
44 #include <machine/bus.h>
45 #include <machine/intr.h>
46
47 #include <sys/audioio.h>
48 #include <dev/audio_if.h>
49 #include <dev/mulaw.h>
50
51 #include <dev/ofw/openfirm.h>
52 #include <dev/isa/isavar.h>
53 #include <dev/ofisa/ofisavar.h>
54
55 #include <dev/isa/essreg.h>
56 #include <dev/isa/essvar.h>
57
58 int ess_ofisa_match __P((struct device *, struct cfdata *, void *));
59 void ess_ofisa_attach __P((struct device *, struct device *, void *));
60
61 struct cfattach ess_ofisa_ca = {
62 sizeof(struct ess_softc), ess_ofisa_match, ess_ofisa_attach
63 };
64
65 int
66 ess_ofisa_match(parent, cf, aux)
67 struct device *parent;
68 struct cfdata *cf;
69 void *aux;
70 {
71 struct ofisa_attach_args *aa = aux;
72 const char *compatible_strings[] = {
73 "ESST,es1887-codec", /* ESS 1887 */
74 "ESST,es1888-codec", /* ESS 1888 */
75 "ESST,es888-codec", /* ESS 888 */
76 NULL,
77 };
78 int rv = 0;
79
80 /* XXX table */
81 if (of_compatible(aa->oba.oba_phandle, compatible_strings) != -1) {
82 rv = 10;
83 }
84
85 return (rv);
86 }
87
88 void
89 ess_ofisa_attach(parent, self, aux)
90 struct device *parent, *self;
91 void *aux;
92 {
93 struct ess_softc *sc = (void *)self;
94 struct ofisa_attach_args *aa = aux;
95 struct ofisa_reg_desc reg;
96 struct ofisa_intr_desc intr[2];
97 struct ofisa_dma_desc dma[2];
98 int n, ndrq;
99 char *model;
100
101 /*
102 * We're living on an OFW. We have to ask the OFW what our
103 * registers and interrupts properties look like.
104 *
105 * We expect:
106 *
107 * 1 i/o register region
108 * 2 interrupts
109 * 2 dma channels
110 */
111
112 n = ofisa_reg_get(aa->oba.oba_phandle, ®, 1);
113 if (n != 1) {
114 printf(": error getting register data\n");
115 return;
116 }
117 if (reg.type != OFISA_REG_TYPE_IO) {
118 printf(": register type not i/o\n");
119 return;
120 }
121 if (reg.len != ESS_NPORT) {
122 printf(": weird register size (%lu, expected %d)\n",
123 (unsigned long)reg.len, ESS_NPORT);
124 return;
125 }
126
127 n = ofisa_intr_get(aa->oba.oba_phandle, intr, 2);
128 if (n != 2) {
129 printf(": error getting interrupt data\n");
130 return;
131 }
132 sc->sc_in.irq = intr[0].irq;
133 sc->sc_in.ist = intr[0].share;
134 sc->sc_out.irq = intr[1].irq;
135 sc->sc_out.ist = intr[1].share;
136
137 ndrq = ofisa_dma_get(aa->oba.oba_phandle, dma, 2);
138 if (ndrq != 2) {
139 printf(": error getting DMA data\n");
140 return;
141 }
142 sc->sc_in.drq = dma[0].drq;
143 sc->sc_out.drq = dma[1].drq;
144
145 sc->sc_in.mode = ESS_DMA_SIZE(sc->sc_in.drq);
146 sc->sc_out.mode = ESS_DMA_SIZE(sc->sc_out.drq);
147
148 sc->sc_ic = aa->ic;
149
150 sc->sc_iot = aa->iot;
151 sc->sc_iobase = reg.addr;
152 if (bus_space_map(sc->sc_iot, sc->sc_iobase, reg.len, 0,
153 &sc->sc_ioh)) {
154 printf(": unable to map register space\n");
155 return;
156 }
157
158 printf("ess attach irq i=%d o=%d, drq i=%d o=%d\n",
159 sc->sc_in.irq, sc->sc_out.irq,
160 sc->sc_in.drq, sc->sc_out.drq);
161
162 if (essmatch(sc) == 0) {
163 printf(": essmatch failed\n");
164 return;
165 }
166
167 n = OF_getproplen(aa->oba.oba_phandle, "model");
168 if (n > 0) {
169 model = alloca(n);
170 if (OF_getprop(aa->oba.oba_phandle, "model", model, n) == n)
171 printf(": %s\n%s", model, sc->sc_dev.dv_xname);
172 }
173
174 essattach(sc);
175 }
176