fdc_jazzio.c revision 1.1 1 /* $NetBSD: fdc_jazzio.c,v 1.1 2001/05/22 03:22:50 soda Exp $ */
2 /* $OpenBSD: fd.c,v 1.6 1998/10/03 21:18:57 millert Exp $ */
3 /* NetBSD: fd.c,v 1.78 1995/07/04 07:23:09 mycroft Exp */
4
5 /*-
6 * Copyright (c) 1998 The NetBSD Foundation, Inc.
7 * All rights reserved.
8 *
9 * This code is derived from software contributed to The NetBSD Foundation
10 * by Charles M. Hannum.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the NetBSD
23 * Foundation, Inc. and its contributors.
24 * 4. Neither the name of The NetBSD Foundation nor the names of its
25 * contributors may be used to endorse or promote products derived
26 * from this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
32 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
39 */
40
41 /*-
42 * Copyright (c) 1990 The Regents of the University of California.
43 * All rights reserved.
44 *
45 * This code is derived from software contributed to Berkeley by
46 * Don Ahn.
47 *
48 * Redistribution and use in source and binary forms, with or without
49 * modification, are permitted provided that the following conditions
50 * are met:
51 * 1. Redistributions of source code must retain the above copyright
52 * notice, this list of conditions and the following disclaimer.
53 * 2. Redistributions in binary form must reproduce the above copyright
54 * notice, this list of conditions and the following disclaimer in the
55 * documentation and/or other materials provided with the distribution.
56 * 3. All advertising materials mentioning features or use of this software
57 * must display the following acknowledgement:
58 * This product includes software developed by the University of
59 * California, Berkeley and its contributors.
60 * 4. Neither the name of the University nor the names of its contributors
61 * may be used to endorse or promote products derived from this software
62 * without specific prior written permission.
63 *
64 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
65 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
66 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
67 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
68 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
69 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
70 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
71 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
72 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
73 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
74 * SUCH DAMAGE.
75 *
76 * @(#)fd.c 7.4 (Berkeley) 5/25/91
77 */
78
79 #include <sys/param.h>
80 #include <sys/systm.h>
81 #include <sys/callout.h>
82 #include <sys/device.h>
83 #include <sys/buf.h>
84 #include <sys/queue.h>
85
86 #include <mips/locore.h> /* for mips3_HitFlushDCache() */
87
88 #include <machine/autoconf.h>
89 #include <machine/bus.h>
90 #include <machine/cpu.h>
91
92 #include <arc/jazz/jazzdmatlbreg.h>
93 #include <arc/jazz/fdreg.h>
94 #include <arc/jazz/fdcvar.h>
95 #include <arc/jazz/jazziovar.h>
96 #include <arc/jazz/dma.h>
97
98 #include "locators.h"
99
100 /* controller driver configuration */
101 int fdc_jazzio_probe(struct device *, struct cfdata *, void *);
102 void fdc_jazzio_attach(struct device *, struct device *, void *);
103
104 /* MD DMA hook functions */
105 void fdc_jazzio_dma_start(struct fdc_softc *, caddr_t, size_t, int);
106 void fdc_jazzio_dma_abort(struct fdc_softc *);
107 void fdc_jazzio_dma_done(struct fdc_softc *);
108
109 /* software state, per controller */
110 struct fdc_jazzio_softc {
111 struct fdc_softc sc_fdc; /* base fdc device */
112
113 bus_space_handle_t sc_baseioh; /* base I/O handle */
114 struct dma_softc __dma;
115 struct dma_softc *dma;
116 };
117
118 struct cfattach fdc_jazzio_ca = {
119 sizeof(struct fdc_jazzio_softc), fdc_jazzio_probe, fdc_jazzio_attach
120 };
121
122 #define FDC_NPORT 6
123 #define FDC_OFFSET 2 /* Should we use bus_space_subregion() or not? */
124
125 int
126 fdc_jazzio_probe(parent, match, aux)
127 struct device *parent;
128 struct cfdata *match;
129 void *aux;
130 {
131 struct jazzio_attach_args *ja = aux;
132 bus_space_tag_t iot;
133 bus_space_handle_t base_ioh, ioh;
134 int rv;
135
136 if (strcmp(ja->ja_name, "fdc") != 0)
137 return 0;
138
139 iot = ja->ja_bust;
140 rv = 0;
141
142 /* Map the I/O space. */
143 if (bus_space_map(iot, ja->ja_addr,
144 FDC_OFFSET + FDC_NPORT, 0, &base_ioh))
145 return 0;
146
147 if (bus_space_subregion(iot, base_ioh, FDC_OFFSET, FDC_NPORT, &ioh))
148 goto out;
149
150 /* reset */
151 bus_space_write_1(iot, ioh, FDOUT, 0);
152 delay(100);
153 bus_space_write_1(iot, ioh, FDOUT, FDO_FRST);
154
155 /* see if it can handle a command */
156 if (out_fdc(iot, ioh, NE7CMD_SPECIFY) < 0)
157 goto out;
158 out_fdc(iot, ioh, 0xdf); /* XXX */
159 out_fdc(iot, ioh, 2); /* XXX */
160
161 rv = 1;
162
163 out:
164 bus_space_unmap(iot, base_ioh, FDC_OFFSET + FDC_NPORT);
165 return rv;
166 }
167
168 void
169 fdc_jazzio_attach(parent, self, aux)
170 struct device *parent, *self;
171 void *aux;
172 {
173 struct fdc_jazzio_softc *jsc = (struct fdc_jazzio_softc *)self;
174 struct fdc_softc *fdc = &jsc->sc_fdc;
175 struct jazzio_attach_args *ja = aux;
176
177 fdc->sc_iot = ja->ja_bust;
178
179 fdc->sc_maxiosize = 4096; /* XXX */
180 fdc->sc_dma_start = fdc_jazzio_dma_start;
181 fdc->sc_dma_abort = fdc_jazzio_dma_abort;
182 fdc->sc_dma_done = fdc_jazzio_dma_done;
183
184 jsc->dma = &jsc->__dma;
185 fdc_dma_init(jsc->dma);
186
187 if (bus_space_map(fdc->sc_iot, ja->ja_addr,
188 FDC_OFFSET + FDC_NPORT, 0, &jsc->sc_baseioh)) {
189 printf(": unable to map I/O space\n");
190 return;
191 }
192
193 if (bus_space_subregion(fdc->sc_iot, jsc->sc_baseioh,
194 FDC_OFFSET, FDC_NPORT, &fdc->sc_ioh)) {
195 printf(": unable to subregion I/O space\n");
196 bus_space_unmap(fdc->sc_iot, jsc->sc_baseioh,
197 FDC_OFFSET + FDC_NPORT);
198 return;
199 }
200
201 printf("\n");
202
203 jazzio_intr_establish(ja->ja_intr, fdcintr, fdc);
204
205 fdcattach(fdc);
206 }
207
208 void
209 fdc_jazzio_dma_start(fdc, addr, size, datain)
210 struct fdc_softc *fdc;
211 caddr_t addr;
212 size_t size;
213 int datain;
214 {
215 struct fdc_jazzio_softc *jsc = (void *)fdc;
216
217 mips3_FlushDCache((vaddr_t)addr, (vsize_t)size);
218 DMA_START(jsc->dma, addr, size, datain ? DMA_FROM_DEV : DMA_TO_DEV);
219 }
220
221 void
222 fdc_jazzio_dma_abort(fdc)
223 struct fdc_softc *fdc;
224 {
225 struct fdc_jazzio_softc *jsc = (void *)fdc;
226
227 DMA_RESET(jsc->dma);
228 }
229
230 void
231 fdc_jazzio_dma_done(fdc)
232 struct fdc_softc *fdc;
233 {
234 struct fdc_jazzio_softc *jsc = (void *)fdc;
235
236 DMA_END(jsc->dma);
237 }
238