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