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