Lines Matching +full:adc +full:- +full:res +full:- +full:names
1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2003-2004 Poul-Henning Kamp
15 * 3. The names of the authors may not be used to endorse or promote
31 * This is a device driver or the Adlink 9812 and 9810 ADC cards, mainly
33 * in the VLF band. See http://phk.freebsd.dk/loran-c
79 # define STATE_RESET -1
105 struct resource *res[3]; member
136 u = bus_read_4(sc->res[0], 0x38); in adlink_intr()
139 bus_write_4(sc->res[0], 0x38, u | 0x003f4000); in adlink_intr()
141 sc->sample += sc->p0->chunksize / 2; in adlink_intr()
142 pg = sc->next; in adlink_intr()
143 *(pg->sample) = sc->sample; in adlink_intr()
145 u = bus_read_4(sc->res[1], 0x18); in adlink_intr()
147 sc->p0->state = EIO; in adlink_intr()
149 if (sc->p0->state != STATE_RUN) { in adlink_intr()
150 printf("adlink: stopping %d\n", sc->p0->state); in adlink_intr()
154 pg = pg->next; in adlink_intr()
155 sc->next = pg; in adlink_intr()
156 *(pg->sample) = 0; in adlink_intr()
157 bus_write_4(sc->res[0], 0x24, pg->phys); in adlink_intr()
158 bus_write_4(sc->res[0], 0x28, sc->p0->chunksize); in adlink_intr()
172 sc = dev->si_drv1; in adlink_mmap()
174 return (-1); in adlink_mmap()
176 *paddr = vtophys(sc->p0); in adlink_mmap()
180 pg = sc->chunks; in adlink_mmap()
181 for (i = 0; i < sc->nchunks; i++, pg++) { in adlink_mmap()
182 if (offset - o >= sc->p0->chunksize) { in adlink_mmap()
183 o += sc->p0->chunksize; in adlink_mmap()
186 *paddr = pg->phys + (offset - o); in adlink_mmap()
189 return (-1); in adlink_mmap()
201 sc = dev->si_drv1; in adlink_ioctl()
206 if (sc->p0->state == STATE_RUN) in adlink_ioctl()
210 sc->p0->divisor = u; in adlink_ioctl()
213 if (sc->p0->state != STATE_RESET) in adlink_ioctl()
217 if (sc->p0->ringsize != 0 && sc->p0->ringsize % u) in adlink_ioctl()
219 sc->p0->chunksize = u; in adlink_ioctl()
222 if (sc->p0->state != STATE_RESET) in adlink_ioctl()
226 if (sc->p0->chunksize != 0 && u % sc->p0->chunksize) in adlink_ioctl()
228 sc->p0->ringsize = u; in adlink_ioctl()
231 if (sc->p0->state == STATE_RUN) in adlink_ioctl()
233 if (sc->p0->state == STATE_RESET) { in adlink_ioctl()
235 if (sc->p0->chunksize == 0) in adlink_ioctl()
236 sc->p0->chunksize = 4 * PAGE_SIZE; in adlink_ioctl()
237 if (sc->p0->ringsize == 0) in adlink_ioctl()
238 sc->p0->ringsize = 16 * sc->p0->chunksize; in adlink_ioctl()
239 if (sc->p0->divisor == 0) in adlink_ioctl()
240 sc->p0->divisor = 4; in adlink_ioctl()
242 sc->nchunks = sc->p0->ringsize / sc->p0->chunksize; in adlink_ioctl()
243 if (sc->nchunks * sizeof (*pg->sample) + in adlink_ioctl()
244 sizeof *sc->p0 > PAGE_SIZE) in adlink_ioctl()
246 sc->p0->o_ring = PAGE_SIZE; in adlink_ioctl()
247 sample = (uint64_t *)(sc->p0 + 1); in adlink_ioctl()
248 sc->p0->o_sample = in adlink_ioctl()
249 (uintptr_t)sample - (uintptr_t)(sc->p0); in adlink_ioctl()
250 pg = malloc(sizeof *pg * sc->nchunks, in adlink_ioctl()
252 sc->chunks = pg; in adlink_ioctl()
253 for (i = 0; i < sc->nchunks; i++) { in adlink_ioctl()
254 pg->sample = sample; in adlink_ioctl()
255 *pg->sample = 0; in adlink_ioctl()
257 pg->virt = contigmalloc(sc->p0->chunksize, in adlink_ioctl()
261 pg->phys = vtophys(pg->virt); in adlink_ioctl()
262 if (i == sc->nchunks - 1) in adlink_ioctl()
263 pg->next = sc->chunks; in adlink_ioctl()
265 pg->next = pg + 1; in adlink_ioctl()
268 sc->next = sc->chunks; in adlink_ioctl()
272 pg = sc->chunks; in adlink_ioctl()
273 for (i = 0; i < sc->nchunks; i++) { in adlink_ioctl()
274 *pg->sample = 0; in adlink_ioctl()
279 bus_write_4(sc->res[0], 0x38, 0x00004000); in adlink_ioctl()
282 bus_write_4(sc->res[1], 0x00, 1); in adlink_ioctl()
285 bus_write_4(sc->res[1], 0x04, sc->p0->divisor); in adlink_ioctl()
288 bus_write_4(sc->res[1], 0x08, 0); in adlink_ioctl()
291 bus_write_4(sc->res[1], 0x0c, 0); in adlink_ioctl()
294 bus_write_4(sc->res[1], 0x10, 0); in adlink_ioctl()
297 bus_write_4(sc->res[1], 0x18, 3); in adlink_ioctl()
300 bus_write_4(sc->res[1], 0x20, 2); in adlink_ioctl()
303 sc->p0->state = STATE_RUN; in adlink_ioctl()
306 pg = sc->next = sc->chunks; in adlink_ioctl()
307 *(pg->sample) = 0; in adlink_ioctl()
308 bus_write_4(sc->res[0], 0x24, pg->phys); in adlink_ioctl()
309 bus_write_4(sc->res[0], 0x28, sc->p0->chunksize); in adlink_ioctl()
310 u = bus_read_4(sc->res[0], 0x3c); in adlink_ioctl()
311 bus_write_4(sc->res[0], 0x3c, u | 0x00000600); in adlink_ioctl()
314 bus_write_4(sc->res[1], 0x1c, 1); in adlink_ioctl()
318 if (sc->p0->state == STATE_RESET) in adlink_ioctl()
320 sc->p0->state = EINTR; in adlink_ioctl()
321 while (*(sc->next->sample) == 0) in adlink_ioctl()
330 if (sc->p0->state == STATE_RESET) in adlink_ioctl()
332 sc->p0->state = EINTR; in adlink_ioctl()
333 while (*(sc->next->samp) == 0) in adlink_ioctl()
352 .desc ="Adlink PCI-9812 4 ch 12 bit 20 msps" }
377 { -1, 0, 0 }
388 sc->device = self; in adlink_attach()
390 error = bus_alloc_resources(self, adlink_res_spec, sc->res); in adlink_attach()
394 i = bus_setup_intr(self, sc->res[2], INTR_TYPE_MISC, in adlink_attach()
395 adlink_intr, NULL, sc, &sc->intrhand); in adlink_attach()
398 i = bus_setup_intr(self, sc->res[2], in adlink_attach()
400 NULL, (driver_intr_t *)adlink_intr, sc, &sc->intrhand); in adlink_attach()
404 bus_release_resources(self, adlink_res_spec, sc->res); in adlink_attach()
408 sc->p0 = malloc(PAGE_SIZE, M_DEVBUF, M_WAITOK | M_ZERO); in adlink_attach()
409 sc->p0->version = PAGE0VERSION; in adlink_attach()
410 sc->p0->state = STATE_RESET; in adlink_attach()
412 sc->dev = make_dev(&adlink_cdevsw, device_get_unit(self), in adlink_attach()
414 sc->dev->si_drv1 = sc; in adlink_attach()