ptsc.c revision 1.1.4.3 1 1.1.4.3 nathanw /* $NetBSD: ptsc.c,v 1.1.4.3 2002/08/13 01:02:38 nathanw Exp $ */
2 1.1.4.2 nathanw
3 1.1.4.2 nathanw /*
4 1.1.4.2 nathanw * Copyright (c) 1995 Scott Stevens
5 1.1.4.2 nathanw * Copyright (c) 1995 Daniel Widenfalk
6 1.1.4.2 nathanw * Copyright (c) 1994 Christian E. Hopps
7 1.1.4.2 nathanw * Copyright (c) 1982, 1990 The Regents of the University of California.
8 1.1.4.2 nathanw * All rights reserved.
9 1.1.4.2 nathanw *
10 1.1.4.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.1.4.2 nathanw * modification, are permitted provided that the following conditions
12 1.1.4.2 nathanw * are met:
13 1.1.4.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.1.4.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.1.4.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.4.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.1.4.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.1.4.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.1.4.2 nathanw * must display the following acknowledgement:
20 1.1.4.2 nathanw * This product includes software developed by the University of
21 1.1.4.2 nathanw * California, Berkeley and its contributors.
22 1.1.4.2 nathanw * 4. Neither the name of the University nor the names of its contributors
23 1.1.4.2 nathanw * may be used to endorse or promote products derived from this software
24 1.1.4.2 nathanw * without specific prior written permission.
25 1.1.4.2 nathanw *
26 1.1.4.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 1.1.4.2 nathanw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 1.1.4.2 nathanw * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 1.1.4.2 nathanw * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 1.1.4.2 nathanw * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 1.1.4.2 nathanw * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 1.1.4.2 nathanw * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 1.1.4.2 nathanw * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 1.1.4.2 nathanw * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 1.1.4.2 nathanw * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 1.1.4.2 nathanw * SUCH DAMAGE.
37 1.1.4.2 nathanw *
38 1.1.4.2 nathanw * @(#)ptsc.c
39 1.1.4.2 nathanw */
40 1.1.4.2 nathanw
41 1.1.4.2 nathanw /*
42 1.1.4.2 nathanw * Power-tec SCSI-2 driver uses SFAS216 generic driver
43 1.1.4.2 nathanw *
44 1.1.4.2 nathanw * Thanks to Alsystems for loaning a development card and providing
45 1.1.4.2 nathanw * programming information.
46 1.1.4.2 nathanw */
47 1.1.4.2 nathanw
48 1.1.4.2 nathanw #include <sys/param.h>
49 1.1.4.2 nathanw #include <sys/systm.h>
50 1.1.4.2 nathanw #include <sys/kernel.h>
51 1.1.4.2 nathanw #include <sys/device.h>
52 1.1.4.2 nathanw #include <dev/scsipi/scsi_all.h>
53 1.1.4.2 nathanw #include <dev/scsipi/scsipi_all.h>
54 1.1.4.2 nathanw #include <dev/scsipi/scsiconf.h>
55 1.1.4.2 nathanw #include <uvm/uvm_extern.h>
56 1.1.4.2 nathanw #include <machine/pmap.h>
57 1.1.4.2 nathanw #include <machine/io.h>
58 1.1.4.2 nathanw #include <machine/intr.h>
59 1.1.4.2 nathanw #include <machine/bootconfig.h>
60 1.1.4.2 nathanw #include <acorn32/podulebus/podulebus.h>
61 1.1.4.2 nathanw #include <acorn32/podulebus/sfasreg.h>
62 1.1.4.2 nathanw #include <acorn32/podulebus/sfasvar.h>
63 1.1.4.2 nathanw #include <acorn32/podulebus/ptscreg.h>
64 1.1.4.2 nathanw #include <acorn32/podulebus/ptscvar.h>
65 1.1.4.2 nathanw #include <dev/podulebus/podules.h>
66 1.1.4.2 nathanw #include <dev/podulebus/powerromreg.h>
67 1.1.4.2 nathanw
68 1.1.4.2 nathanw void ptscattach __P((struct device *, struct device *, void *));
69 1.1.4.2 nathanw int ptscmatch __P((struct device *, struct cfdata *, void *));
70 1.1.4.2 nathanw
71 1.1.4.2 nathanw struct cfattach ptsc_ca = {
72 1.1.4.2 nathanw sizeof(struct ptsc_softc), ptscmatch, ptscattach
73 1.1.4.2 nathanw };
74 1.1.4.2 nathanw
75 1.1.4.2 nathanw int ptsc_intr __P((void *arg));
76 1.1.4.2 nathanw int ptsc_setup_dma __P((struct sfas_softc *sc, void *ptr, int len,
77 1.1.4.2 nathanw int mode));
78 1.1.4.2 nathanw int ptsc_build_dma_chain __P((struct sfas_softc *sc,
79 1.1.4.2 nathanw struct sfas_dma_chain *chain, void *p, int l));
80 1.1.4.2 nathanw int ptsc_need_bump __P((struct sfas_softc *sc, void *ptr, int len));
81 1.1.4.2 nathanw void ptsc_led __P((struct sfas_softc *sc, int mode));
82 1.1.4.2 nathanw
83 1.1.4.2 nathanw /*
84 1.1.4.2 nathanw * if we are a Power-tec SCSI-2 card
85 1.1.4.2 nathanw */
86 1.1.4.2 nathanw int
87 1.1.4.2 nathanw ptscmatch(pdp, cf, auxp)
88 1.1.4.2 nathanw struct device *pdp;
89 1.1.4.2 nathanw struct cfdata *cf;
90 1.1.4.2 nathanw void *auxp;
91 1.1.4.2 nathanw {
92 1.1.4.2 nathanw struct podule_attach_args *pa = (struct podule_attach_args *)auxp;
93 1.1.4.2 nathanw
94 1.1.4.2 nathanw /* Look for the card */
95 1.1.4.2 nathanw
96 1.1.4.2 nathanw /*
97 1.1.4.2 nathanw * All Power-tec cards effectively have PowerROMS. Note,
98 1.1.4.2 nathanw * though, that here, if we fail to initialise the loader, we
99 1.1.4.2 nathanw * assume this _is_ the right kind of card.
100 1.1.4.2 nathanw */
101 1.1.4.2 nathanw if (pa->pa_product == PODULE_ALSYSTEMS_SCSI &&
102 1.1.4.2 nathanw (podulebus_initloader(pa) != 0 ||
103 1.1.4.2 nathanw podloader_callloader(pa, 0, 0) == PRID_POWERTEC))
104 1.1.4.2 nathanw return 1;
105 1.1.4.2 nathanw
106 1.1.4.2 nathanw return 0;
107 1.1.4.2 nathanw }
108 1.1.4.2 nathanw
109 1.1.4.2 nathanw void
110 1.1.4.2 nathanw ptscattach(pdp, dp, auxp)
111 1.1.4.2 nathanw struct device *pdp;
112 1.1.4.2 nathanw struct device *dp;
113 1.1.4.2 nathanw void *auxp;
114 1.1.4.2 nathanw {
115 1.1.4.2 nathanw struct ptsc_softc *sc = (struct ptsc_softc *)dp;
116 1.1.4.2 nathanw struct podule_attach_args *pa;
117 1.1.4.2 nathanw ptsc_regmap_p rp = &sc->sc_regmap;
118 1.1.4.2 nathanw vu_char *fas;
119 1.1.4.2 nathanw
120 1.1.4.2 nathanw pa = (struct podule_attach_args *)auxp;
121 1.1.4.2 nathanw
122 1.1.4.2 nathanw if (pa->pa_podule_number == -1)
123 1.1.4.2 nathanw panic("Podule has disappeared !");
124 1.1.4.2 nathanw
125 1.1.4.2 nathanw sc->sc_specific.sc_podule_number = pa->pa_podule_number;
126 1.1.4.2 nathanw sc->sc_specific.sc_podule = pa->pa_podule;
127 1.1.4.2 nathanw sc->sc_specific.sc_iobase =
128 1.1.4.2 nathanw (vu_char *)sc->sc_specific.sc_podule->fast_base;
129 1.1.4.2 nathanw
130 1.1.4.2 nathanw rp->chipreset = &sc->sc_specific.sc_iobase[PTSC_CONTROL_CHIPRESET];
131 1.1.4.2 nathanw rp->inten = &sc->sc_specific.sc_iobase[PTSC_CONTROL_INTEN];
132 1.1.4.2 nathanw rp->status = &sc->sc_specific.sc_iobase[PTSC_STATUS];
133 1.1.4.2 nathanw rp->term = &sc->sc_specific.sc_iobase[PTSC_CONTROL_TERM];
134 1.1.4.2 nathanw rp->led = &sc->sc_specific.sc_iobase[PTSC_CONTROL_LED];
135 1.1.4.2 nathanw fas = &sc->sc_specific.sc_iobase[PTSC_FASOFFSET_BASE];
136 1.1.4.2 nathanw
137 1.1.4.2 nathanw rp->FAS216.sfas_tc_low = &fas[PTSC_FASOFFSET_TCL];
138 1.1.4.2 nathanw rp->FAS216.sfas_tc_mid = &fas[PTSC_FASOFFSET_TCM];
139 1.1.4.2 nathanw rp->FAS216.sfas_fifo = &fas[PTSC_FASOFFSET_FIFO];
140 1.1.4.2 nathanw rp->FAS216.sfas_command = &fas[PTSC_FASOFFSET_COMMAND];
141 1.1.4.2 nathanw rp->FAS216.sfas_dest_id = &fas[PTSC_FASOFFSET_DESTID];
142 1.1.4.2 nathanw rp->FAS216.sfas_timeout = &fas[PTSC_FASOFFSET_TIMEOUT];
143 1.1.4.2 nathanw rp->FAS216.sfas_syncper = &fas[PTSC_FASOFFSET_PERIOD];
144 1.1.4.2 nathanw rp->FAS216.sfas_syncoff = &fas[PTSC_FASOFFSET_OFFSET];
145 1.1.4.2 nathanw rp->FAS216.sfas_config1 = &fas[PTSC_FASOFFSET_CONFIG1];
146 1.1.4.2 nathanw rp->FAS216.sfas_clkconv = &fas[PTSC_FASOFFSET_CLOCKCONV];
147 1.1.4.2 nathanw rp->FAS216.sfas_test = &fas[PTSC_FASOFFSET_TEST];
148 1.1.4.2 nathanw rp->FAS216.sfas_config2 = &fas[PTSC_FASOFFSET_CONFIG2];
149 1.1.4.2 nathanw rp->FAS216.sfas_config3 = &fas[PTSC_FASOFFSET_CONFIG3];
150 1.1.4.2 nathanw rp->FAS216.sfas_tc_high = &fas[PTSC_FASOFFSET_TCH];
151 1.1.4.2 nathanw rp->FAS216.sfas_fifo_bot = &fas[PTSC_FASOFFSET_FIFOBOTTOM];
152 1.1.4.2 nathanw
153 1.1.4.2 nathanw sc->sc_softc.sc_fas = (sfas_regmap_p)rp;
154 1.1.4.2 nathanw sc->sc_softc.sc_spec = &sc->sc_specific;
155 1.1.4.2 nathanw
156 1.1.4.2 nathanw sc->sc_softc.sc_led = ptsc_led;
157 1.1.4.2 nathanw
158 1.1.4.2 nathanw sc->sc_softc.sc_setup_dma = ptsc_setup_dma;
159 1.1.4.2 nathanw sc->sc_softc.sc_build_dma_chain = ptsc_build_dma_chain;
160 1.1.4.2 nathanw sc->sc_softc.sc_need_bump = ptsc_need_bump;
161 1.1.4.2 nathanw
162 1.1.4.2 nathanw sc->sc_softc.sc_clock_freq = 40; /* Power-Tec runs at 8MHz */
163 1.1.4.2 nathanw sc->sc_softc.sc_timeout = 250; /* Set default timeout to 250ms */
164 1.1.4.2 nathanw sc->sc_softc.sc_config_flags = SFAS_NO_DMA /*| SFAS_NF_DEBUG*/;
165 1.1.4.2 nathanw sc->sc_softc.sc_host_id = 7; /* Should check the jumpers */
166 1.1.4.2 nathanw
167 1.1.4.2 nathanw sc->sc_softc.sc_bump_sz = NBPG;
168 1.1.4.2 nathanw sc->sc_softc.sc_bump_pa = 0x0;
169 1.1.4.2 nathanw
170 1.1.4.2 nathanw sfasinitialize((struct sfas_softc *)sc);
171 1.1.4.2 nathanw
172 1.1.4.2 nathanw sc->sc_softc.sc_adapter.adapt_dev = &sc->sc_softc.sc_dev;
173 1.1.4.2 nathanw sc->sc_softc.sc_adapter.adapt_nchannels = 1;
174 1.1.4.2 nathanw sc->sc_softc.sc_adapter.adapt_openings = 7;
175 1.1.4.2 nathanw sc->sc_softc.sc_adapter.adapt_max_periph = 1;
176 1.1.4.2 nathanw sc->sc_softc.sc_adapter.adapt_ioctl = NULL;
177 1.1.4.2 nathanw sc->sc_softc.sc_adapter.adapt_minphys = sfas_minphys;
178 1.1.4.3 nathanw sc->sc_softc.sc_adapter.adapt_request = sfas_scsi_request;
179 1.1.4.2 nathanw
180 1.1.4.2 nathanw sc->sc_softc.sc_channel.chan_adapter = &sc->sc_softc.sc_adapter;
181 1.1.4.2 nathanw sc->sc_softc.sc_channel.chan_bustype = &scsi_bustype;
182 1.1.4.2 nathanw sc->sc_softc.sc_channel.chan_channel = 0;
183 1.1.4.2 nathanw sc->sc_softc.sc_channel.chan_ntargets = 8;
184 1.1.4.2 nathanw sc->sc_softc.sc_channel.chan_nluns = 8;
185 1.1.4.2 nathanw sc->sc_softc.sc_channel.chan_id = sc->sc_softc.sc_host_id;
186 1.1.4.2 nathanw
187 1.1.4.2 nathanw /* Provide an override for the host id */
188 1.1.4.2 nathanw (void)get_bootconf_option(boot_args, "ptsc.hostid",
189 1.1.4.2 nathanw BOOTOPT_TYPE_INT, &sc->sc_softc.sc_channel.chan_id);
190 1.1.4.2 nathanw
191 1.1.4.2 nathanw printf(": host=%d", sc->sc_softc.sc_channel.chan_id);
192 1.1.4.2 nathanw
193 1.1.4.2 nathanw /* initialise the card */
194 1.1.4.2 nathanw /* *rp->term = 0;*/
195 1.1.4.2 nathanw *rp->inten = (PTSC_POLL?0:1);
196 1.1.4.2 nathanw *rp->led = 0;
197 1.1.4.2 nathanw
198 1.1.4.2 nathanw #if PTSC_POLL == 0
199 1.1.4.2 nathanw evcnt_attach_dynamic(&sc->sc_softc.sc_intrcnt, EVCNT_TYPE_INTR, NULL,
200 1.1.4.2 nathanw dp->dv_xname, "intr");
201 1.1.4.2 nathanw sc->sc_softc.sc_ih = podulebus_irq_establish(pa->pa_ih, IPL_BIO,
202 1.1.4.2 nathanw ptsc_intr, &sc->sc_softc, &sc->sc_softc.sc_intrcnt);
203 1.1.4.2 nathanw if (sc->sc_softc.sc_ih == NULL)
204 1.1.4.2 nathanw panic("%s: Cannot install IRQ handler\n", dp->dv_xname);
205 1.1.4.2 nathanw #else
206 1.1.4.2 nathanw printf(" polling");
207 1.1.4.3 nathanw sc->sc_softc.sc_adapter.adapt_flags = SCSIPI_ADAPT_POLL_ONLY;
208 1.1.4.2 nathanw #endif
209 1.1.4.2 nathanw
210 1.1.4.2 nathanw printf("\n");
211 1.1.4.2 nathanw
212 1.1.4.2 nathanw /* attach all scsi units on us */
213 1.1.4.2 nathanw config_found(dp, &sc->sc_softc.sc_channel, scsiprint);
214 1.1.4.2 nathanw }
215 1.1.4.2 nathanw
216 1.1.4.2 nathanw
217 1.1.4.2 nathanw int
218 1.1.4.2 nathanw ptsc_intr(arg)
219 1.1.4.2 nathanw void *arg;
220 1.1.4.2 nathanw {
221 1.1.4.2 nathanw struct sfas_softc *dev = arg;
222 1.1.4.2 nathanw ptsc_regmap_p rp;
223 1.1.4.2 nathanw int quickints;
224 1.1.4.2 nathanw
225 1.1.4.2 nathanw rp = (ptsc_regmap_p)dev->sc_fas;
226 1.1.4.2 nathanw
227 1.1.4.2 nathanw if (*rp->FAS216.sfas_status & SFAS_STAT_INTERRUPT_PENDING) {
228 1.1.4.2 nathanw quickints = 16;
229 1.1.4.2 nathanw do {
230 1.1.4.2 nathanw dev->sc_status = *rp->FAS216.sfas_status;
231 1.1.4.2 nathanw dev->sc_interrupt = *rp->FAS216.sfas_interrupt;
232 1.1.4.2 nathanw
233 1.1.4.2 nathanw if (dev->sc_interrupt & SFAS_INT_RESELECTED) {
234 1.1.4.2 nathanw dev->sc_resel[0] = *rp->FAS216.sfas_fifo;
235 1.1.4.2 nathanw dev->sc_resel[1] = *rp->FAS216.sfas_fifo;
236 1.1.4.2 nathanw }
237 1.1.4.2 nathanw
238 1.1.4.2 nathanw sfasintr(dev);
239 1.1.4.2 nathanw
240 1.1.4.2 nathanw } while((*rp->FAS216.sfas_status & SFAS_STAT_INTERRUPT_PENDING)
241 1.1.4.2 nathanw && --quickints);
242 1.1.4.2 nathanw }
243 1.1.4.2 nathanw
244 1.1.4.2 nathanw return(0); /* Pass interrupt on down the chain */
245 1.1.4.2 nathanw }
246 1.1.4.2 nathanw
247 1.1.4.2 nathanw /* Load transfer address into dma register */
248 1.1.4.2 nathanw void
249 1.1.4.2 nathanw ptsc_set_dma_adr(sc, ptr)
250 1.1.4.2 nathanw struct sfas_softc *sc;
251 1.1.4.2 nathanw void *ptr;
252 1.1.4.2 nathanw {
253 1.1.4.2 nathanw #if 0
254 1.1.4.2 nathanw ptsc_regmap_p rp;
255 1.1.4.2 nathanw unsigned int *p;
256 1.1.4.2 nathanw unsigned int d;
257 1.1.4.2 nathanw #endif
258 1.1.4.2 nathanw #if 0
259 1.1.4.2 nathanw printf("ptsc_set_dma_adr(sc = 0x%08x, ptr = 0x%08x)\n", (u_int)sc, (u_int)ptr);
260 1.1.4.2 nathanw #endif
261 1.1.4.2 nathanw return;
262 1.1.4.2 nathanw #if 0
263 1.1.4.2 nathanw rp = (ptsc_regmap_p)sc->sc_fas;
264 1.1.4.2 nathanw
265 1.1.4.2 nathanw d = (unsigned int)ptr;
266 1.1.4.2 nathanw p = (unsigned int *)((d & 0xFFFFFF) + (int)rp->dmabase);
267 1.1.4.2 nathanw
268 1.1.4.2 nathanw *rp->clear=0;
269 1.1.4.2 nathanw *p = d;
270 1.1.4.2 nathanw #endif
271 1.1.4.2 nathanw }
272 1.1.4.2 nathanw
273 1.1.4.2 nathanw /* Set DMA transfer counter */
274 1.1.4.2 nathanw void
275 1.1.4.2 nathanw ptsc_set_dma_tc(sc, len)
276 1.1.4.2 nathanw struct sfas_softc *sc;
277 1.1.4.2 nathanw unsigned int len;
278 1.1.4.2 nathanw {
279 1.1.4.2 nathanw printf("ptsc_set_dma_tc(sc, len = 0x%08x)", len);
280 1.1.4.2 nathanw
281 1.1.4.2 nathanw *sc->sc_fas->sfas_tc_low = len; len >>= 8;
282 1.1.4.2 nathanw *sc->sc_fas->sfas_tc_mid = len; len >>= 8;
283 1.1.4.2 nathanw *sc->sc_fas->sfas_tc_high = len;
284 1.1.4.2 nathanw }
285 1.1.4.2 nathanw
286 1.1.4.2 nathanw /* Set DMA mode */
287 1.1.4.2 nathanw void
288 1.1.4.2 nathanw ptsc_set_dma_mode(sc, mode)
289 1.1.4.2 nathanw struct sfas_softc *sc;
290 1.1.4.2 nathanw int mode;
291 1.1.4.2 nathanw {
292 1.1.4.2 nathanw #if 0
293 1.1.4.2 nathanw struct csc_specific *spec;
294 1.1.4.2 nathanw
295 1.1.4.2 nathanw spec = sc->sc_spec;
296 1.1.4.2 nathanw
297 1.1.4.2 nathanw spec->portbits = (spec->portbits & ~FLSC_PB_DMA_BITS) | mode;
298 1.1.4.2 nathanw *((flsc_regmap_p)sc->sc_fas)->hardbits = spec->portbits;
299 1.1.4.2 nathanw #endif
300 1.1.4.2 nathanw }
301 1.1.4.2 nathanw
302 1.1.4.2 nathanw /* Initialize DMA for transfer */
303 1.1.4.2 nathanw int
304 1.1.4.2 nathanw ptsc_setup_dma(sc, ptr, len, mode)
305 1.1.4.2 nathanw struct sfas_softc *sc;
306 1.1.4.2 nathanw void *ptr;
307 1.1.4.2 nathanw int len;
308 1.1.4.2 nathanw int mode;
309 1.1.4.2 nathanw {
310 1.1.4.2 nathanw int retval;
311 1.1.4.2 nathanw
312 1.1.4.2 nathanw retval = 0;
313 1.1.4.2 nathanw
314 1.1.4.2 nathanw #if 0
315 1.1.4.2 nathanw printf("ptsc_setup_dma(sc, ptr = 0x%08x, len = 0x%08x, mode = 0x%08x)\n", (u_int)ptr, len, mode);
316 1.1.4.2 nathanw #endif
317 1.1.4.2 nathanw return(0);
318 1.1.4.2 nathanw
319 1.1.4.2 nathanw #if 0
320 1.1.4.2 nathanw switch(mode) {
321 1.1.4.2 nathanw case SFAS_DMA_READ:
322 1.1.4.2 nathanw case SFAS_DMA_WRITE:
323 1.1.4.2 nathanw flsc_set_dma_adr(sc, ptr);
324 1.1.4.2 nathanw if (mode == SFAS_DMA_READ)
325 1.1.4.2 nathanw flsc_set_dma_mode(sc,FLSC_PB_ENABLE_DMA | FLSC_PB_DMA_READ);
326 1.1.4.2 nathanw else
327 1.1.4.2 nathanw flsc_set_dma_mode(sc,FLSC_PB_ENABLE_DMA | FLSC_PB_DMA_WRITE);
328 1.1.4.2 nathanw
329 1.1.4.2 nathanw flsc_set_dma_tc(sc, len);
330 1.1.4.2 nathanw break;
331 1.1.4.2 nathanw
332 1.1.4.2 nathanw case SFAS_DMA_CLEAR:
333 1.1.4.2 nathanw default:
334 1.1.4.2 nathanw flsc_set_dma_mode(sc, FLSC_PB_DISABLE_DMA);
335 1.1.4.2 nathanw flsc_set_dma_adr(sc, 0);
336 1.1.4.2 nathanw
337 1.1.4.2 nathanw retval = (*sc->sc_fas->sfas_tc_high << 16) |
338 1.1.4.2 nathanw (*sc->sc_fas->sfas_tc_mid << 8) |
339 1.1.4.2 nathanw *sc->sc_fas->sfas_tc_low;
340 1.1.4.2 nathanw
341 1.1.4.2 nathanw flsc_set_dma_tc(sc, 0);
342 1.1.4.2 nathanw break;
343 1.1.4.2 nathanw }
344 1.1.4.2 nathanw
345 1.1.4.2 nathanw return(retval);
346 1.1.4.2 nathanw #endif
347 1.1.4.2 nathanw }
348 1.1.4.2 nathanw
349 1.1.4.2 nathanw /* Check if address and len is ok for DMA transfer */
350 1.1.4.2 nathanw int
351 1.1.4.2 nathanw ptsc_need_bump(sc, ptr, len)
352 1.1.4.2 nathanw struct sfas_softc *sc;
353 1.1.4.2 nathanw void *ptr;
354 1.1.4.2 nathanw int len;
355 1.1.4.2 nathanw {
356 1.1.4.2 nathanw int p;
357 1.1.4.2 nathanw
358 1.1.4.2 nathanw p = (int)ptr & 0x03;
359 1.1.4.2 nathanw
360 1.1.4.2 nathanw if (p) {
361 1.1.4.2 nathanw p = 4-p;
362 1.1.4.2 nathanw
363 1.1.4.2 nathanw if (len < 256)
364 1.1.4.2 nathanw p = len;
365 1.1.4.2 nathanw }
366 1.1.4.2 nathanw
367 1.1.4.2 nathanw return(p);
368 1.1.4.2 nathanw }
369 1.1.4.2 nathanw
370 1.1.4.2 nathanw /* Interrupt driven routines */
371 1.1.4.2 nathanw int
372 1.1.4.2 nathanw ptsc_build_dma_chain(sc, chain, p, l)
373 1.1.4.2 nathanw struct sfas_softc *sc;
374 1.1.4.2 nathanw struct sfas_dma_chain *chain;
375 1.1.4.2 nathanw void *p;
376 1.1.4.2 nathanw int l;
377 1.1.4.2 nathanw {
378 1.1.4.2 nathanw #if 0
379 1.1.4.2 nathanw vm_offset_t pa, lastpa;
380 1.1.4.2 nathanw char *ptr;
381 1.1.4.2 nathanw int len, prelen, postlen, max_t, n;
382 1.1.4.2 nathanw #endif
383 1.1.4.2 nathanw #if 0
384 1.1.4.2 nathanw printf("ptsc_build_dma_chain()\n");
385 1.1.4.2 nathanw #endif
386 1.1.4.2 nathanw return(0);
387 1.1.4.2 nathanw
388 1.1.4.2 nathanw #if 0
389 1.1.4.2 nathanw if (l == 0)
390 1.1.4.2 nathanw return(0);
391 1.1.4.2 nathanw
392 1.1.4.2 nathanw #define set_link(n, p, l, f)\
393 1.1.4.2 nathanw do { chain[n].ptr = (p); chain[n].len = (l); chain[n++].flg = (f); } while(0)
394 1.1.4.2 nathanw
395 1.1.4.2 nathanw n = 0;
396 1.1.4.2 nathanw
397 1.1.4.2 nathanw if (l < 512)
398 1.1.4.2 nathanw set_link(n, (vm_offset_t)p, l, SFAS_CHAIN_BUMP);
399 1.1.4.2 nathanw else if (p >= (void *)0xFF000000) {
400 1.1.4.2 nathanw while(l != 0) {
401 1.1.4.2 nathanw len = ((l > sc->sc_bump_sz) ? sc->sc_bump_sz : l);
402 1.1.4.2 nathanw
403 1.1.4.2 nathanw set_link(n, (vm_offset_t)p, len, SFAS_CHAIN_BUMP);
404 1.1.4.2 nathanw
405 1.1.4.2 nathanw p += len;
406 1.1.4.2 nathanw l -= len;
407 1.1.4.2 nathanw }
408 1.1.4.2 nathanw } else {
409 1.1.4.2 nathanw ptr = p;
410 1.1.4.2 nathanw len = l;
411 1.1.4.2 nathanw
412 1.1.4.2 nathanw pa = kvtop(ptr);
413 1.1.4.2 nathanw prelen = ((int)ptr & 0x03);
414 1.1.4.2 nathanw
415 1.1.4.2 nathanw if (prelen) {
416 1.1.4.2 nathanw prelen = 4-prelen;
417 1.1.4.2 nathanw set_link(n, (vm_offset_t)ptr, prelen, SFAS_CHAIN_BUMP);
418 1.1.4.2 nathanw ptr += prelen;
419 1.1.4.2 nathanw len -= prelen;
420 1.1.4.2 nathanw }
421 1.1.4.2 nathanw
422 1.1.4.2 nathanw lastpa = 0;
423 1.1.4.2 nathanw while(len > 3) {
424 1.1.4.2 nathanw pa = kvtop(ptr);
425 1.1.4.2 nathanw max_t = NBPG - (pa & PGOFSET);
426 1.1.4.2 nathanw if (max_t > len)
427 1.1.4.2 nathanw max_t = len;
428 1.1.4.2 nathanw
429 1.1.4.2 nathanw max_t &= ~3;
430 1.1.4.2 nathanw
431 1.1.4.2 nathanw if (lastpa == pa)
432 1.1.4.2 nathanw sc->sc_chain[n-1].len += max_t;
433 1.1.4.2 nathanw else
434 1.1.4.2 nathanw set_link(n, pa, max_t, SFAS_CHAIN_DMA);
435 1.1.4.2 nathanw
436 1.1.4.2 nathanw lastpa = pa+max_t;
437 1.1.4.2 nathanw
438 1.1.4.2 nathanw ptr += max_t;
439 1.1.4.2 nathanw len -= max_t;
440 1.1.4.2 nathanw }
441 1.1.4.2 nathanw
442 1.1.4.2 nathanw if (len)
443 1.1.4.2 nathanw set_link(n, (vm_offset_t)ptr, len, SFAS_CHAIN_BUMP);
444 1.1.4.2 nathanw }
445 1.1.4.2 nathanw
446 1.1.4.2 nathanw return(n);
447 1.1.4.2 nathanw #endif
448 1.1.4.2 nathanw }
449 1.1.4.2 nathanw
450 1.1.4.2 nathanw /* Turn on/off led */
451 1.1.4.2 nathanw void
452 1.1.4.2 nathanw ptsc_led(sc, mode)
453 1.1.4.2 nathanw struct sfas_softc *sc;
454 1.1.4.2 nathanw int mode;
455 1.1.4.2 nathanw {
456 1.1.4.2 nathanw ptsc_regmap_p rp;
457 1.1.4.2 nathanw
458 1.1.4.2 nathanw rp = (ptsc_regmap_p)sc->sc_fas;
459 1.1.4.2 nathanw
460 1.1.4.2 nathanw if (mode) {
461 1.1.4.2 nathanw sc->sc_led_status++;
462 1.1.4.2 nathanw } else {
463 1.1.4.2 nathanw if (sc->sc_led_status)
464 1.1.4.2 nathanw sc->sc_led_status--;
465 1.1.4.2 nathanw }
466 1.1.4.2 nathanw *rp->led = (sc->sc_led_status?1:0);
467 1.1.4.2 nathanw }
468