atppc_acpi.c revision 1.13 1 /* $NetBSD: atppc_acpi.c,v 1.13 2008/04/16 09:39:01 cegger Exp $ */
2
3 /*-
4 * Copyright (c) 2004 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jaromir Dolecek.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: atppc_acpi.c,v 1.13 2008/04/16 09:39:01 cegger Exp $");
41
42 #include "opt_atppc.h"
43
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/errno.h>
47 #include <sys/ioctl.h>
48 #include <sys/syslog.h>
49 #include <sys/device.h>
50 #include <sys/proc.h>
51 #include <sys/termios.h>
52
53 #include <sys/bus.h>
54
55 #include <dev/isa/isavar.h>
56 #include <dev/isa/isadmavar.h>
57
58 #include <dev/acpi/acpica.h>
59 #include <dev/acpi/acpireg.h>
60 #include <dev/acpi/acpivar.h>
61
62 #include <dev/ic/atppcvar.h>
63 #include <dev/isa/atppc_isadma.h>
64
65 static int atppc_acpi_match(device_t, cfdata_t, void *);
66 static void atppc_acpi_attach(device_t, device_t, void *);
67
68 struct atppc_acpi_softc {
69 struct atppc_softc sc_atppc;
70
71 isa_chipset_tag_t sc_ic;
72 int sc_drq;
73 };
74
75 CFATTACH_DECL_NEW(atppc_acpi, sizeof(struct atppc_acpi_softc), atppc_acpi_match,
76 atppc_acpi_attach, NULL, NULL);
77
78 /*
79 * Supported device IDs
80 */
81
82 static const char * const atppc_acpi_ids[] = {
83 "PNP04??", /* Standard AT printer port */
84 NULL
85 };
86
87 static int atppc_acpi_dma_start(struct atppc_softc *, void *, u_int,
88 u_int8_t);
89 static int atppc_acpi_dma_finish(struct atppc_softc *);
90 static int atppc_acpi_dma_abort(struct atppc_softc *);
91 static int atppc_acpi_dma_malloc(device_t, void **, bus_addr_t *,
92 bus_size_t);
93 static void atppc_acpi_dma_free(device_t, void **, bus_addr_t *,
94 bus_size_t);
95 /*
96 * atppc_acpi_match: autoconf(9) match routine
97 */
98 static int
99 atppc_acpi_match(device_t parent, cfdata_t match, void *aux)
100 {
101 struct acpi_attach_args *aa = aux;
102
103 if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
104 return 0;
105
106 return acpi_match_hid(aa->aa_node->ad_devinfo, atppc_acpi_ids);
107 }
108
109 static void
110 atppc_acpi_attach(device_t parent, device_t self, void *aux)
111 {
112 struct atppc_softc *sc = device_private(self);
113 struct atppc_acpi_softc *asc = device_private(self);
114 struct acpi_attach_args *aa = aux;
115 struct acpi_resources res;
116 struct acpi_io *io;
117 struct acpi_irq *irq;
118 struct acpi_drq *drq;
119 ACPI_STATUS rv;
120 int nirq;
121
122 sc->sc_dev_ok = ATPPC_NOATTACH;
123
124 aprint_naive(": AT Parallel Port\n");
125 aprint_normal(": AT Parallel Port\n");
126
127 /* parse resources */
128 rv = acpi_resource_parse(sc->sc_dev, aa->aa_node->ad_handle, "_CRS",
129 &res, &acpi_resource_parse_ops_default);
130 if (ACPI_FAILURE(rv))
131 return;
132
133 /* find our i/o registers */
134 io = acpi_res_io(&res, 0);
135 if (io == NULL) {
136 aprint_error_dev(sc->sc_dev, "unable to find i/o register resource\n");
137 goto out;
138 }
139
140 /* find our IRQ */
141 irq = acpi_res_irq(&res, 0);
142 if (irq == NULL) {
143 aprint_error_dev(sc->sc_dev, "unable to find irq resource\n");
144 goto out;
145 }
146 nirq = irq->ar_irq;
147
148 /* find our DRQ */
149 drq = acpi_res_drq(&res, 0);
150 if (drq == NULL) {
151 aprint_error_dev(sc->sc_dev, "unable to find drq resource\n");
152 goto out;
153 }
154 asc->sc_drq = drq->ar_drq;
155
156 /* Attach */
157 sc->sc_dev = self;
158 sc->sc_iot = aa->aa_iot;
159 sc->sc_has = 0;
160 asc->sc_ic = aa->aa_ic;
161
162 sc->sc_dev_ok = ATPPC_ATTACHED;
163
164 if (bus_space_map(sc->sc_iot, io->ar_base, io->ar_length, 0,
165 &sc->sc_ioh) != 0) {
166 aprint_error_dev(self, "attempt to map bus space failed, device not "
167 "properly attached.\n");
168 goto out;
169 }
170
171 sc->sc_ieh = isa_intr_establish(aa->aa_ic, nirq,
172 (irq->ar_type == ACPI_EDGE_SENSITIVE) ? IST_EDGE : IST_LEVEL,
173 IPL_TTY, atppcintr, sc);
174
175 /* setup DMA hooks */
176 if (atppc_isadma_setup(sc, asc->sc_ic, asc->sc_drq) == 0) {
177 sc->sc_has |= ATPPC_HAS_DMA;
178 sc->sc_dma_start = atppc_acpi_dma_start;
179 sc->sc_dma_finish = atppc_acpi_dma_finish;
180 sc->sc_dma_abort = atppc_acpi_dma_abort;
181 sc->sc_dma_malloc = atppc_acpi_dma_malloc;
182 sc->sc_dma_free = atppc_acpi_dma_free;
183 }
184
185 sc->sc_has |= ATPPC_HAS_INTR;
186
187 /* Run soft configuration attach */
188 atppc_sc_attach(sc);
189 out:
190 acpi_resource_cleanup(&res);
191 }
192
193 /* Start DMA operation over ISA bus */
194 static int
195 atppc_acpi_dma_start(struct atppc_softc *lsc, void *buf, u_int nbytes,
196 u_int8_t mode)
197 {
198 struct atppc_acpi_softc * sc = (struct atppc_acpi_softc *) lsc;
199
200 return atppc_isadma_start(sc->sc_ic, sc->sc_drq, buf, nbytes, mode);
201 }
202
203 /* Stop DMA operation over ISA bus */
204 static int
205 atppc_acpi_dma_finish(struct atppc_softc * lsc)
206 {
207 struct atppc_acpi_softc * sc = (struct atppc_acpi_softc *) lsc;
208
209 return atppc_isadma_finish(sc->sc_ic, sc->sc_drq);
210 }
211
212 /* Abort DMA operation over ISA bus */
213 int
214 atppc_acpi_dma_abort(struct atppc_softc * lsc)
215 {
216 struct atppc_acpi_softc * sc = (struct atppc_acpi_softc *) lsc;
217
218 return atppc_isadma_abort(sc->sc_ic, sc->sc_drq);
219 }
220
221 /* Allocate memory for DMA over ISA bus */
222 static int
223 atppc_acpi_dma_malloc(device_t dev, void ** buf, bus_addr_t * bus_addr,
224 bus_size_t size)
225 {
226 struct atppc_acpi_softc * sc = device_private(dev);
227
228 return atppc_isadma_malloc(sc->sc_ic, sc->sc_drq, buf, bus_addr, size);
229 }
230
231 /* Free memory allocated by atppc_isa_dma_malloc() */
232 static void
233 atppc_acpi_dma_free(device_t dev, void ** buf, bus_addr_t * bus_addr,
234 bus_size_t size)
235 {
236 struct atppc_acpi_softc * sc = device_private(dev);
237
238 return atppc_isadma_free(sc->sc_ic, sc->sc_drq, buf, bus_addr, size);
239 }
240