wss_acpi.c revision 1.3.2.4 1 1.3.2.4 thorpej /* $NetBSD: wss_acpi.c,v 1.3.2.4 2003/01/15 18:44:15 thorpej Exp $ */
2 1.3.2.2 thorpej
3 1.3.2.2 thorpej /*
4 1.3.2.2 thorpej * Copyright (c) 2002 Jared D. McNeill <jmcneill (at) invisible.ca>
5 1.3.2.2 thorpej * All rights reserved.
6 1.3.2.2 thorpej *
7 1.3.2.2 thorpej * Redistribution and use in source and binary forms, with or without
8 1.3.2.2 thorpej * modification, are permitted provided that the following conditions
9 1.3.2.2 thorpej * are met:
10 1.3.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
11 1.3.2.2 thorpej * notice, this list of conditions and the following disclaimer.
12 1.3.2.2 thorpej * 2. The name of the author may not be used to endorse or promote products
13 1.3.2.2 thorpej * derived from this software without specific prior written permission.
14 1.3.2.2 thorpej *
15 1.3.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 1.3.2.2 thorpej * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 1.3.2.2 thorpej * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 1.3.2.2 thorpej * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 1.3.2.2 thorpej * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
20 1.3.2.2 thorpej * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 1.3.2.2 thorpej * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
22 1.3.2.2 thorpej * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23 1.3.2.2 thorpej * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 1.3.2.2 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 1.3.2.2 thorpej * SUCH DAMAGE.
26 1.3.2.2 thorpej */
27 1.3.2.2 thorpej
28 1.3.2.2 thorpej #include <sys/cdefs.h>
29 1.3.2.4 thorpej __KERNEL_RCSID(0, "$NetBSD: wss_acpi.c,v 1.3.2.4 2003/01/15 18:44:15 thorpej Exp $");
30 1.3.2.2 thorpej
31 1.3.2.2 thorpej #include <sys/param.h>
32 1.3.2.2 thorpej #include <sys/systm.h>
33 1.3.2.2 thorpej #include <sys/errno.h>
34 1.3.2.2 thorpej #include <sys/ioctl.h>
35 1.3.2.2 thorpej #include <sys/syslog.h>
36 1.3.2.2 thorpej #include <sys/device.h>
37 1.3.2.2 thorpej #include <sys/proc.h>
38 1.3.2.2 thorpej
39 1.3.2.2 thorpej #include <machine/bus.h>
40 1.3.2.2 thorpej
41 1.3.2.2 thorpej #include <sys/audioio.h>
42 1.3.2.2 thorpej #include <dev/audio_if.h>
43 1.3.2.2 thorpej
44 1.3.2.2 thorpej #include <dev/isa/isavar.h>
45 1.3.2.2 thorpej #include <dev/isa/isadmavar.h>
46 1.3.2.2 thorpej
47 1.3.2.2 thorpej #include <dev/acpi/acpica.h>
48 1.3.2.2 thorpej #include <dev/acpi/acpireg.h>
49 1.3.2.2 thorpej #include <dev/acpi/acpivar.h>
50 1.3.2.2 thorpej
51 1.3.2.2 thorpej #include <dev/isa/ad1848var.h>
52 1.3.2.2 thorpej #include <dev/isa/wssreg.h>
53 1.3.2.2 thorpej #include <dev/isa/wssvar.h>
54 1.3.2.2 thorpej
55 1.3.2.2 thorpej int wss_acpi_match(struct device *, struct cfdata *, void *);
56 1.3.2.2 thorpej void wss_acpi_attach(struct device *, struct device *, void *);
57 1.3.2.2 thorpej
58 1.3.2.2 thorpej CFATTACH_DECL(wss_acpi, sizeof(struct wss_softc), wss_acpi_match,
59 1.3.2.2 thorpej wss_acpi_attach, NULL, NULL);
60 1.3.2.2 thorpej
61 1.3.2.2 thorpej /*
62 1.3.2.2 thorpej * Supported device IDs
63 1.3.2.2 thorpej */
64 1.3.2.2 thorpej
65 1.3.2.4 thorpej struct wss_acpi_hint {
66 1.3.2.4 thorpej char idstr[8];
67 1.3.2.4 thorpej int io_region_idx_ad1848; /* which region index is the DAC? */
68 1.3.2.4 thorpej int io_region_idx_opl; /* which region index is the OPL? */
69 1.3.2.4 thorpej int offset_ad1848; /* offset from start of DAC region */
70 1.3.2.2 thorpej };
71 1.3.2.2 thorpej
72 1.3.2.4 thorpej struct wss_acpi_hint wss_acpi_hints[] = {
73 1.3.2.4 thorpej { "NMX2210", 1, 2, WSS_CODEC },
74 1.3.2.4 thorpej { "CSC0000", 0, 1, 0 }, /* Dell Latitude CPi */
75 1.3.2.4 thorpej { "CSC0100", 0, 1, 0 }, /* CS4610 with CS4236 codec */
76 1.3.2.4 thorpej { { 0 }, 0, 0, 0 }
77 1.3.2.4 thorpej };
78 1.3.2.4 thorpej
79 1.3.2.4 thorpej int wss_acpi_hints_index (const char *);
80 1.3.2.4 thorpej
81 1.3.2.4 thorpej int
82 1.3.2.4 thorpej wss_acpi_hints_index(idstr)
83 1.3.2.4 thorpej const char *idstr;
84 1.3.2.4 thorpej {
85 1.3.2.4 thorpej int idx = 0;
86 1.3.2.4 thorpej
87 1.3.2.4 thorpej while (wss_acpi_hints[idx].idstr[0] != 0) {
88 1.3.2.4 thorpej if (!strcmp(wss_acpi_hints[idx].idstr, idstr))
89 1.3.2.4 thorpej return idx;
90 1.3.2.4 thorpej ++idx;
91 1.3.2.4 thorpej }
92 1.3.2.4 thorpej
93 1.3.2.4 thorpej return -1;
94 1.3.2.4 thorpej }
95 1.3.2.4 thorpej
96 1.3.2.2 thorpej /*
97 1.3.2.2 thorpej * wss_acpi_match: autoconf(9) match routine
98 1.3.2.2 thorpej */
99 1.3.2.2 thorpej int
100 1.3.2.2 thorpej wss_acpi_match(struct device *parent, struct cfdata *match, void *aux)
101 1.3.2.2 thorpej {
102 1.3.2.2 thorpej struct acpi_attach_args *aa = aux;
103 1.3.2.2 thorpej
104 1.3.2.4 thorpej if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE ||
105 1.3.2.4 thorpej wss_acpi_hints_index(aa->aa_node->ad_devinfo.HardwareId) == -1)
106 1.3.2.4 thorpej return (0);
107 1.3.2.2 thorpej
108 1.3.2.4 thorpej return (1);
109 1.3.2.2 thorpej }
110 1.3.2.2 thorpej
111 1.3.2.2 thorpej /*
112 1.3.2.2 thorpej * wss_acpi_attach: autoconf(9) attach routine
113 1.3.2.2 thorpej */
114 1.3.2.2 thorpej void
115 1.3.2.2 thorpej wss_acpi_attach(struct device *parent, struct device *self, void *aux)
116 1.3.2.2 thorpej {
117 1.3.2.2 thorpej struct wss_softc *sc = (struct wss_softc *)self;
118 1.3.2.2 thorpej struct acpi_attach_args *aa = aux;
119 1.3.2.2 thorpej struct acpi_resources res;
120 1.3.2.2 thorpej struct acpi_io *dspio, *oplio;
121 1.3.2.2 thorpej struct acpi_irq *irq;
122 1.3.2.2 thorpej struct acpi_drq *playdrq, *recdrq;
123 1.3.2.2 thorpej struct audio_attach_args arg;
124 1.3.2.2 thorpej ACPI_STATUS rv;
125 1.3.2.4 thorpej struct wss_acpi_hint *wah;
126 1.3.2.2 thorpej
127 1.3.2.2 thorpej printf(": NeoMagic 256AV audio\n");
128 1.3.2.2 thorpej
129 1.3.2.4 thorpej wah = &wss_acpi_hints[
130 1.3.2.4 thorpej wss_acpi_hints_index(aa->aa_node->ad_devinfo.HardwareId)];
131 1.3.2.4 thorpej
132 1.3.2.2 thorpej /* Parse our resources */
133 1.3.2.2 thorpej rv = acpi_resource_parse(&sc->sc_ad1848.sc_ad1848.sc_dev,
134 1.3.2.2 thorpej aa->aa_node, &res, &acpi_resource_parse_ops_default);
135 1.3.2.2 thorpej if (rv != AE_OK) {
136 1.3.2.2 thorpej printf("%s: unable to parse resources\n",
137 1.3.2.2 thorpej sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
138 1.3.2.2 thorpej return;
139 1.3.2.2 thorpej }
140 1.3.2.2 thorpej
141 1.3.2.2 thorpej /* Find and map our i/o registers */
142 1.3.2.2 thorpej sc->sc_iot = aa->aa_iot;
143 1.3.2.4 thorpej dspio = acpi_res_io(&res, wah->io_region_idx_ad1848);
144 1.3.2.4 thorpej oplio = acpi_res_io(&res, wah->io_region_idx_opl);
145 1.3.2.2 thorpej if (dspio == NULL || oplio == NULL) {
146 1.3.2.2 thorpej printf("%s: unable to find i/o registers resource\n",
147 1.3.2.2 thorpej sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
148 1.3.2.2 thorpej return;
149 1.3.2.2 thorpej }
150 1.3.2.2 thorpej if (bus_space_map(sc->sc_iot, dspio->ar_base, dspio->ar_length,
151 1.3.2.2 thorpej 0, &sc->sc_ioh) != 0) {
152 1.3.2.2 thorpej printf("%s: unable to map i/o registers\n",
153 1.3.2.2 thorpej sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
154 1.3.2.2 thorpej return;
155 1.3.2.2 thorpej }
156 1.3.2.2 thorpej if (bus_space_map(sc->sc_iot, oplio->ar_base, oplio->ar_length,
157 1.3.2.2 thorpej 0, &sc->sc_opl_ioh) != 0) {
158 1.3.2.2 thorpej printf("%s: unable to map opl i/o registers\n",
159 1.3.2.2 thorpej sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
160 1.3.2.2 thorpej return;
161 1.3.2.2 thorpej }
162 1.3.2.2 thorpej
163 1.3.2.2 thorpej sc->wss_ic = aa->aa_ic;
164 1.3.2.2 thorpej
165 1.3.2.2 thorpej /* Find our IRQ */
166 1.3.2.2 thorpej irq = acpi_res_irq(&res, 0);
167 1.3.2.2 thorpej if (irq == NULL) {
168 1.3.2.2 thorpej printf("%s: unable to find irq resource\n",
169 1.3.2.2 thorpej sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
170 1.3.2.2 thorpej /* XXX bus_space_unmap */
171 1.3.2.2 thorpej return;
172 1.3.2.2 thorpej }
173 1.3.2.2 thorpej sc->wss_irq = irq->ar_irq;
174 1.3.2.2 thorpej
175 1.3.2.2 thorpej /* Find our playback and record DRQs */
176 1.3.2.2 thorpej playdrq = acpi_res_drq(&res, 0);
177 1.3.2.2 thorpej recdrq = acpi_res_drq(&res, 1);
178 1.3.2.2 thorpej if (playdrq == NULL || recdrq == NULL) {
179 1.3.2.2 thorpej printf("%s: unable to find drq resources\n",
180 1.3.2.2 thorpej sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
181 1.3.2.2 thorpej /* XXX bus_space_unmap */
182 1.3.2.2 thorpej return;
183 1.3.2.2 thorpej }
184 1.3.2.2 thorpej sc->wss_playdrq = playdrq->ar_drq;
185 1.3.2.2 thorpej sc->wss_recdrq = recdrq->ar_drq;
186 1.3.2.2 thorpej
187 1.3.2.2 thorpej sc->sc_ad1848.sc_ad1848.sc_iot = sc->sc_iot;
188 1.3.2.4 thorpej bus_space_subregion(sc->sc_iot, sc->sc_ioh, wah->offset_ad1848, 4,
189 1.3.2.2 thorpej &sc->sc_ad1848.sc_ad1848.sc_ioh);
190 1.3.2.2 thorpej
191 1.3.2.2 thorpej /* Look for the ad1848 */
192 1.3.2.2 thorpej if (!ad1848_isa_probe(&sc->sc_ad1848)) {
193 1.3.2.2 thorpej printf("%s: ad1848 probe failed\n",
194 1.3.2.2 thorpej sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
195 1.3.2.2 thorpej /* XXX cleanup */
196 1.3.2.2 thorpej return;
197 1.3.2.2 thorpej }
198 1.3.2.2 thorpej
199 1.3.2.2 thorpej printf("%s", sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
200 1.3.2.2 thorpej /* Attach our wss device */
201 1.3.2.2 thorpej wssattach(sc);
202 1.3.2.2 thorpej
203 1.3.2.2 thorpej arg.type = AUDIODEV_TYPE_OPL;
204 1.3.2.2 thorpej arg.hwif = 0;
205 1.3.2.2 thorpej arg.hdl = 0;
206 1.3.2.2 thorpej config_found(self, &arg, audioprint);
207 1.3.2.2 thorpej }
208