atppc_isapnp.c revision 1.2.4.4 1 1.2.4.4 skrll /* $NetBSD: atppc_isapnp.c,v 1.2.4.4 2004/09/21 13:30:16 skrll Exp $ */
2 1.2.4.2 skrll
3 1.2.4.2 skrll /*-
4 1.2.4.2 skrll * Copyright (c) 2004 The NetBSD Foundation, Inc.
5 1.2.4.2 skrll * All rights reserved.
6 1.2.4.2 skrll *
7 1.2.4.2 skrll * This code is derived from software contributed to The NetBSD Foundation
8 1.2.4.2 skrll * by Jaromir Dolecek.
9 1.2.4.2 skrll *
10 1.2.4.2 skrll * Redistribution and use in source and binary forms, with or without
11 1.2.4.2 skrll * modification, are permitted provided that the following conditions
12 1.2.4.2 skrll * are met:
13 1.2.4.2 skrll * 1. Redistributions of source code must retain the above copyright
14 1.2.4.2 skrll * notice, this list of conditions and the following disclaimer.
15 1.2.4.2 skrll * 2. Redistributions in binary form must reproduce the above copyright
16 1.2.4.2 skrll * notice, this list of conditions and the following disclaimer in the
17 1.2.4.2 skrll * documentation and/or other materials provided with the distribution.
18 1.2.4.2 skrll * 3. All advertising materials mentioning features or use of this software
19 1.2.4.2 skrll * must display the following acknowledgement:
20 1.2.4.2 skrll * This product includes software developed by the NetBSD
21 1.2.4.2 skrll * Foundation, Inc. and its contributors.
22 1.2.4.2 skrll * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.2.4.2 skrll * contributors may be used to endorse or promote products derived
24 1.2.4.2 skrll * from this software without specific prior written permission.
25 1.2.4.2 skrll *
26 1.2.4.2 skrll * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.2.4.2 skrll * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.2.4.2 skrll * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.2.4.2 skrll * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.2.4.2 skrll * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.2.4.2 skrll * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.2.4.2 skrll * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.2.4.2 skrll * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.2.4.2 skrll * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.2.4.2 skrll * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.2.4.2 skrll * POSSIBILITY OF SUCH DAMAGE.
37 1.2.4.2 skrll */
38 1.2.4.2 skrll
39 1.2.4.2 skrll #include <sys/cdefs.h>
40 1.2.4.4 skrll __KERNEL_RCSID(0, "$NetBSD: atppc_isapnp.c,v 1.2.4.4 2004/09/21 13:30:16 skrll Exp $");
41 1.2.4.2 skrll
42 1.2.4.2 skrll #include "opt_atppc.h"
43 1.2.4.2 skrll
44 1.2.4.2 skrll #include <sys/param.h>
45 1.2.4.2 skrll #include <sys/systm.h>
46 1.2.4.2 skrll #include <sys/errno.h>
47 1.2.4.2 skrll #include <sys/ioctl.h>
48 1.2.4.2 skrll #include <sys/syslog.h>
49 1.2.4.2 skrll #include <sys/device.h>
50 1.2.4.2 skrll #include <sys/proc.h>
51 1.2.4.2 skrll #include <sys/termios.h>
52 1.2.4.2 skrll
53 1.2.4.2 skrll #include <machine/bus.h>
54 1.2.4.2 skrll
55 1.2.4.2 skrll #include <dev/isa/isavar.h>
56 1.2.4.2 skrll #include <dev/isa/isadmavar.h>
57 1.2.4.2 skrll
58 1.2.4.2 skrll #include <dev/isapnp/isapnpreg.h>
59 1.2.4.2 skrll #include <dev/isapnp/isapnpvar.h>
60 1.2.4.2 skrll #include <dev/isapnp/isapnpdevs.h>
61 1.2.4.2 skrll
62 1.2.4.2 skrll #include <dev/ic/atppcvar.h>
63 1.2.4.2 skrll #include <dev/isa/atppc_isadma.h>
64 1.2.4.2 skrll
65 1.2.4.2 skrll static int atppc_isapnp_match(struct device *, struct cfdata *, void *);
66 1.2.4.2 skrll static void atppc_isapnp_attach(struct device *, struct device *, void *);
67 1.2.4.2 skrll
68 1.2.4.2 skrll struct atppc_isapnp_softc {
69 1.2.4.2 skrll struct atppc_softc sc_atppc;
70 1.2.4.2 skrll
71 1.2.4.2 skrll isa_chipset_tag_t sc_ic;
72 1.2.4.2 skrll int sc_drq;
73 1.2.4.2 skrll };
74 1.2.4.2 skrll
75 1.2.4.2 skrll CFATTACH_DECL(atppc_isapnp, sizeof(struct atppc_isapnp_softc),
76 1.2.4.2 skrll atppc_isapnp_match, atppc_isapnp_attach, NULL, NULL);
77 1.2.4.2 skrll
78 1.2.4.2 skrll static int atppc_isapnp_dma_start(struct atppc_softc *, void *, u_int,
79 1.2.4.2 skrll u_int8_t);
80 1.2.4.2 skrll static int atppc_isapnp_dma_finish(struct atppc_softc *);
81 1.2.4.2 skrll static int atppc_isapnp_dma_abort(struct atppc_softc *);
82 1.2.4.2 skrll static int atppc_isapnp_dma_malloc(struct device *, caddr_t *, bus_addr_t *,
83 1.2.4.2 skrll bus_size_t);
84 1.2.4.2 skrll static void atppc_isapnp_dma_free(struct device *, caddr_t *, bus_addr_t *,
85 1.2.4.2 skrll bus_size_t);
86 1.2.4.2 skrll /*
87 1.2.4.2 skrll * atppc_isapnp_match: autoconf(9) match routine
88 1.2.4.2 skrll */
89 1.2.4.2 skrll static int
90 1.2.4.2 skrll atppc_isapnp_match(struct device *parent, struct cfdata *match, void *aux)
91 1.2.4.2 skrll {
92 1.2.4.2 skrll int pri, variant;
93 1.2.4.2 skrll
94 1.2.4.2 skrll pri = isapnp_devmatch(aux, &isapnp_atppc_devinfo, &variant);
95 1.2.4.2 skrll if (pri && variant > 0)
96 1.2.4.2 skrll pri = 0;
97 1.2.4.2 skrll return (pri);
98 1.2.4.2 skrll }
99 1.2.4.2 skrll
100 1.2.4.2 skrll static void
101 1.2.4.2 skrll atppc_isapnp_attach(struct device *parent, struct device *self, void *aux)
102 1.2.4.2 skrll {
103 1.2.4.2 skrll struct atppc_softc *sc = (struct atppc_softc *) self;
104 1.2.4.2 skrll struct atppc_isapnp_softc *asc = (struct atppc_isapnp_softc *)self;
105 1.2.4.2 skrll struct isapnp_attach_args *ipa = aux;
106 1.2.4.2 skrll
107 1.2.4.2 skrll sc->sc_dev_ok = ATPPC_NOATTACH;
108 1.2.4.2 skrll
109 1.2.4.2 skrll printf(": AT Parallel Port\n");
110 1.2.4.2 skrll
111 1.2.4.2 skrll if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
112 1.2.4.2 skrll printf("%s: error in region allocation\n",
113 1.2.4.2 skrll sc->sc_dev.dv_xname);
114 1.2.4.2 skrll return;
115 1.2.4.2 skrll }
116 1.2.4.2 skrll
117 1.2.4.2 skrll /* Attach */
118 1.2.4.2 skrll sc->sc_iot = ipa->ipa_iot;
119 1.2.4.2 skrll sc->sc_ioh = ipa->ipa_io[0].h;
120 1.2.4.2 skrll sc->sc_has = 0;
121 1.2.4.2 skrll asc->sc_ic = ipa->ipa_ic;
122 1.2.4.2 skrll asc->sc_drq = -1; /* Initialized below */
123 1.2.4.2 skrll
124 1.2.4.2 skrll sc->sc_dev_ok = ATPPC_ATTACHED;
125 1.2.4.2 skrll
126 1.2.4.2 skrll sc->sc_ieh = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
127 1.2.4.2 skrll ipa->ipa_irq[0].type, IPL_TTY, atppcintr, sc);
128 1.2.4.2 skrll sc->sc_has |= ATPPC_HAS_INTR;
129 1.2.4.2 skrll
130 1.2.4.2 skrll /* setup DMA hooks */
131 1.2.4.2 skrll if (ipa->ipa_ndrq > 0
132 1.2.4.2 skrll && atppc_isadma_setup(sc, asc->sc_ic, ipa->ipa_drq[0].num) == 0) {
133 1.2.4.2 skrll asc->sc_drq = ipa->ipa_drq[0].num;
134 1.2.4.2 skrll sc->sc_has |= ATPPC_HAS_DMA;
135 1.2.4.2 skrll sc->sc_dma_start = atppc_isapnp_dma_start;
136 1.2.4.2 skrll sc->sc_dma_finish = atppc_isapnp_dma_finish;
137 1.2.4.2 skrll sc->sc_dma_abort = atppc_isapnp_dma_abort;
138 1.2.4.2 skrll sc->sc_dma_malloc = atppc_isapnp_dma_malloc;
139 1.2.4.2 skrll sc->sc_dma_free = atppc_isapnp_dma_free;
140 1.2.4.2 skrll }
141 1.2.4.2 skrll
142 1.2.4.2 skrll /* Run soft configuration attach */
143 1.2.4.2 skrll atppc_sc_attach(sc);
144 1.2.4.2 skrll }
145 1.2.4.2 skrll
146 1.2.4.2 skrll /* Start DMA operation over ISA bus */
147 1.2.4.2 skrll static int
148 1.2.4.2 skrll atppc_isapnp_dma_start(struct atppc_softc *lsc, void *buf, u_int nbytes,
149 1.2.4.2 skrll u_int8_t mode)
150 1.2.4.2 skrll {
151 1.2.4.2 skrll struct atppc_isapnp_softc * sc = (struct atppc_isapnp_softc *) lsc;
152 1.2.4.2 skrll
153 1.2.4.2 skrll return atppc_isadma_start(sc->sc_ic, sc->sc_drq, buf, nbytes, mode);
154 1.2.4.2 skrll }
155 1.2.4.2 skrll
156 1.2.4.2 skrll /* Stop DMA operation over ISA bus */
157 1.2.4.2 skrll static int
158 1.2.4.2 skrll atppc_isapnp_dma_finish(struct atppc_softc * lsc)
159 1.2.4.2 skrll {
160 1.2.4.2 skrll struct atppc_isapnp_softc * sc = (struct atppc_isapnp_softc *) lsc;
161 1.2.4.2 skrll
162 1.2.4.2 skrll return atppc_isadma_finish(sc->sc_ic, sc->sc_drq);
163 1.2.4.2 skrll }
164 1.2.4.2 skrll
165 1.2.4.2 skrll /* Abort DMA operation over ISA bus */
166 1.2.4.2 skrll int
167 1.2.4.2 skrll atppc_isapnp_dma_abort(struct atppc_softc * lsc)
168 1.2.4.2 skrll {
169 1.2.4.2 skrll struct atppc_isapnp_softc * sc = (struct atppc_isapnp_softc *) lsc;
170 1.2.4.2 skrll
171 1.2.4.2 skrll return atppc_isadma_abort(sc->sc_ic, sc->sc_drq);
172 1.2.4.2 skrll }
173 1.2.4.2 skrll
174 1.2.4.2 skrll /* Allocate memory for DMA over ISA bus */
175 1.2.4.2 skrll int
176 1.2.4.2 skrll atppc_isapnp_dma_malloc(struct device * dev, caddr_t * buf, bus_addr_t * bus_addr,
177 1.2.4.2 skrll bus_size_t size)
178 1.2.4.2 skrll {
179 1.2.4.2 skrll struct atppc_isapnp_softc * sc = (struct atppc_isapnp_softc *) dev;
180 1.2.4.2 skrll
181 1.2.4.2 skrll return atppc_isadma_malloc(sc->sc_ic, sc->sc_drq, buf, bus_addr, size);
182 1.2.4.2 skrll }
183 1.2.4.2 skrll
184 1.2.4.2 skrll /* Free memory allocated by atppc_isa_dma_malloc() */
185 1.2.4.2 skrll void
186 1.2.4.2 skrll atppc_isapnp_dma_free(struct device * dev, caddr_t * buf, bus_addr_t * bus_addr,
187 1.2.4.2 skrll bus_size_t size)
188 1.2.4.2 skrll {
189 1.2.4.2 skrll struct atppc_isapnp_softc * sc = (struct atppc_isapnp_softc *) dev;
190 1.2.4.2 skrll
191 1.2.4.2 skrll return atppc_isadma_free(sc->sc_ic, sc->sc_drq, buf, bus_addr, size);
192 1.2.4.2 skrll }
193