2 comedi/drivers/ni_at_a2150.c
3 Driver for National Instruments AT-A2150 boards
4 Copyright (C) 2001, 2002 Frank Mori Hess <fmhess@users.sourceforge.net>
6 COMEDI - Linux Control and Measurement Device Interface
7 Copyright (C) 2000 David A. Schleef <ds@schleef.org>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 ************************************************************************
27 Description: National Instruments AT-A2150
28 Author: Frank Mori Hess
30 Devices: [National Instruments] AT-A2150C (at_a2150c), AT-2150S (at_a2150s)
32 If you want to ac couple the board's inputs, use AREF_OTHER.
34 Configuration options:
35 [0] - I/O port base address
36 [1] - IRQ (optional, required for timed conversions)
37 [2] - DMA (optional, required for timed conversions)
41 Yet another driver for obsolete hardware brought to you by Frank Hess.
42 Testing and debugging help provided by Dave Andruczyk.
44 This driver supports the boards:
49 The only difference is their master clock frequencies.
56 References (from ftp://ftp.natinst.com/support/manuals):
58 320360.pdf AT-A2150 User Manual
62 analog level triggering
67 #include <linux/interrupt.h>
68 #include <linux/slab.h>
69 #include "../comedidev.h"
71 #include <linux/ioport.h>
75 #include "comedi_fc.h"
78 #define A2150_DMA_BUFFER_SIZE 0xff00 /* size in bytes of dma buffer */
80 /* #define A2150_DEBUG enable debugging code */
81 #undef A2150_DEBUG /* disable debugging code */
83 /* Registers and bits */
84 #define CONFIG_REG 0x0
85 #define CHANNEL_BITS(x) ((x) & 0x7)
86 #define CHANNEL_MASK 0x7
87 #define CLOCK_SELECT_BITS(x) (((x) & 0x3) << 3)
88 #define CLOCK_DIVISOR_BITS(x) (((x) & 0x3) << 5)
89 #define CLOCK_MASK (0xf << 3)
90 #define ENABLE0_BIT 0x80 /* enable (don't internally ground) channels 0 and 1 */
91 #define ENABLE1_BIT 0x100 /* enable (don't internally ground) channels 2 and 3 */
92 #define AC0_BIT 0x200 /* ac couple channels 0,1 */
93 #define AC1_BIT 0x400 /* ac couple channels 2,3 */
94 #define APD_BIT 0x800 /* analog power down */
95 #define DPD_BIT 0x1000 /* digital power down */
96 #define TRIGGER_REG 0x2 /* trigger config register */
97 #define POST_TRIGGER_BITS 0x2
98 #define DELAY_TRIGGER_BITS 0x3
99 #define HW_TRIG_EN 0x10 /* enable hardware trigger */
100 #define FIFO_START_REG 0x6 /* software start aquistion trigger */
101 #define FIFO_RESET_REG 0x8 /* clears fifo + fifo flags */
102 #define FIFO_DATA_REG 0xa /* read data */
103 #define DMA_TC_CLEAR_REG 0xe /* clear dma terminal count interrupt */
104 #define STATUS_REG 0x12 /* read only */
105 #define FNE_BIT 0x1 /* fifo not empty */
106 #define OVFL_BIT 0x8 /* fifo overflow */
107 #define EDAQ_BIT 0x10 /* end of aquisition interrupt */
108 #define DCAL_BIT 0x20 /* offset calibration in progress */
109 #define INTR_BIT 0x40 /* interrupt has occured */
110 #define DMA_TC_BIT 0x80 /* dma terminal count interrupt has occured */
111 #define ID_BITS(x) (((x) >> 8) & 0x3)
112 #define IRQ_DMA_CNTRL_REG 0x12 /* write only */
113 #define DMA_CHAN_BITS(x) ((x) & 0x7) /* sets dma channel */
114 #define DMA_EN_BIT 0x8 /* enables dma */
115 #define IRQ_LVL_BITS(x) (((x) & 0xf) << 4) /* sets irq level */
116 #define FIFO_INTR_EN_BIT 0x100 /* enable fifo interrupts */
117 #define FIFO_INTR_FHF_BIT 0x200 /* interrupt fifo half full */
118 #define DMA_INTR_EN_BIT 0x800 /* enable interrupt on dma terminal count */
119 #define DMA_DEM_EN_BIT 0x1000 /* enables demand mode dma */
120 #define I8253_BASE_REG 0x14
121 #define I8253_MODE_REG 0x17
122 #define HW_COUNT_DISABLE 0x30 /* disable hardware counting of conversions */
126 int clock[4]; /* master clock periods, in nanoseconds */
127 int num_clocks; /* number of available master clock speeds */
128 int ai_speed; /* maximum conversion rate in nanoseconds */
131 /* analog input range */
132 static const struct comedi_lrange range_a2150 = {
135 RANGE(-2.828, 2.828),
139 /* enum must match board indices */
140 enum { a2150_c, a2150_s };
141 static const struct a2150_board a2150_boards[] = {
144 .clock = {31250, 22676, 20833, 19531},
150 .clock = {62500, 50000, 41667, 0},
157 * Useful for shorthand access to the particular board structure
159 #define thisboard ((const struct a2150_board *)dev->board_ptr)
161 struct a2150_private {
163 volatile unsigned int count; /* number of data points left to be taken */
164 unsigned int dma; /* dma channel */
165 s16 *dma_buffer; /* dma buffer */
166 unsigned int dma_transfer_size; /* size in bytes of dma transfers */
167 int irq_dma_bits; /* irq/dma register bits */
168 int config_bits; /* config register bits */
171 #define devpriv ((struct a2150_private *)dev->private)
173 static int a2150_attach(struct comedi_device *dev, struct comedi_devconfig *it);
174 static int a2150_detach(struct comedi_device *dev);
175 static int a2150_cancel(struct comedi_device *dev, struct comedi_subdevice *s);
177 static struct comedi_driver driver_a2150 = {
178 .driver_name = "ni_at_a2150",
179 .module = THIS_MODULE,
180 .attach = a2150_attach,
181 .detach = a2150_detach,
184 static irqreturn_t a2150_interrupt(int irq, void *d);
185 static int a2150_ai_cmdtest(struct comedi_device *dev,
186 struct comedi_subdevice *s, struct comedi_cmd *cmd);
187 static int a2150_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s);
188 static int a2150_ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
189 struct comedi_insn *insn, unsigned int *data);
190 static int a2150_get_timing(struct comedi_device *dev, unsigned int *period,
192 static int a2150_probe(struct comedi_device *dev);
193 static int a2150_set_chanlist(struct comedi_device *dev,
194 unsigned int start_channel,
195 unsigned int num_channels);
197 * A convenient macro that defines init_module() and cleanup_module(),
200 static int __init driver_a2150_init_module(void)
202 return comedi_driver_register(&driver_a2150);
205 static void __exit driver_a2150_cleanup_module(void)
207 comedi_driver_unregister(&driver_a2150);
210 module_init(driver_a2150_init_module);
211 module_exit(driver_a2150_cleanup_module);
215 static void ni_dump_regs(struct comedi_device *dev)
217 printk("config bits 0x%x\n", devpriv->config_bits);
218 printk("irq dma bits 0x%x\n", devpriv->irq_dma_bits);
219 printk("status bits 0x%x\n", inw(dev->iobase + STATUS_REG));
224 /* interrupt service routine */
225 static irqreturn_t a2150_interrupt(int irq, void *d)
230 struct comedi_device *dev = d;
231 struct comedi_subdevice *s = dev->read_subdev;
232 struct comedi_async *async;
233 struct comedi_cmd *cmd;
234 unsigned int max_points, num_points, residue, leftover;
236 static const int sample_size = sizeof(devpriv->dma_buffer[0]);
238 if (dev->attached == 0) {
239 comedi_error(dev, "premature interrupt");
242 /* initialize async here to make sure s is not NULL */
247 status = inw(dev->iobase + STATUS_REG);
249 if ((status & INTR_BIT) == 0) {
250 comedi_error(dev, "spurious interrupt");
254 if (status & OVFL_BIT) {
255 comedi_error(dev, "fifo overflow");
256 a2150_cancel(dev, s);
257 async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA;
260 if ((status & DMA_TC_BIT) == 0) {
261 comedi_error(dev, "caught non-dma interrupt? Aborting.");
262 a2150_cancel(dev, s);
263 async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA;
264 comedi_event(dev, s);
268 flags = claim_dma_lock();
269 disable_dma(devpriv->dma);
270 /* clear flip-flop to make sure 2-byte registers for
271 * count and address get set correctly */
272 clear_dma_ff(devpriv->dma);
274 /* figure out how many points to read */
275 max_points = devpriv->dma_transfer_size / sample_size;
276 /* residue is the number of points left to be done on the dma
277 * transfer. It should always be zero at this point unless
278 * the stop_src is set to external triggering.
280 residue = get_dma_residue(devpriv->dma) / sample_size;
281 num_points = max_points - residue;
282 if (devpriv->count < num_points && cmd->stop_src == TRIG_COUNT)
283 num_points = devpriv->count;
285 /* figure out how many points will be stored next time */
287 if (cmd->stop_src == TRIG_NONE) {
288 leftover = devpriv->dma_transfer_size / sample_size;
289 } else if (devpriv->count > max_points) {
290 leftover = devpriv->count - max_points;
291 if (leftover > max_points)
292 leftover = max_points;
294 /* there should only be a residue if collection was stopped by having
295 * the stop_src set to an external trigger, in which case there
296 * will be no more data
301 for (i = 0; i < num_points; i++) {
302 /* write data point to comedi buffer */
303 dpnt = devpriv->dma_buffer[i];
304 /* convert from 2's complement to unsigned coding */
306 cfc_write_to_buffer(s, dpnt);
307 if (cmd->stop_src == TRIG_COUNT) {
308 if (--devpriv->count == 0) { /* end of acquisition */
309 a2150_cancel(dev, s);
310 async->events |= COMEDI_CB_EOA;
317 set_dma_addr(devpriv->dma, virt_to_bus(devpriv->dma_buffer));
318 set_dma_count(devpriv->dma, leftover * sample_size);
319 enable_dma(devpriv->dma);
321 release_dma_lock(flags);
323 async->events |= COMEDI_CB_BLOCK;
325 comedi_event(dev, s);
327 /* clear interrupt */
328 outw(0x00, dev->iobase + DMA_TC_CLEAR_REG);
333 /* probes board type, returns offset */
334 static int a2150_probe(struct comedi_device *dev)
336 int status = inw(dev->iobase + STATUS_REG);
337 return ID_BITS(status);
340 static int a2150_attach(struct comedi_device *dev, struct comedi_devconfig *it)
342 struct comedi_subdevice *s;
343 unsigned long iobase = it->options[0];
344 unsigned int irq = it->options[1];
345 unsigned int dma = it->options[2];
346 static const int timeout = 2000;
349 printk("comedi%d: %s: io 0x%lx", dev->minor, driver_a2150.driver_name,
352 printk(", irq %u", irq);
357 printk(", dma %u", dma);
363 /* allocate and initialize dev->private */
364 if (alloc_private(dev, sizeof(struct a2150_private)) < 0)
368 printk(" io base address required\n");
372 /* check if io addresses are available */
373 if (!request_region(iobase, A2150_SIZE, driver_a2150.driver_name)) {
374 printk(" I/O port conflict\n");
377 dev->iobase = iobase;
381 /* check that irq is supported */
382 if (irq < 3 || irq == 8 || irq == 13 || irq > 15) {
383 printk(" invalid irq line %u\n", irq);
386 if (request_irq(irq, a2150_interrupt, 0,
387 driver_a2150.driver_name, dev)) {
388 printk("unable to allocate irq %u\n", irq);
391 devpriv->irq_dma_bits |= IRQ_LVL_BITS(irq);
396 if (dma == 4 || dma > 7) {
397 printk(" invalid dma channel %u\n", dma);
400 if (request_dma(dma, driver_a2150.driver_name)) {
401 printk(" failed to allocate dma channel %u\n", dma);
405 devpriv->dma_buffer =
406 kmalloc(A2150_DMA_BUFFER_SIZE, GFP_KERNEL | GFP_DMA);
407 if (devpriv->dma_buffer == NULL)
411 set_dma_mode(dma, DMA_MODE_READ);
413 devpriv->irq_dma_bits |= DMA_CHAN_BITS(dma);
416 dev->board_ptr = a2150_boards + a2150_probe(dev);
417 dev->board_name = thisboard->name;
419 if (alloc_subdevices(dev, 1) < 0)
422 /* analog input subdevice */
423 s = dev->subdevices + 0;
424 dev->read_subdev = s;
425 s->type = COMEDI_SUBD_AI;
426 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_OTHER | SDF_CMD_READ;
430 s->range_table = &range_a2150;
431 s->do_cmd = a2150_ai_cmd;
432 s->do_cmdtest = a2150_ai_cmdtest;
433 s->insn_read = a2150_ai_rinsn;
434 s->cancel = a2150_cancel;
436 /* need to do this for software counting of completed conversions, to
437 * prevent hardware count from stopping aquisition */
438 outw(HW_COUNT_DISABLE, dev->iobase + I8253_MODE_REG);
440 /* set card's irq and dma levels */
441 outw(devpriv->irq_dma_bits, dev->iobase + IRQ_DMA_CNTRL_REG);
443 /* reset and sync adc clock circuitry */
444 outw_p(DPD_BIT | APD_BIT, dev->iobase + CONFIG_REG);
445 outw_p(DPD_BIT, dev->iobase + CONFIG_REG);
446 /* initialize configuration register */
447 devpriv->config_bits = 0;
448 outw(devpriv->config_bits, dev->iobase + CONFIG_REG);
449 /* wait until offset calibration is done, then enable analog inputs */
450 for (i = 0; i < timeout; i++) {
451 if ((DCAL_BIT & inw(dev->iobase + STATUS_REG)) == 0)
457 (" timed out waiting for offset calibration to complete\n");
460 devpriv->config_bits |= ENABLE0_BIT | ENABLE1_BIT;
461 outw(devpriv->config_bits, dev->iobase + CONFIG_REG);
466 static int a2150_detach(struct comedi_device *dev)
468 printk("comedi%d: %s: remove\n", dev->minor, driver_a2150.driver_name);
470 /* only free stuff if it has been allocated by _attach */
472 /* put board in power-down mode */
473 outw(APD_BIT | DPD_BIT, dev->iobase + CONFIG_REG);
474 release_region(dev->iobase, A2150_SIZE);
478 free_irq(dev->irq, dev);
481 free_dma(devpriv->dma);
482 if (devpriv->dma_buffer)
483 kfree(devpriv->dma_buffer);
489 static int a2150_cancel(struct comedi_device *dev, struct comedi_subdevice *s)
491 /* disable dma on card */
492 devpriv->irq_dma_bits &= ~DMA_INTR_EN_BIT & ~DMA_EN_BIT;
493 outw(devpriv->irq_dma_bits, dev->iobase + IRQ_DMA_CNTRL_REG);
495 /* disable computer's dma */
496 disable_dma(devpriv->dma);
498 /* clear fifo and reset triggering circuitry */
499 outw(0, dev->iobase + FIFO_RESET_REG);
504 static int a2150_ai_cmdtest(struct comedi_device *dev,
505 struct comedi_subdevice *s, struct comedi_cmd *cmd)
512 /* step 1: make sure trigger sources are trivially valid */
514 tmp = cmd->start_src;
515 cmd->start_src &= TRIG_NOW | TRIG_EXT;
516 if (!cmd->start_src || tmp != cmd->start_src)
519 tmp = cmd->scan_begin_src;
520 cmd->scan_begin_src &= TRIG_TIMER;
521 if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
524 tmp = cmd->convert_src;
525 cmd->convert_src &= TRIG_NOW;
526 if (!cmd->convert_src || tmp != cmd->convert_src)
529 tmp = cmd->scan_end_src;
530 cmd->scan_end_src &= TRIG_COUNT;
531 if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
535 cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
536 if (!cmd->stop_src || tmp != cmd->stop_src)
542 /* step 2: make sure trigger sources are unique and mutually compatible */
544 if (cmd->start_src != TRIG_NOW && cmd->start_src != TRIG_EXT)
546 if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE)
552 /* step 3: make sure arguments are trivially compatible */
554 if (cmd->start_arg != 0) {
558 if (cmd->convert_src == TRIG_TIMER) {
559 if (cmd->convert_arg < thisboard->ai_speed) {
560 cmd->convert_arg = thisboard->ai_speed;
564 if (!cmd->chanlist_len) {
565 cmd->chanlist_len = 1;
568 if (cmd->scan_end_arg != cmd->chanlist_len) {
569 cmd->scan_end_arg = cmd->chanlist_len;
572 if (cmd->stop_src == TRIG_COUNT) {
573 if (!cmd->stop_arg) {
577 } else { /* TRIG_NONE */
578 if (cmd->stop_arg != 0) {
587 /* step 4: fix up any arguments */
589 if (cmd->scan_begin_src == TRIG_TIMER) {
590 tmp = cmd->scan_begin_arg;
591 a2150_get_timing(dev, &cmd->scan_begin_arg, cmd->flags);
592 if (tmp != cmd->scan_begin_arg)
599 /* check channel/gain list against card's limitations */
601 startChan = CR_CHAN(cmd->chanlist[0]);
602 for (i = 1; i < cmd->chanlist_len; i++) {
603 if (CR_CHAN(cmd->chanlist[i]) != (startChan + i)) {
605 "entries in chanlist must be consecutive channels, counting upwards\n");
609 if (cmd->chanlist_len == 2 && CR_CHAN(cmd->chanlist[0]) == 1) {
611 "length 2 chanlist must be channels 0,1 or channels 2,3");
614 if (cmd->chanlist_len == 3) {
616 "chanlist must have 1,2 or 4 channels");
619 if (CR_AREF(cmd->chanlist[0]) != CR_AREF(cmd->chanlist[1]) ||
620 CR_AREF(cmd->chanlist[2]) != CR_AREF(cmd->chanlist[3])) {
622 "channels 0/1 and 2/3 must have the same analog reference");
633 static int a2150_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
635 struct comedi_async *async = s->async;
636 struct comedi_cmd *cmd = &async->cmd;
637 unsigned long lock_flags;
638 unsigned int old_config_bits = devpriv->config_bits;
639 unsigned int trigger_bits;
641 if (!dev->irq || !devpriv->dma) {
643 " irq and dma required, cannot do hardware conversions");
646 if (cmd->flags & TRIG_RT) {
648 " dma incompatible with hard real-time interrupt (TRIG_RT), aborting");
651 /* clear fifo and reset triggering circuitry */
652 outw(0, dev->iobase + FIFO_RESET_REG);
655 if (a2150_set_chanlist(dev, CR_CHAN(cmd->chanlist[0]),
656 cmd->chanlist_len) < 0)
659 /* setup ac/dc coupling */
660 if (CR_AREF(cmd->chanlist[0]) == AREF_OTHER)
661 devpriv->config_bits |= AC0_BIT;
663 devpriv->config_bits &= ~AC0_BIT;
664 if (CR_AREF(cmd->chanlist[2]) == AREF_OTHER)
665 devpriv->config_bits |= AC1_BIT;
667 devpriv->config_bits &= ~AC1_BIT;
670 a2150_get_timing(dev, &cmd->scan_begin_arg, cmd->flags);
672 /* send timing, channel, config bits */
673 outw(devpriv->config_bits, dev->iobase + CONFIG_REG);
675 /* initialize number of samples remaining */
676 devpriv->count = cmd->stop_arg * cmd->chanlist_len;
678 /* enable computer's dma */
679 lock_flags = claim_dma_lock();
680 disable_dma(devpriv->dma);
681 /* clear flip-flop to make sure 2-byte registers for
682 * count and address get set correctly */
683 clear_dma_ff(devpriv->dma);
684 set_dma_addr(devpriv->dma, virt_to_bus(devpriv->dma_buffer));
685 /* set size of transfer to fill in 1/3 second */
686 #define ONE_THIRD_SECOND 333333333
687 devpriv->dma_transfer_size =
688 sizeof(devpriv->dma_buffer[0]) * cmd->chanlist_len *
689 ONE_THIRD_SECOND / cmd->scan_begin_arg;
690 if (devpriv->dma_transfer_size > A2150_DMA_BUFFER_SIZE)
691 devpriv->dma_transfer_size = A2150_DMA_BUFFER_SIZE;
692 if (devpriv->dma_transfer_size < sizeof(devpriv->dma_buffer[0]))
693 devpriv->dma_transfer_size = sizeof(devpriv->dma_buffer[0]);
694 devpriv->dma_transfer_size -=
695 devpriv->dma_transfer_size % sizeof(devpriv->dma_buffer[0]);
696 set_dma_count(devpriv->dma, devpriv->dma_transfer_size);
697 enable_dma(devpriv->dma);
698 release_dma_lock(lock_flags);
700 /* clear dma interrupt before enabling it, to try and get rid of that
701 * one spurious interrupt that has been happening */
702 outw(0x00, dev->iobase + DMA_TC_CLEAR_REG);
704 /* enable dma on card */
705 devpriv->irq_dma_bits |= DMA_INTR_EN_BIT | DMA_EN_BIT;
706 outw(devpriv->irq_dma_bits, dev->iobase + IRQ_DMA_CNTRL_REG);
708 /* may need to wait 72 sampling periods if timing was changed */
709 i8254_load(dev->iobase + I8253_BASE_REG, 0, 2, 72, 0);
711 /* setup start triggering */
713 /* decide if we need to wait 72 periods for valid data */
714 if (cmd->start_src == TRIG_NOW &&
715 (old_config_bits & CLOCK_MASK) !=
716 (devpriv->config_bits & CLOCK_MASK)) {
717 /* set trigger source to delay trigger */
718 trigger_bits |= DELAY_TRIGGER_BITS;
720 /* otherwise no delay */
721 trigger_bits |= POST_TRIGGER_BITS;
723 /* enable external hardware trigger */
724 if (cmd->start_src == TRIG_EXT) {
725 trigger_bits |= HW_TRIG_EN;
726 } else if (cmd->start_src == TRIG_OTHER) {
727 /* XXX add support for level/slope start trigger using TRIG_OTHER */
728 comedi_error(dev, "you shouldn't see this?");
730 /* send trigger config bits */
731 outw(trigger_bits, dev->iobase + TRIGGER_REG);
733 /* start aquisition for soft trigger */
734 if (cmd->start_src == TRIG_NOW) {
735 outw(0, dev->iobase + FIFO_START_REG);
744 static int a2150_ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
745 struct comedi_insn *insn, unsigned int *data)
748 static const int timeout = 100000;
749 static const int filter_delay = 36;
751 /* clear fifo and reset triggering circuitry */
752 outw(0, dev->iobase + FIFO_RESET_REG);
755 if (a2150_set_chanlist(dev, CR_CHAN(insn->chanspec), 1) < 0)
758 /* set dc coupling */
759 devpriv->config_bits &= ~AC0_BIT;
760 devpriv->config_bits &= ~AC1_BIT;
762 /* send timing, channel, config bits */
763 outw(devpriv->config_bits, dev->iobase + CONFIG_REG);
765 /* disable dma on card */
766 devpriv->irq_dma_bits &= ~DMA_INTR_EN_BIT & ~DMA_EN_BIT;
767 outw(devpriv->irq_dma_bits, dev->iobase + IRQ_DMA_CNTRL_REG);
769 /* setup start triggering */
770 outw(0, dev->iobase + TRIGGER_REG);
772 /* start aquisition for soft trigger */
773 outw(0, dev->iobase + FIFO_START_REG);
775 /* there is a 35.6 sample delay for data to get through the antialias filter */
776 for (n = 0; n < filter_delay; n++) {
777 for (i = 0; i < timeout; i++) {
778 if (inw(dev->iobase + STATUS_REG) & FNE_BIT)
783 comedi_error(dev, "timeout");
786 inw(dev->iobase + FIFO_DATA_REG);
790 for (n = 0; n < insn->n; n++) {
791 for (i = 0; i < timeout; i++) {
792 if (inw(dev->iobase + STATUS_REG) & FNE_BIT)
797 comedi_error(dev, "timeout");
803 data[n] = inw(dev->iobase + FIFO_DATA_REG);
805 printk(" data is %i\n", data[n]);
810 /* clear fifo and reset triggering circuitry */
811 outw(0, dev->iobase + FIFO_RESET_REG);
816 /* sets bits in devpriv->clock_bits to nearest approximation of requested period,
817 * adjusts requested period to actual timing. */
818 static int a2150_get_timing(struct comedi_device *dev, unsigned int *period,
822 int lub_divisor_shift, lub_index, glb_divisor_shift, glb_index;
825 /* initialize greatest lower and least upper bounds */
826 lub_divisor_shift = 3;
828 lub = thisboard->clock[lub_index] * (1 << lub_divisor_shift);
829 glb_divisor_shift = 0;
830 glb_index = thisboard->num_clocks - 1;
831 glb = thisboard->clock[glb_index] * (1 << glb_divisor_shift);
833 /* make sure period is in available range */
839 /* we can multiply period by 1, 2, 4, or 8, using (1 << i) */
840 for (i = 0; i < 4; i++) {
841 /* there are a maximum of 4 master clocks */
842 for (j = 0; j < thisboard->num_clocks; j++) {
843 /* temp is the period in nanosec we are evaluating */
844 temp = thisboard->clock[j] * (1 << i);
845 /* if it is the best match yet */
846 if (temp < lub && temp >= *period) {
847 lub_divisor_shift = i;
851 if (temp > glb && temp <= *period) {
852 glb_divisor_shift = i;
858 flags &= TRIG_ROUND_MASK;
860 case TRIG_ROUND_NEAREST:
862 /* if least upper bound is better approximation */
863 if (lub - *period < *period - glb) {
872 case TRIG_ROUND_DOWN:
877 /* set clock bits for config register appropriately */
878 devpriv->config_bits &= ~CLOCK_MASK;
879 if (*period == lub) {
880 devpriv->config_bits |=
881 CLOCK_SELECT_BITS(lub_index) |
882 CLOCK_DIVISOR_BITS(lub_divisor_shift);
884 devpriv->config_bits |=
885 CLOCK_SELECT_BITS(glb_index) |
886 CLOCK_DIVISOR_BITS(glb_divisor_shift);
892 static int a2150_set_chanlist(struct comedi_device *dev,
893 unsigned int start_channel,
894 unsigned int num_channels)
896 if (start_channel + num_channels > 4)
899 devpriv->config_bits &= ~CHANNEL_MASK;
901 switch (num_channels) {
903 devpriv->config_bits |= CHANNEL_BITS(0x4 | start_channel);
906 if (start_channel == 0) {
907 devpriv->config_bits |= CHANNEL_BITS(0x2);
908 } else if (start_channel == 2) {
909 devpriv->config_bits |= CHANNEL_BITS(0x3);
915 devpriv->config_bits |= CHANNEL_BITS(0x1);
925 MODULE_AUTHOR("Comedi http://www.comedi.org");
926 MODULE_DESCRIPTION("Comedi low-level driver");
927 MODULE_LICENSE("GPL");