atppc_isa.c revision 1.2 1 1.2 bjh21 /* $NetBSD: atppc_isa.c,v 1.2 2004/01/21 00:33:37 bjh21 Exp $ */
2 1.2 bjh21
3 1.1 jdolecek /*-
4 1.1 jdolecek * Copyright (c) 2001 Alcove - Nicolas Souchu
5 1.1 jdolecek * All rights reserved.
6 1.1 jdolecek *
7 1.1 jdolecek * Redistribution and use in source and binary forms, with or without
8 1.1 jdolecek * modification, are permitted provided that the following conditions
9 1.1 jdolecek * are met:
10 1.1 jdolecek * 1. Redistributions of source code must retain the above copyright
11 1.1 jdolecek * notice, this list of conditions and the following disclaimer.
12 1.1 jdolecek * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 jdolecek * notice, this list of conditions and the following disclaimer in the
14 1.1 jdolecek * documentation and/or other materials provided with the distribution.
15 1.1 jdolecek *
16 1.1 jdolecek * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 1.1 jdolecek * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 1.1 jdolecek * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 1.1 jdolecek * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 1.1 jdolecek * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 1.1 jdolecek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 1.1 jdolecek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.1 jdolecek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 1.1 jdolecek * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1 jdolecek * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1 jdolecek * SUCH DAMAGE.
27 1.1 jdolecek *
28 1.1 jdolecek * $FreeBSD: src/sys/isa/ppc.c,v 1.26.2.5 2001/10/02 05:21:45 nsouch Exp $
29 1.1 jdolecek *
30 1.1 jdolecek */
31 1.1 jdolecek
32 1.1 jdolecek #include "opt_atppc.h"
33 1.1 jdolecek
34 1.1 jdolecek #include <sys/param.h>
35 1.1 jdolecek #include <sys/systm.h>
36 1.1 jdolecek #include <sys/kernel.h>
37 1.1 jdolecek #include <sys/malloc.h>
38 1.1 jdolecek #include <sys/device.h>
39 1.1 jdolecek
40 1.1 jdolecek #include <machine/intr.h>
41 1.1 jdolecek #include <machine/bus.h>
42 1.1 jdolecek
43 1.1 jdolecek #include <dev/isa/isareg.h>
44 1.1 jdolecek #include <dev/isa/isavar.h>
45 1.1 jdolecek #include <dev/isa/isadmavar.h>
46 1.1 jdolecek #include <dev/isa/atppc_isa_subr.h>
47 1.1 jdolecek
48 1.1 jdolecek #include <dev/ic/atppcreg.h>
49 1.1 jdolecek #include <dev/ic/atppcvar.h>
50 1.1 jdolecek
51 1.1 jdolecek /*
52 1.1 jdolecek * ISA bus attach code for atppc driver.
53 1.1 jdolecek * Note on capabilities: capabilites may exist in the chipset but may not
54 1.1 jdolecek * necessarily be useable. I.e. you may specify an IRQ in the autoconfig, but
55 1.1 jdolecek * will the port actually have an IRQ assigned to it at the hardware level?
56 1.1 jdolecek * How can you test if the capabilites can be used? For interrupts, see if a
57 1.1 jdolecek * handler exists (sc_intr != NULL). For DMA, see if the sc_dma_start() and
58 1.1 jdolecek * sc_dma_finish() function pointers are not NULL.
59 1.1 jdolecek */
60 1.1 jdolecek
61 1.1 jdolecek /* Probe, attach, and detach functions for a atppc device on the ISA bus. */
62 1.1 jdolecek static int atppc_isa_probe __P((struct device *, struct cfdata *, void *));
63 1.1 jdolecek static void atppc_isa_attach __P((struct device *, struct device *, void *));
64 1.1 jdolecek static int atppc_isa_detach __P((struct device *, int));
65 1.1 jdolecek
66 1.1 jdolecek CFATTACH_DECL(atppc_isa, sizeof(struct atppc_isa_softc), atppc_isa_probe,
67 1.1 jdolecek atppc_isa_attach, atppc_isa_detach, NULL);
68 1.1 jdolecek
69 1.1 jdolecek /*
70 1.1 jdolecek * Probe function: find parallel port controller on isa bus. Combined from
71 1.1 jdolecek * lpt_isa_probe() in lpt.c and atppc_detect_port() from FreeBSD's ppc.c.
72 1.1 jdolecek */
73 1.1 jdolecek static int
74 1.1 jdolecek atppc_isa_probe(struct device * parent, struct cfdata * cf, void * aux)
75 1.1 jdolecek {
76 1.1 jdolecek bus_space_handle_t ioh;
77 1.1 jdolecek struct isa_attach_args * ia = aux;
78 1.1 jdolecek bus_space_tag_t iot = ia->ia_iot;
79 1.1 jdolecek int addr = ia->ia_io->ir_addr;
80 1.1 jdolecek int rval = 0;
81 1.1 jdolecek
82 1.1 jdolecek if(ia->ia_nio < 1 || addr == ISACF_PORT_DEFAULT) {
83 1.1 jdolecek printf("%s(%s): io port unknown.\n", __func__,
84 1.1 jdolecek parent->dv_xname);
85 1.1 jdolecek }
86 1.1 jdolecek else if(bus_space_map(iot, addr, IO_LPTSIZE, 0, &ioh) == 0) {
87 1.1 jdolecek if (atppc_detect_port(iot, ioh) == 0)
88 1.1 jdolecek rval = 1;
89 1.1 jdolecek else
90 1.1 jdolecek printf("%s(%s): unable to write/read I/O port.\n",
91 1.1 jdolecek __func__, parent->dv_xname);
92 1.1 jdolecek bus_space_unmap(iot, ioh, IO_LPTSIZE);
93 1.1 jdolecek }
94 1.1 jdolecek else {
95 1.1 jdolecek printf("%s(%s): attempt to map bus space failed.\n", __func__,
96 1.1 jdolecek parent->dv_xname);
97 1.1 jdolecek }
98 1.1 jdolecek
99 1.1 jdolecek if(rval) {
100 1.1 jdolecek ia->ia_nio = 1;
101 1.1 jdolecek ia->ia_io[0].ir_size = IO_LPTSIZE;
102 1.1 jdolecek ia->ia_nirq = 1;
103 1.1 jdolecek ia->ia_ndrq = 1;
104 1.1 jdolecek ia->ia_niomem = 0;
105 1.1 jdolecek }
106 1.1 jdolecek
107 1.1 jdolecek return rval;
108 1.1 jdolecek }
109 1.1 jdolecek
110 1.1 jdolecek /* Attach function: attach and configure parallel port controller on isa bus. */
111 1.1 jdolecek static void
112 1.1 jdolecek atppc_isa_attach(struct device * parent, struct device * self, void * aux)
113 1.1 jdolecek {
114 1.1 jdolecek struct atppc_isa_softc * sc = (struct atppc_isa_softc *)self;
115 1.1 jdolecek struct atppc_softc * lsc = (struct atppc_softc *)self;
116 1.1 jdolecek struct isa_attach_args * ia = aux;
117 1.1 jdolecek
118 1.1 jdolecek lsc->sc_iot = ia->ia_iot;
119 1.1 jdolecek lsc->sc_dmat = ia->ia_dmat;
120 1.1 jdolecek lsc->sc_has = 0;
121 1.1 jdolecek sc->sc_ic = ia->ia_ic;
122 1.1 jdolecek sc->sc_iobase = ia->ia_io->ir_addr;
123 1.1 jdolecek
124 1.1 jdolecek if(bus_space_map(lsc->sc_iot, sc->sc_iobase, IO_LPTSIZE, 0,
125 1.1 jdolecek &lsc->sc_ioh) != 0) {
126 1.1 jdolecek printf("%s: attempt to map bus space failed, device not "
127 1.1 jdolecek "properly attached.\n", self->dv_xname);
128 1.1 jdolecek lsc->sc_dev_ok = ATPPC_NOATTACH;
129 1.1 jdolecek return;
130 1.1 jdolecek }
131 1.1 jdolecek else {
132 1.1 jdolecek lsc->sc_dev_ok = ATPPC_ATTACHED;
133 1.1 jdolecek }
134 1.1 jdolecek
135 1.1 jdolecek /* Assign interrupt handler */
136 1.1 jdolecek if(!(self->dv_cfdata->cf_flags & ATPPC_FLAG_DISABLE_INTR)) {
137 1.1 jdolecek if((ia->ia_irq->ir_irq != ISACF_IRQ_DEFAULT) &&
138 1.1 jdolecek (ia->ia_nirq > 0)) {
139 1.1 jdolecek
140 1.1 jdolecek sc->sc_irq = ia->ia_irq->ir_irq;
141 1.1 jdolecek /* Establish interrupt handler. */
142 1.1 jdolecek if(!(atppc_isa_intr_establish(lsc))) {
143 1.1 jdolecek lsc->sc_has |= ATPPC_HAS_INTR;
144 1.1 jdolecek }
145 1.1 jdolecek }
146 1.1 jdolecek else {
147 1.1 jdolecek ATPPC_DPRINTF(("%s: IRQ not assigned or bad number of "
148 1.1 jdolecek "IRQs.\n", self->dv_xname));
149 1.1 jdolecek }
150 1.1 jdolecek }
151 1.1 jdolecek else {
152 1.1 jdolecek ATPPC_VPRINTF(("%s: interrupts not configured due to flags.\n",
153 1.1 jdolecek self->dv_xname));
154 1.1 jdolecek }
155 1.1 jdolecek
156 1.1 jdolecek /* Configure DMA */
157 1.1 jdolecek if(!(self->dv_cfdata->cf_flags & ATPPC_FLAG_DISABLE_DMA)) {
158 1.1 jdolecek if((ia->ia_drq->ir_drq != ISACF_DRQ_DEFAULT) &&
159 1.1 jdolecek (ia->ia_ndrq > 0)) {
160 1.1 jdolecek
161 1.1 jdolecek sc->sc_drq = ia->ia_drq->ir_drq;
162 1.1 jdolecek if(!(atppc_isa_dma_setup(lsc))) {
163 1.1 jdolecek lsc->sc_has |= ATPPC_HAS_DMA;
164 1.1 jdolecek }
165 1.1 jdolecek }
166 1.1 jdolecek else {
167 1.1 jdolecek ATPPC_DPRINTF(("%s: DRQ not assigned or bad number of "
168 1.1 jdolecek "DRQs.\n", self->dv_xname));
169 1.1 jdolecek }
170 1.1 jdolecek }
171 1.1 jdolecek else {
172 1.1 jdolecek ATPPC_VPRINTF(("%s: dma not configured due to flags.\n",
173 1.1 jdolecek self->dv_xname));
174 1.1 jdolecek }
175 1.1 jdolecek
176 1.1 jdolecek /* Run soft configuration attach */
177 1.1 jdolecek atppc_sc_attach(lsc);
178 1.1 jdolecek
179 1.1 jdolecek return;
180 1.1 jdolecek }
181 1.1 jdolecek
182 1.1 jdolecek /* Detach function: used to detach atppc driver at run time. */
183 1.1 jdolecek static int
184 1.1 jdolecek atppc_isa_detach(struct device * dev, int flag)
185 1.1 jdolecek {
186 1.1 jdolecek struct atppc_softc * lsc = (struct atppc_softc *) dev;
187 1.1 jdolecek int rval;
188 1.1 jdolecek
189 1.1 jdolecek if(lsc->sc_dev_ok == ATPPC_ATTACHED) {
190 1.1 jdolecek /* Run soft configuration detach first */
191 1.1 jdolecek rval = atppc_sc_detach(lsc, flag);
192 1.1 jdolecek
193 1.1 jdolecek /* Disable DMA */
194 1.1 jdolecek atppc_isa_dma_remove(lsc);
195 1.1 jdolecek
196 1.1 jdolecek /* Disestablish interrupt handler */
197 1.1 jdolecek atppc_isa_intr_disestablish(lsc);
198 1.1 jdolecek
199 1.1 jdolecek /* Unmap bus space */
200 1.1 jdolecek bus_space_unmap(lsc->sc_iot, lsc->sc_ioh, IO_LPTSIZE);
201 1.1 jdolecek
202 1.1 jdolecek /* Mark config data */
203 1.1 jdolecek lsc->sc_dev_ok = ATPPC_NOATTACH;
204 1.1 jdolecek }
205 1.1 jdolecek else {
206 1.1 jdolecek rval = 0;
207 1.1 jdolecek if(!(flag & DETACH_QUIET)) {
208 1.1 jdolecek printf("%s not properly attached! Detach routines "
209 1.1 jdolecek "skipped.\n", dev->dv_xname);
210 1.1 jdolecek }
211 1.1 jdolecek }
212 1.1 jdolecek
213 1.1 jdolecek if(!(flag & DETACH_QUIET)) {
214 1.1 jdolecek printf("%s: detached.", dev->dv_xname);
215 1.1 jdolecek }
216 1.1 jdolecek
217 1.1 jdolecek return rval;
218 1.1 jdolecek }
219