1 /* $NetBSD: ess_ofisa.c,v 1.32 2021/01/27 03:10:21 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 *
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: ess_ofisa.c,v 1.32 2021/01/27 03:10:21 thorpej Exp $");
35
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/device.h>
39
40 #include <sys/bus.h>
41 #include <sys/intr.h>
42
43 #include <sys/audioio.h>
44 #include <dev/audio/audio_if.h>
45
46 #include <dev/ofw/openfirm.h>
47 #include <dev/isa/isavar.h>
48 #include <dev/ofisa/ofisavar.h>
49
50 #include <dev/isa/essreg.h>
51 #include <dev/isa/essvar.h>
52
53 int ess_ofisa_match(device_t, cfdata_t, void *);
54 void ess_ofisa_attach(device_t, device_t, void *);
55
56 CFATTACH_DECL_NEW(ess_ofisa, sizeof(struct ess_softc),
57 ess_ofisa_match, ess_ofisa_attach, NULL, NULL);
58
59 static const struct device_compatible_entry compat_data[] = {
60 { .compat = "ESST,es1887-codec" }, /* ESS 1887 */
61 { .compat = "ESST,es1888-codec" }, /* ESS 1888 */
62 { .compat = "ESST,es888-codec" }, /* ESS 888 */
63 DEVICE_COMPAT_EOL
64 };
65
66 int
ess_ofisa_match(device_t parent,cfdata_t cf,void * aux)67 ess_ofisa_match(device_t parent, cfdata_t cf, void *aux)
68 {
69 struct ofisa_attach_args *aa = aux;
70
71 /* beat generic SB */
72 return of_compatible_match(aa->oba.oba_phandle, compat_data) ? 10 : 0;
73 }
74
75 void
ess_ofisa_attach(device_t parent,device_t self,void * aux)76 ess_ofisa_attach(device_t parent, device_t self, void *aux)
77 {
78 struct ess_softc *sc = device_private(self);
79 struct ofisa_attach_args *aa = aux;
80 struct ofisa_reg_desc reg;
81 struct ofisa_intr_desc intr[2];
82 struct ofisa_dma_desc dma[2];
83 int n, ndrq;
84
85 sc->sc_dev = self;
86
87 /*
88 * We're living on an OFW. We have to ask the OFW what our
89 * registers and interrupts properties look like.
90 *
91 * We expect:
92 *
93 * 1 i/o register region
94 * 1 or 2 interrupts
95 * 2 DMA channels
96 */
97
98 n = ofisa_reg_get(aa->oba.oba_phandle, ®, 1);
99 if (n != 1) {
100 aprint_error(": error getting register data\n");
101 return;
102 }
103 if (reg.type != OFISA_REG_TYPE_IO) {
104 aprint_error(": register type not i/o\n");
105 return;
106 }
107 if (reg.len != ESS_NPORT) {
108 aprint_error(": weird register size (%lu, expected %d)\n",
109 (unsigned long)reg.len, ESS_NPORT);
110 return;
111 }
112
113 n = ofisa_intr_get(aa->oba.oba_phandle, intr, 2);
114 if (n == 1) {
115 sc->sc_audio1.irq = intr[0].irq;
116 sc->sc_audio1.ist = intr[0].share;
117 sc->sc_audio2.irq = intr[0].irq;
118 sc->sc_audio2.ist = intr[0].share;
119 } else if (n == 2) {
120 sc->sc_audio1.irq = intr[0].irq;
121 sc->sc_audio1.ist = intr[0].share;
122 sc->sc_audio2.irq = intr[1].irq;
123 sc->sc_audio2.ist = intr[1].share;
124 } else {
125 aprint_error(": error getting interrupt data\n");
126 return;
127 }
128
129 ndrq = ofisa_dma_get(aa->oba.oba_phandle, dma, 2);
130 if (ndrq != 2) {
131 aprint_error(": error getting DMA data\n");
132 return;
133 }
134 sc->sc_audio1.drq = dma[0].drq;
135 sc->sc_audio2.drq = dma[1].drq;
136
137 sc->sc_ic = aa->ic;
138
139 sc->sc_iot = aa->iot;
140 sc->sc_iobase = reg.addr;
141 if (bus_space_map(sc->sc_iot, sc->sc_iobase, reg.len, 0,
142 &sc->sc_ioh)) {
143 aprint_error(": unable to map register space\n");
144 return;
145 }
146
147 /*
148 * The Shark firmware doesn't program the ESS ISA address registers.
149 * Do that here instead of inside essmatch() since we want to defer
150 * to the firmware on other platforms.
151 */
152 if (ess_config_addr(sc))
153 return;
154 if (essmatch(sc) == 0) {
155 aprint_error(": essmatch failed\n");
156 return;
157 }
158
159 ofisa_print_model(self, aa->oba.oba_phandle);
160
161 essattach(sc, 0);
162 }
163