wss_acpi.c revision 1.3.2.2 1 1.3.2.2 thorpej /* $NetBSD: wss_acpi.c,v 1.3.2.2 2002/12/29 20:45:31 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.2 thorpej __KERNEL_RCSID(0, "$NetBSD: wss_acpi.c,v 1.3.2.2 2002/12/29 20:45:31 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 void wss_acpi_config_interrupts(struct device *);
59 1.3.2.2 thorpej
60 1.3.2.2 thorpej CFATTACH_DECL(wss_acpi, sizeof(struct wss_softc), wss_acpi_match,
61 1.3.2.2 thorpej wss_acpi_attach, NULL, NULL);
62 1.3.2.2 thorpej
63 1.3.2.2 thorpej /*
64 1.3.2.2 thorpej * Supported device IDs
65 1.3.2.2 thorpej */
66 1.3.2.2 thorpej
67 1.3.2.2 thorpej static const char * const wss_acpi_ids[] = {
68 1.3.2.2 thorpej "CSC0100", /* NeoMagic 256AV with CS4232 codec */
69 1.3.2.2 thorpej NULL
70 1.3.2.2 thorpej };
71 1.3.2.2 thorpej
72 1.3.2.2 thorpej /*
73 1.3.2.2 thorpej * wss_acpi_match: autoconf(9) match routine
74 1.3.2.2 thorpej */
75 1.3.2.2 thorpej int
76 1.3.2.2 thorpej wss_acpi_match(struct device *parent, struct cfdata *match, void *aux)
77 1.3.2.2 thorpej {
78 1.3.2.2 thorpej struct acpi_attach_args *aa = aux;
79 1.3.2.2 thorpej const char *id;
80 1.3.2.2 thorpej int i;
81 1.3.2.2 thorpej
82 1.3.2.2 thorpej if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
83 1.3.2.2 thorpej return 0;
84 1.3.2.2 thorpej
85 1.3.2.2 thorpej for (i = 0; (id = wss_acpi_ids[i]) != NULL; ++i) {
86 1.3.2.2 thorpej if (strcmp(aa->aa_node->ad_devinfo.HardwareId, id) == 0)
87 1.3.2.2 thorpej return 1;
88 1.3.2.2 thorpej }
89 1.3.2.2 thorpej
90 1.3.2.2 thorpej /* No matches found */
91 1.3.2.2 thorpej return 0;
92 1.3.2.2 thorpej }
93 1.3.2.2 thorpej
94 1.3.2.2 thorpej /*
95 1.3.2.2 thorpej * wss_acpi_attach: autoconf(9) attach routine
96 1.3.2.2 thorpej */
97 1.3.2.2 thorpej void
98 1.3.2.2 thorpej wss_acpi_attach(struct device *parent, struct device *self, void *aux)
99 1.3.2.2 thorpej {
100 1.3.2.2 thorpej struct wss_softc *sc = (struct wss_softc *)self;
101 1.3.2.2 thorpej struct acpi_attach_args *aa = aux;
102 1.3.2.2 thorpej struct acpi_resources res;
103 1.3.2.2 thorpej struct acpi_io *dspio, *oplio;
104 1.3.2.2 thorpej struct acpi_irq *irq;
105 1.3.2.2 thorpej struct acpi_drq *playdrq, *recdrq;
106 1.3.2.2 thorpej struct audio_attach_args arg;
107 1.3.2.2 thorpej ACPI_STATUS rv;
108 1.3.2.2 thorpej
109 1.3.2.2 thorpej printf(": NeoMagic 256AV audio\n");
110 1.3.2.2 thorpej
111 1.3.2.2 thorpej /* Parse our resources */
112 1.3.2.2 thorpej rv = acpi_resource_parse(&sc->sc_ad1848.sc_ad1848.sc_dev,
113 1.3.2.2 thorpej aa->aa_node, &res, &acpi_resource_parse_ops_default);
114 1.3.2.2 thorpej if (rv != AE_OK) {
115 1.3.2.2 thorpej printf("%s: unable to parse resources\n",
116 1.3.2.2 thorpej sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
117 1.3.2.2 thorpej return;
118 1.3.2.2 thorpej }
119 1.3.2.2 thorpej
120 1.3.2.2 thorpej /* Find and map our i/o registers */
121 1.3.2.2 thorpej sc->sc_iot = aa->aa_iot;
122 1.3.2.2 thorpej dspio = acpi_res_io(&res, 0);
123 1.3.2.2 thorpej oplio = acpi_res_io(&res, 1);
124 1.3.2.2 thorpej if (dspio == NULL || oplio == NULL) {
125 1.3.2.2 thorpej printf("%s: unable to find i/o registers resource\n",
126 1.3.2.2 thorpej sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
127 1.3.2.2 thorpej return;
128 1.3.2.2 thorpej }
129 1.3.2.2 thorpej if (bus_space_map(sc->sc_iot, dspio->ar_base, dspio->ar_length,
130 1.3.2.2 thorpej 0, &sc->sc_ioh) != 0) {
131 1.3.2.2 thorpej printf("%s: unable to map i/o registers\n",
132 1.3.2.2 thorpej sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
133 1.3.2.2 thorpej return;
134 1.3.2.2 thorpej }
135 1.3.2.2 thorpej if (bus_space_map(sc->sc_iot, oplio->ar_base, oplio->ar_length,
136 1.3.2.2 thorpej 0, &sc->sc_opl_ioh) != 0) {
137 1.3.2.2 thorpej printf("%s: unable to map opl i/o registers\n",
138 1.3.2.2 thorpej sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
139 1.3.2.2 thorpej return;
140 1.3.2.2 thorpej }
141 1.3.2.2 thorpej
142 1.3.2.2 thorpej sc->wss_ic = aa->aa_ic;
143 1.3.2.2 thorpej
144 1.3.2.2 thorpej /* Find our IRQ */
145 1.3.2.2 thorpej irq = acpi_res_irq(&res, 0);
146 1.3.2.2 thorpej if (irq == NULL) {
147 1.3.2.2 thorpej printf("%s: unable to find irq resource\n",
148 1.3.2.2 thorpej sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
149 1.3.2.2 thorpej /* XXX bus_space_unmap */
150 1.3.2.2 thorpej return;
151 1.3.2.2 thorpej }
152 1.3.2.2 thorpej sc->wss_irq = irq->ar_irq;
153 1.3.2.2 thorpej
154 1.3.2.2 thorpej /* Find our playback and record DRQs */
155 1.3.2.2 thorpej playdrq = acpi_res_drq(&res, 0);
156 1.3.2.2 thorpej recdrq = acpi_res_drq(&res, 1);
157 1.3.2.2 thorpej if (playdrq == NULL || recdrq == NULL) {
158 1.3.2.2 thorpej printf("%s: unable to find drq resources\n",
159 1.3.2.2 thorpej sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
160 1.3.2.2 thorpej /* XXX bus_space_unmap */
161 1.3.2.2 thorpej return;
162 1.3.2.2 thorpej }
163 1.3.2.2 thorpej sc->wss_playdrq = playdrq->ar_drq;
164 1.3.2.2 thorpej sc->wss_recdrq = recdrq->ar_drq;
165 1.3.2.2 thorpej
166 1.3.2.2 thorpej sc->sc_ad1848.sc_ad1848.sc_iot = sc->sc_iot;
167 1.3.2.2 thorpej bus_space_subregion(sc->sc_iot, sc->sc_ioh, 0, 4,
168 1.3.2.2 thorpej &sc->sc_ad1848.sc_ad1848.sc_ioh);
169 1.3.2.2 thorpej
170 1.3.2.2 thorpej /* Look for the ad1848 */
171 1.3.2.2 thorpej if (!ad1848_isa_probe(&sc->sc_ad1848)) {
172 1.3.2.2 thorpej printf("%s: ad1848 probe failed\n",
173 1.3.2.2 thorpej sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
174 1.3.2.2 thorpej /* XXX cleanup */
175 1.3.2.2 thorpej return;
176 1.3.2.2 thorpej }
177 1.3.2.2 thorpej
178 1.3.2.2 thorpej printf("%s", sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
179 1.3.2.2 thorpej /* Attach our wss device */
180 1.3.2.2 thorpej wssattach(sc);
181 1.3.2.2 thorpej
182 1.3.2.2 thorpej arg.type = AUDIODEV_TYPE_OPL;
183 1.3.2.2 thorpej arg.hwif = 0;
184 1.3.2.2 thorpej arg.hdl = 0;
185 1.3.2.2 thorpej config_found(self, &arg, audioprint);
186 1.3.2.2 thorpej }
187