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