2 comedi/drivers/cb_pcidas.c
4 Developed by Ivan Martinez and Frank Mori Hess, with valuable help from
5 David Schleef and the rest of the Comedi developers comunity.
7 Copyright (C) 2001-2003 Ivan Martinez <imr@oersted.dtu.dk>
8 Copyright (C) 2001,2002 Frank Mori Hess <fmhess@users.sourceforge.net>
10 COMEDI - Linux Control and Measurement Device Interface
11 Copyright (C) 1997-8 David A. Schleef <ds@schleef.org>
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 ************************************************************************
31 Description: MeasurementComputing PCI-DAS series with the AMCC S5933 PCI controller
32 Author: Ivan Martinez <imr@oersted.dtu.dk>,
33 Frank Mori Hess <fmhess@users.sourceforge.net>
35 Devices: [Measurement Computing] PCI-DAS1602/16 (cb_pcidas),
36 PCI-DAS1602/16jr, PCI-DAS1602/12, PCI-DAS1200, PCI-DAS1200jr,
37 PCI-DAS1000, PCI-DAS1001, PCI_DAS1002
40 There are many reports of the driver being used with most of the
41 supported cards. Despite no detailed log is maintained, it can
42 be said that the driver is quite tested and stable.
44 The boards may be autocalibrated using the comedi_calibrate
47 Configuration options:
48 [0] - PCI bus of device (optional)
49 [1] - PCI slot of device (optional)
50 If bus/slot is not specified, the first supported
51 PCI device found will be used.
53 For commands, the scanned channels must be consecutive
54 (i.e. 4-5-6-7, 2-3-4,...), and must all have the same
58 For start_src == TRIG_EXT, the A/D EXTERNAL TRIGGER IN (pin 45) is used.
59 For 1602 series, the start_arg is interpreted as follows:
60 start_arg == 0 => gated triger (level high)
61 start_arg == CR_INVERT => gated triger (level low)
62 start_arg == CR_EDGE => Rising edge
63 start_arg == CR_EDGE | CR_INVERT => Falling edge
64 For the other boards the trigger will be done on rising edge
70 analog triggering on 1602 series
73 #include "../comedidev.h"
74 #include <linux/delay.h>
75 #include <linux/interrupt.h>
79 #include "amcc_s5933.h"
80 #include "comedi_pci.h"
81 #include "comedi_fc.h"
83 #undef CB_PCIDAS_DEBUG /* disable debugging code */
84 /* #define CB_PCIDAS_DEBUG enable debugging code */
86 /* PCI vendor number of ComputerBoards/MeasurementComputing */
87 #define PCI_VENDOR_ID_CB 0x1307
88 #define TIMER_BASE 100 /* 10MHz master clock */
89 #define AI_BUFFER_SIZE 1024 /* maximum fifo size of any supported board */
90 #define AO_BUFFER_SIZE 1024 /* maximum fifo size of any supported board */
91 #define NUM_CHANNELS_8800 8
92 #define NUM_CHANNELS_7376 1
93 #define NUM_CHANNELS_8402 2
94 #define NUM_CHANNELS_DAC08 1
96 /* PCI-DAS base addresses */
98 /* indices of base address regions */
99 #define S5933_BADRINDEX 0
100 #define CONT_STAT_BADRINDEX 1
101 #define ADC_FIFO_BADRINDEX 2
102 #define PACER_BADRINDEX 3
103 #define AO_BADRINDEX 4
104 /* sizes of io regions */
105 #define CONT_STAT_SIZE 10
106 #define ADC_FIFO_SIZE 4
107 #define PACER_SIZE 12
110 /* Control/Status registers */
111 #define INT_ADCFIFO 0 /* INTERRUPT / ADC FIFO register */
112 #define INT_EOS 0x1 /* interrupt end of scan */
113 #define INT_FHF 0x2 /* interrupt fifo half full */
114 #define INT_FNE 0x3 /* interrupt fifo not empty */
115 #define INT_MASK 0x3 /* mask of interrupt select bits */
116 #define INTE 0x4 /* interrupt enable */
117 #define DAHFIE 0x8 /* dac half full interrupt enable */
118 #define EOAIE 0x10 /* end of acquisition interrupt enable */
119 #define DAHFI 0x20 /* dac half full read status / write interrupt clear */
120 #define EOAI 0x40 /* read end of acq. interrupt status / write clear */
121 #define INT 0x80 /* read interrupt status / write clear */
122 #define EOBI 0x200 /* read end of burst interrupt status */
123 #define ADHFI 0x400 /* read half-full interrupt status */
124 #define ADNEI 0x800 /* read fifo not empty interrupt latch status */
125 #define ADNE 0x1000 /* read, fifo not empty (realtime, not latched) status */
126 #define DAEMIE 0x1000 /* write, dac empty interrupt enable */
127 #define LADFUL 0x2000 /* read fifo overflow / write clear */
128 #define DAEMI 0x4000 /* dac fifo empty interrupt status / write clear */
130 #define ADCMUX_CONT 2 /* ADC CHANNEL MUX AND CONTROL register */
131 #define BEGIN_SCAN(x) ((x) & 0xf)
132 #define END_SCAN(x) (((x) & 0xf) << 4)
133 #define GAIN_BITS(x) (((x) & 0x3) << 8)
134 #define UNIP 0x800 /* Analog front-end unipolar for range */
135 #define SE 0x400 /* Inputs in single-ended mode */
136 #define PACER_MASK 0x3000 /* pacer source bits */
137 #define PACER_INT 0x1000 /* internal pacer */
138 #define PACER_EXT_FALL 0x2000 /* external falling edge */
139 #define PACER_EXT_RISE 0x3000 /* external rising edge */
140 #define EOC 0x4000 /* adc not busy */
142 #define TRIG_CONTSTAT 4 /* TRIGGER CONTROL/STATUS register */
143 #define SW_TRIGGER 0x1 /* software start trigger */
144 #define EXT_TRIGGER 0x2 /* external start trigger */
145 #define ANALOG_TRIGGER 0x3 /* external analog trigger */
146 #define TRIGGER_MASK 0x3 /* mask of bits that determine start trigger */
147 #define TGPOL 0x04 /* invert the edge/level of the external trigger (1602 only) */
148 #define TGSEL 0x08 /* if set edge triggered, otherwise level trigerred (1602 only) */
149 #define TGEN 0x10 /* enable external start trigger */
150 #define BURSTE 0x20 /* burst mode enable */
151 #define XTRCL 0x80 /* clear external trigger */
153 #define CALIBRATION_REG 6 /* CALIBRATION register */
154 #define SELECT_8800_BIT 0x100 /* select 8800 caldac */
155 #define SELECT_TRIMPOT_BIT 0x200 /* select ad7376 trim pot */
156 #define SELECT_DAC08_BIT 0x400 /* select dac08 caldac */
157 #define CAL_SRC_BITS(x) (((x) & 0x7) << 11)
158 #define CAL_EN_BIT 0x4000 /* read calibration source instead of analog input channel 0 */
159 #define SERIAL_DATA_IN_BIT 0x8000 /* serial data stream going to 8800 and 7376 */
161 #define DAC_CSR 0x8 /* dac control and status register */
163 DACEN
= 0x2, /* dac enable */
164 DAC_MODE_UPDATE_BOTH
= 0x80, /* update both dacs when dac0 is written */
166 static inline unsigned int DAC_RANGE(unsigned int channel
, unsigned int range
)
168 return (range
& 0x3) << (8 + 2 * (channel
& 0x1));
171 static inline unsigned int DAC_RANGE_MASK(unsigned int channel
)
173 return 0x3 << (8 + 2 * (channel
& 0x1));
176 /* bits for 1602 series only */
177 enum dac_csr_bits_1602
{
178 DAC_EMPTY
= 0x1, /* dac fifo empty, read, write clear */
179 DAC_START
= 0x4, /* start/arm dac fifo operations */
180 DAC_PACER_MASK
= 0x18, /* bits that set dac pacer source */
181 DAC_PACER_INT
= 0x8, /* dac internal pacing */
182 DAC_PACER_EXT_FALL
= 0x10, /* dac external pacing, falling edge */
183 DAC_PACER_EXT_RISE
= 0x18, /* dac external pacing, rising edge */
185 static inline unsigned int DAC_CHAN_EN(unsigned int channel
)
187 return 1 << (5 + (channel
& 0x1)); /* enable channel 0 or 1 */
190 /* analog input fifo */
191 #define ADCDATA 0 /* ADC DATA register */
192 #define ADCFIFOCLR 2 /* ADC FIFO CLEAR */
194 /* pacer, counter, dio registers */
199 /* analog output registers for 100x, 1200 series */
200 static inline unsigned int DAC_DATA_REG(unsigned int channel
)
202 return 2 * (channel
& 0x1);
205 /* analog output registers for 1602 series*/
206 #define DACDATA 0 /* DAC DATA register */
207 #define DACFIFOCLR 2 /* DAC FIFO CLEAR */
209 /* bit in hexadecimal representation of range index that indicates unipolar input range */
210 #define IS_UNIPOLAR 0x4
211 /* analog input ranges for most boards */
212 static const struct comedi_lrange cb_pcidas_ranges
= {
226 /* pci-das1001 input ranges */
227 static const struct comedi_lrange cb_pcidas_alt_ranges
= {
241 /* analog output ranges */
242 static const struct comedi_lrange cb_pcidas_ao_ranges
= {
257 struct cb_pcidas_board
{
259 unsigned short device_id
;
260 int ai_se_chans
; /* Inputs in single-ended mode */
261 int ai_diff_chans
; /* Inputs in differential mode */
262 int ai_bits
; /* analog input resolution */
263 int ai_speed
; /* fastest conversion period in ns */
264 int ao_nchan
; /* number of analog out channels */
265 int has_ao_fifo
; /* analog output has fifo */
266 int ao_scan_speed
; /* analog output speed for 1602 series (for a scan, not conversion) */
267 int fifo_size
; /* number of samples fifo can hold */
268 const struct comedi_lrange
*ranges
;
269 enum trimpot_model trimpot
;
270 unsigned has_dac08
:1;
271 unsigned has_ai_trig_gated
:1; /* Tells if the AI trigger can be gated */
272 unsigned has_ai_trig_invert
:1; /* Tells if the AI trigger can be inverted */
275 static const struct cb_pcidas_board cb_pcidas_boards
[] = {
277 .name
= "pci-das1602/16",
285 .ao_scan_speed
= 10000,
287 .ranges
= &cb_pcidas_ranges
,
290 .has_ai_trig_gated
= 1,
291 .has_ai_trig_invert
= 1,
294 .name
= "pci-das1200",
303 .ranges
= &cb_pcidas_ranges
,
306 .has_ai_trig_gated
= 0,
307 .has_ai_trig_invert
= 0,
310 .name
= "pci-das1602/12",
318 .ao_scan_speed
= 4000,
320 .ranges
= &cb_pcidas_ranges
,
323 .has_ai_trig_gated
= 1,
324 .has_ai_trig_invert
= 1,
327 .name
= "pci-das1200/jr",
336 .ranges
= &cb_pcidas_ranges
,
339 .has_ai_trig_gated
= 0,
340 .has_ai_trig_invert
= 0,
343 .name
= "pci-das1602/16/jr",
352 .ranges
= &cb_pcidas_ranges
,
355 .has_ai_trig_gated
= 1,
356 .has_ai_trig_invert
= 1,
359 .name
= "pci-das1000",
368 .ranges
= &cb_pcidas_ranges
,
371 .has_ai_trig_gated
= 0,
372 .has_ai_trig_invert
= 0,
375 .name
= "pci-das1001",
384 .ranges
= &cb_pcidas_alt_ranges
,
387 .has_ai_trig_gated
= 0,
388 .has_ai_trig_invert
= 0,
391 .name
= "pci-das1002",
400 .ranges
= &cb_pcidas_ranges
,
403 .has_ai_trig_gated
= 0,
404 .has_ai_trig_invert
= 0,
408 static DEFINE_PCI_DEVICE_TABLE(cb_pcidas_pci_table
) = {
409 { PCI_DEVICE(PCI_VENDOR_ID_CB
, 0x0001) },
410 { PCI_DEVICE(PCI_VENDOR_ID_CB
, 0x000f) },
411 { PCI_DEVICE(PCI_VENDOR_ID_CB
, 0x0010) },
412 { PCI_DEVICE(PCI_VENDOR_ID_CB
, 0x0019) },
413 { PCI_DEVICE(PCI_VENDOR_ID_CB
, 0x001c) },
414 { PCI_DEVICE(PCI_VENDOR_ID_CB
, 0x004c) },
415 { PCI_DEVICE(PCI_VENDOR_ID_CB
, 0x001a) },
416 { PCI_DEVICE(PCI_VENDOR_ID_CB
, 0x001b) },
420 MODULE_DEVICE_TABLE(pci
, cb_pcidas_pci_table
);
423 * Useful for shorthand access to the particular board structure
425 #define thisboard ((const struct cb_pcidas_board *)dev->board_ptr)
427 /* this structure is for data unique to this hardware driver. If
428 several hardware drivers keep similar information in this structure,
429 feel free to suggest moving the variable to the struct comedi_device struct. */
430 struct cb_pcidas_private
{
431 /* would be useful for a PCI device */
432 struct pci_dev
*pci_dev
;
434 unsigned long s5933_config
;
435 unsigned long control_status
;
436 unsigned long adc_fifo
;
437 unsigned long pacer_counter_dio
;
438 unsigned long ao_registers
;
439 /* divisors of master clock for analog input pacing */
440 unsigned int divisor1
;
441 unsigned int divisor2
;
442 volatile unsigned int count
; /* number of analog input samples remaining */
443 volatile unsigned int adc_fifo_bits
; /* bits to write to interrupt/adcfifo register */
444 volatile unsigned int s5933_intcsr_bits
; /* bits to write to amcc s5933 interrupt control/status register */
445 volatile unsigned int ao_control_bits
; /* bits to write to ao control and status register */
446 short ai_buffer
[AI_BUFFER_SIZE
];
447 short ao_buffer
[AO_BUFFER_SIZE
];
448 /* divisors of master clock for analog output pacing */
449 unsigned int ao_divisor1
;
450 unsigned int ao_divisor2
;
451 volatile unsigned int ao_count
; /* number of analog output samples remaining */
452 int ao_value
[2]; /* remember what the analog outputs are set to, to allow readback */
453 unsigned int caldac_value
[NUM_CHANNELS_8800
]; /* for readback of caldac */
454 unsigned int trimpot_value
[NUM_CHANNELS_8402
]; /* for readback of trimpot */
455 unsigned int dac08_value
;
456 unsigned int calibration_source
;
460 * most drivers define the following macro to make it easy to
461 * access the private structure.
463 #define devpriv ((struct cb_pcidas_private *)dev->private)
466 * The struct comedi_driver structure tells the Comedi core module
467 * which functions to call to configure/deconfigure (attach/detach)
468 * the board, and also about the kernel module that contains
471 static int cb_pcidas_attach(struct comedi_device
*dev
,
472 struct comedi_devconfig
*it
);
473 static int cb_pcidas_detach(struct comedi_device
*dev
);
474 static struct comedi_driver driver_cb_pcidas
= {
475 .driver_name
= "cb_pcidas",
476 .module
= THIS_MODULE
,
477 .attach
= cb_pcidas_attach
,
478 .detach
= cb_pcidas_detach
,
481 static int cb_pcidas_ai_rinsn(struct comedi_device
*dev
,
482 struct comedi_subdevice
*s
,
483 struct comedi_insn
*insn
, unsigned int *data
);
484 static int ai_config_insn(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
485 struct comedi_insn
*insn
, unsigned int *data
);
486 static int cb_pcidas_ao_nofifo_winsn(struct comedi_device
*dev
,
487 struct comedi_subdevice
*s
,
488 struct comedi_insn
*insn
,
490 static int cb_pcidas_ao_fifo_winsn(struct comedi_device
*dev
,
491 struct comedi_subdevice
*s
,
492 struct comedi_insn
*insn
,
494 static int cb_pcidas_ao_readback_insn(struct comedi_device
*dev
,
495 struct comedi_subdevice
*s
,
496 struct comedi_insn
*insn
,
498 static int cb_pcidas_ai_cmd(struct comedi_device
*dev
,
499 struct comedi_subdevice
*s
);
500 static int cb_pcidas_ai_cmdtest(struct comedi_device
*dev
,
501 struct comedi_subdevice
*s
,
502 struct comedi_cmd
*cmd
);
503 static int cb_pcidas_ao_cmd(struct comedi_device
*dev
,
504 struct comedi_subdevice
*s
);
505 static int cb_pcidas_ao_inttrig(struct comedi_device
*dev
,
506 struct comedi_subdevice
*subdev
,
507 unsigned int trig_num
);
508 static int cb_pcidas_ao_cmdtest(struct comedi_device
*dev
,
509 struct comedi_subdevice
*s
,
510 struct comedi_cmd
*cmd
);
511 static irqreturn_t
cb_pcidas_interrupt(int irq
, void *d
);
512 static void handle_ao_interrupt(struct comedi_device
*dev
, unsigned int status
);
513 static int cb_pcidas_cancel(struct comedi_device
*dev
,
514 struct comedi_subdevice
*s
);
515 static int cb_pcidas_ao_cancel(struct comedi_device
*dev
,
516 struct comedi_subdevice
*s
);
517 static void cb_pcidas_load_counters(struct comedi_device
*dev
, unsigned int *ns
,
519 static int eeprom_read_insn(struct comedi_device
*dev
,
520 struct comedi_subdevice
*s
,
521 struct comedi_insn
*insn
, unsigned int *data
);
522 static int caldac_read_insn(struct comedi_device
*dev
,
523 struct comedi_subdevice
*s
,
524 struct comedi_insn
*insn
, unsigned int *data
);
525 static int caldac_write_insn(struct comedi_device
*dev
,
526 struct comedi_subdevice
*s
,
527 struct comedi_insn
*insn
, unsigned int *data
);
528 static int trimpot_read_insn(struct comedi_device
*dev
,
529 struct comedi_subdevice
*s
,
530 struct comedi_insn
*insn
, unsigned int *data
);
531 static int cb_pcidas_trimpot_write(struct comedi_device
*dev
,
532 unsigned int channel
, unsigned int value
);
533 static int trimpot_write_insn(struct comedi_device
*dev
,
534 struct comedi_subdevice
*s
,
535 struct comedi_insn
*insn
, unsigned int *data
);
536 static int dac08_read_insn(struct comedi_device
*dev
,
537 struct comedi_subdevice
*s
, struct comedi_insn
*insn
,
539 static int dac08_write(struct comedi_device
*dev
, unsigned int value
);
540 static int dac08_write_insn(struct comedi_device
*dev
,
541 struct comedi_subdevice
*s
,
542 struct comedi_insn
*insn
, unsigned int *data
);
543 static int caldac_8800_write(struct comedi_device
*dev
, unsigned int address
,
545 static int trimpot_7376_write(struct comedi_device
*dev
, uint8_t value
);
546 static int trimpot_8402_write(struct comedi_device
*dev
, unsigned int channel
,
548 static int nvram_read(struct comedi_device
*dev
, unsigned int address
,
551 static inline unsigned int cal_enable_bits(struct comedi_device
*dev
)
553 return CAL_EN_BIT
| CAL_SRC_BITS(devpriv
->calibration_source
);
557 * Attach is called by the Comedi core to configure the driver
558 * for a particular board.
560 static int cb_pcidas_attach(struct comedi_device
*dev
,
561 struct comedi_devconfig
*it
)
563 struct comedi_subdevice
*s
;
564 struct pci_dev
*pcidev
= NULL
;
568 printk("comedi%d: cb_pcidas: ", dev
->minor
);
571 * Allocate the private structure area.
573 if (alloc_private(dev
, sizeof(struct cb_pcidas_private
)) < 0)
577 * Probe the device to determine what device in the series it is.
581 for_each_pci_dev(pcidev
) {
582 /* is it not a computer boards card? */
583 if (pcidev
->vendor
!= PCI_VENDOR_ID_CB
)
585 /* loop through cards supported by this driver */
586 for (index
= 0; index
< ARRAY_SIZE(cb_pcidas_boards
); index
++) {
587 if (cb_pcidas_boards
[index
].device_id
!= pcidev
->device
)
589 /* was a particular bus/slot requested? */
590 if (it
->options
[0] || it
->options
[1]) {
591 /* are we on the wrong bus/slot? */
592 if (pcidev
->bus
->number
!= it
->options
[0] ||
593 PCI_SLOT(pcidev
->devfn
) != it
->options
[1]) {
597 devpriv
->pci_dev
= pcidev
;
598 dev
->board_ptr
= cb_pcidas_boards
+ index
;
603 printk("No supported ComputerBoards/MeasurementComputing card found on "
604 "requested position\n");
609 printk("Found %s on bus %i, slot %i\n", cb_pcidas_boards
[index
].name
,
610 pcidev
->bus
->number
, PCI_SLOT(pcidev
->devfn
));
613 * Enable PCI device and reserve I/O ports.
615 if (comedi_pci_enable(pcidev
, "cb_pcidas")) {
616 printk(" Failed to enable PCI device and request regions\n");
620 * Initialize devpriv->control_status and devpriv->adc_fifo to point to
621 * their base address.
623 devpriv
->s5933_config
=
624 pci_resource_start(devpriv
->pci_dev
, S5933_BADRINDEX
);
625 devpriv
->control_status
=
626 pci_resource_start(devpriv
->pci_dev
, CONT_STAT_BADRINDEX
);
628 pci_resource_start(devpriv
->pci_dev
, ADC_FIFO_BADRINDEX
);
629 devpriv
->pacer_counter_dio
=
630 pci_resource_start(devpriv
->pci_dev
, PACER_BADRINDEX
);
631 if (thisboard
->ao_nchan
) {
632 devpriv
->ao_registers
=
633 pci_resource_start(devpriv
->pci_dev
, AO_BADRINDEX
);
635 /* disable and clear interrupts on amcc s5933 */
636 outl(INTCSR_INBOX_INTR_STATUS
,
637 devpriv
->s5933_config
+ AMCC_OP_REG_INTCSR
);
640 if (request_irq(devpriv
->pci_dev
->irq
, cb_pcidas_interrupt
,
641 IRQF_SHARED
, "cb_pcidas", dev
)) {
642 printk(" unable to allocate irq %d\n", devpriv
->pci_dev
->irq
);
645 dev
->irq
= devpriv
->pci_dev
->irq
;
647 /* Initialize dev->board_name */
648 dev
->board_name
= thisboard
->name
;
651 * Allocate the subdevice structures.
653 if (alloc_subdevices(dev
, 7) < 0)
656 s
= dev
->subdevices
+ 0;
657 /* analog input subdevice */
658 dev
->read_subdev
= s
;
659 s
->type
= COMEDI_SUBD_AI
;
660 s
->subdev_flags
= SDF_READABLE
| SDF_GROUND
| SDF_DIFF
| SDF_CMD_READ
;
661 /* WARNING: Number of inputs in differential mode is ignored */
662 s
->n_chan
= thisboard
->ai_se_chans
;
663 s
->len_chanlist
= thisboard
->ai_se_chans
;
664 s
->maxdata
= (1 << thisboard
->ai_bits
) - 1;
665 s
->range_table
= thisboard
->ranges
;
666 s
->insn_read
= cb_pcidas_ai_rinsn
;
667 s
->insn_config
= ai_config_insn
;
668 s
->do_cmd
= cb_pcidas_ai_cmd
;
669 s
->do_cmdtest
= cb_pcidas_ai_cmdtest
;
670 s
->cancel
= cb_pcidas_cancel
;
672 /* analog output subdevice */
673 s
= dev
->subdevices
+ 1;
674 if (thisboard
->ao_nchan
) {
675 s
->type
= COMEDI_SUBD_AO
;
676 s
->subdev_flags
= SDF_READABLE
| SDF_WRITABLE
| SDF_GROUND
;
677 s
->n_chan
= thisboard
->ao_nchan
;
678 /* analog out resolution is the same as analog input resolution, so use ai_bits */
679 s
->maxdata
= (1 << thisboard
->ai_bits
) - 1;
680 s
->range_table
= &cb_pcidas_ao_ranges
;
681 s
->insn_read
= cb_pcidas_ao_readback_insn
;
682 if (thisboard
->has_ao_fifo
) {
683 dev
->write_subdev
= s
;
684 s
->subdev_flags
|= SDF_CMD_WRITE
;
685 s
->insn_write
= cb_pcidas_ao_fifo_winsn
;
686 s
->do_cmdtest
= cb_pcidas_ao_cmdtest
;
687 s
->do_cmd
= cb_pcidas_ao_cmd
;
688 s
->cancel
= cb_pcidas_ao_cancel
;
690 s
->insn_write
= cb_pcidas_ao_nofifo_winsn
;
693 s
->type
= COMEDI_SUBD_UNUSED
;
697 s
= dev
->subdevices
+ 2;
698 subdev_8255_init(dev
, s
, NULL
, devpriv
->pacer_counter_dio
+ DIO_8255
);
701 s
= dev
->subdevices
+ 3;
702 s
->type
= COMEDI_SUBD_MEMORY
;
703 s
->subdev_flags
= SDF_READABLE
| SDF_INTERNAL
;
706 s
->insn_read
= eeprom_read_insn
;
709 s
= dev
->subdevices
+ 4;
710 s
->type
= COMEDI_SUBD_CALIB
;
711 s
->subdev_flags
= SDF_READABLE
| SDF_WRITABLE
| SDF_INTERNAL
;
712 s
->n_chan
= NUM_CHANNELS_8800
;
714 s
->insn_read
= caldac_read_insn
;
715 s
->insn_write
= caldac_write_insn
;
716 for (i
= 0; i
< s
->n_chan
; i
++)
717 caldac_8800_write(dev
, i
, s
->maxdata
/ 2);
719 /* trim potentiometer */
720 s
= dev
->subdevices
+ 5;
721 s
->type
= COMEDI_SUBD_CALIB
;
722 s
->subdev_flags
= SDF_READABLE
| SDF_WRITABLE
| SDF_INTERNAL
;
723 if (thisboard
->trimpot
== AD7376
) {
724 s
->n_chan
= NUM_CHANNELS_7376
;
727 s
->n_chan
= NUM_CHANNELS_8402
;
730 s
->insn_read
= trimpot_read_insn
;
731 s
->insn_write
= trimpot_write_insn
;
732 for (i
= 0; i
< s
->n_chan
; i
++)
733 cb_pcidas_trimpot_write(dev
, i
, s
->maxdata
/ 2);
736 s
= dev
->subdevices
+ 6;
737 if (thisboard
->has_dac08
) {
738 s
->type
= COMEDI_SUBD_CALIB
;
739 s
->subdev_flags
= SDF_READABLE
| SDF_WRITABLE
| SDF_INTERNAL
;
740 s
->n_chan
= NUM_CHANNELS_DAC08
;
741 s
->insn_read
= dac08_read_insn
;
742 s
->insn_write
= dac08_write_insn
;
744 dac08_write(dev
, s
->maxdata
/ 2);
746 s
->type
= COMEDI_SUBD_UNUSED
;
748 /* make sure mailbox 4 is empty */
749 inl(devpriv
->s5933_config
+ AMCC_OP_REG_IMB4
);
750 /* Set bits to enable incoming mailbox interrupts on amcc s5933. */
751 devpriv
->s5933_intcsr_bits
=
752 INTCSR_INBOX_BYTE(3) | INTCSR_INBOX_SELECT(3) |
753 INTCSR_INBOX_FULL_INT
;
754 /* clear and enable interrupt on amcc s5933 */
755 outl(devpriv
->s5933_intcsr_bits
| INTCSR_INBOX_INTR_STATUS
,
756 devpriv
->s5933_config
+ AMCC_OP_REG_INTCSR
);
762 * cb_pcidas_detach is called to deconfigure a device. It should deallocate
764 * This function is also called when _attach() fails, so it should be
765 * careful not to release resources that were not necessarily
766 * allocated by _attach(). dev->private and dev->subdevices are
767 * deallocated automatically by the core.
769 static int cb_pcidas_detach(struct comedi_device
*dev
)
771 printk("comedi%d: cb_pcidas: remove\n", dev
->minor
);
774 if (devpriv
->s5933_config
) {
775 /* disable and clear interrupts on amcc s5933 */
776 outl(INTCSR_INBOX_INTR_STATUS
,
777 devpriv
->s5933_config
+ AMCC_OP_REG_INTCSR
);
778 #ifdef CB_PCIDAS_DEBUG
779 printk("detaching, incsr is 0x%x\n",
780 inl(devpriv
->s5933_config
+ AMCC_OP_REG_INTCSR
));
785 free_irq(dev
->irq
, dev
);
787 subdev_8255_cleanup(dev
, dev
->subdevices
+ 2);
788 if (devpriv
&& devpriv
->pci_dev
) {
789 if (devpriv
->s5933_config
)
790 comedi_pci_disable(devpriv
->pci_dev
);
791 pci_dev_put(devpriv
->pci_dev
);
798 * "instructions" read/write data in "one-shot" or "software-triggered"
801 static int cb_pcidas_ai_rinsn(struct comedi_device
*dev
,
802 struct comedi_subdevice
*s
,
803 struct comedi_insn
*insn
, unsigned int *data
)
807 static const int timeout
= 10000;
809 /* enable calibration input if appropriate */
810 if (insn
->chanspec
& CR_ALT_SOURCE
) {
811 outw(cal_enable_bits(dev
),
812 devpriv
->control_status
+ CALIBRATION_REG
);
815 outw(0, devpriv
->control_status
+ CALIBRATION_REG
);
816 channel
= CR_CHAN(insn
->chanspec
);
818 /* set mux limits and gain */
819 bits
= BEGIN_SCAN(channel
) |
820 END_SCAN(channel
) | GAIN_BITS(CR_RANGE(insn
->chanspec
));
821 /* set unipolar/bipolar */
822 if (CR_RANGE(insn
->chanspec
) & IS_UNIPOLAR
)
824 /* set singleended/differential */
825 if (CR_AREF(insn
->chanspec
) != AREF_DIFF
)
827 outw(bits
, devpriv
->control_status
+ ADCMUX_CONT
);
830 outw(0, devpriv
->adc_fifo
+ ADCFIFOCLR
);
832 /* convert n samples */
833 for (n
= 0; n
< insn
->n
; n
++) {
834 /* trigger conversion */
835 outw(0, devpriv
->adc_fifo
+ ADCDATA
);
837 /* wait for conversion to end */
838 /* return -ETIMEDOUT if there is a timeout */
839 for (i
= 0; i
< timeout
; i
++) {
840 if (inw(devpriv
->control_status
+ ADCMUX_CONT
) & EOC
)
847 data
[n
] = inw(devpriv
->adc_fifo
+ ADCDATA
);
850 /* return the number of samples read/written */
854 static int ai_config_calibration_source(struct comedi_device
*dev
,
857 static const int num_calibration_sources
= 8;
858 unsigned int source
= data
[1];
860 if (source
>= num_calibration_sources
) {
861 printk("invalid calibration source: %i\n", source
);
865 devpriv
->calibration_source
= source
;
870 static int ai_config_insn(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
871 struct comedi_insn
*insn
, unsigned int *data
)
876 case INSN_CONFIG_ALT_SOURCE
:
877 return ai_config_calibration_source(dev
, data
);
886 /* analog output insn for pcidas-1000 and 1200 series */
887 static int cb_pcidas_ao_nofifo_winsn(struct comedi_device
*dev
,
888 struct comedi_subdevice
*s
,
889 struct comedi_insn
*insn
,
895 /* set channel and range */
896 channel
= CR_CHAN(insn
->chanspec
);
897 spin_lock_irqsave(&dev
->spinlock
, flags
);
898 devpriv
->ao_control_bits
&=
899 ~DAC_MODE_UPDATE_BOTH
& ~DAC_RANGE_MASK(channel
);
900 devpriv
->ao_control_bits
|=
901 DACEN
| DAC_RANGE(channel
, CR_RANGE(insn
->chanspec
));
902 outw(devpriv
->ao_control_bits
, devpriv
->control_status
+ DAC_CSR
);
903 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
905 /* remember value for readback */
906 devpriv
->ao_value
[channel
] = data
[0];
908 outw(data
[0], devpriv
->ao_registers
+ DAC_DATA_REG(channel
));
913 /* analog output insn for pcidas-1602 series */
914 static int cb_pcidas_ao_fifo_winsn(struct comedi_device
*dev
,
915 struct comedi_subdevice
*s
,
916 struct comedi_insn
*insn
, unsigned int *data
)
922 outw(0, devpriv
->ao_registers
+ DACFIFOCLR
);
924 /* set channel and range */
925 channel
= CR_CHAN(insn
->chanspec
);
926 spin_lock_irqsave(&dev
->spinlock
, flags
);
927 devpriv
->ao_control_bits
&=
928 ~DAC_CHAN_EN(0) & ~DAC_CHAN_EN(1) & ~DAC_RANGE_MASK(channel
) &
930 devpriv
->ao_control_bits
|=
931 DACEN
| DAC_RANGE(channel
,
933 chanspec
)) | DAC_CHAN_EN(channel
) |
935 outw(devpriv
->ao_control_bits
, devpriv
->control_status
+ DAC_CSR
);
936 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
938 /* remember value for readback */
939 devpriv
->ao_value
[channel
] = data
[0];
941 outw(data
[0], devpriv
->ao_registers
+ DACDATA
);
946 /* analog output readback insn */
947 /* XXX loses track of analog output value back after an analog ouput command is executed */
948 static int cb_pcidas_ao_readback_insn(struct comedi_device
*dev
,
949 struct comedi_subdevice
*s
,
950 struct comedi_insn
*insn
,
953 data
[0] = devpriv
->ao_value
[CR_CHAN(insn
->chanspec
)];
958 static int eeprom_read_insn(struct comedi_device
*dev
,
959 struct comedi_subdevice
*s
,
960 struct comedi_insn
*insn
, unsigned int *data
)
965 retval
= nvram_read(dev
, CR_CHAN(insn
->chanspec
), &nvram_data
);
969 data
[0] = nvram_data
;
974 static int caldac_write_insn(struct comedi_device
*dev
,
975 struct comedi_subdevice
*s
,
976 struct comedi_insn
*insn
, unsigned int *data
)
978 const unsigned int channel
= CR_CHAN(insn
->chanspec
);
980 return caldac_8800_write(dev
, channel
, data
[0]);
983 static int caldac_read_insn(struct comedi_device
*dev
,
984 struct comedi_subdevice
*s
,
985 struct comedi_insn
*insn
, unsigned int *data
)
987 data
[0] = devpriv
->caldac_value
[CR_CHAN(insn
->chanspec
)];
992 /* 1602/16 pregain offset */
993 static int dac08_write(struct comedi_device
*dev
, unsigned int value
)
995 if (devpriv
->dac08_value
== value
)
998 devpriv
->dac08_value
= value
;
1000 outw(cal_enable_bits(dev
) | (value
& 0xff),
1001 devpriv
->control_status
+ CALIBRATION_REG
);
1003 outw(cal_enable_bits(dev
) | SELECT_DAC08_BIT
| (value
& 0xff),
1004 devpriv
->control_status
+ CALIBRATION_REG
);
1006 outw(cal_enable_bits(dev
) | (value
& 0xff),
1007 devpriv
->control_status
+ CALIBRATION_REG
);
1013 static int dac08_write_insn(struct comedi_device
*dev
,
1014 struct comedi_subdevice
*s
,
1015 struct comedi_insn
*insn
, unsigned int *data
)
1017 return dac08_write(dev
, data
[0]);
1020 static int dac08_read_insn(struct comedi_device
*dev
,
1021 struct comedi_subdevice
*s
, struct comedi_insn
*insn
,
1024 data
[0] = devpriv
->dac08_value
;
1029 static int cb_pcidas_trimpot_write(struct comedi_device
*dev
,
1030 unsigned int channel
, unsigned int value
)
1032 if (devpriv
->trimpot_value
[channel
] == value
)
1035 devpriv
->trimpot_value
[channel
] = value
;
1036 switch (thisboard
->trimpot
) {
1038 trimpot_7376_write(dev
, value
);
1041 trimpot_8402_write(dev
, channel
, value
);
1044 comedi_error(dev
, "driver bug?");
1052 static int trimpot_write_insn(struct comedi_device
*dev
,
1053 struct comedi_subdevice
*s
,
1054 struct comedi_insn
*insn
, unsigned int *data
)
1056 unsigned int channel
= CR_CHAN(insn
->chanspec
);
1058 return cb_pcidas_trimpot_write(dev
, channel
, data
[0]);
1061 static int trimpot_read_insn(struct comedi_device
*dev
,
1062 struct comedi_subdevice
*s
,
1063 struct comedi_insn
*insn
, unsigned int *data
)
1065 unsigned int channel
= CR_CHAN(insn
->chanspec
);
1067 data
[0] = devpriv
->trimpot_value
[channel
];
1072 static int cb_pcidas_ai_cmdtest(struct comedi_device
*dev
,
1073 struct comedi_subdevice
*s
,
1074 struct comedi_cmd
*cmd
)
1078 int i
, gain
, start_chan
;
1080 /* cmdtest tests a particular command to see if it is valid.
1081 * Using the cmdtest ioctl, a user can create a valid cmd
1082 * and then have it executes by the cmd ioctl.
1084 * cmdtest returns 1,2,3,4 or 0, depending on which tests
1085 * the command passes. */
1087 /* step 1: make sure trigger sources are trivially valid */
1089 tmp
= cmd
->start_src
;
1090 cmd
->start_src
&= TRIG_NOW
| TRIG_EXT
;
1091 if (!cmd
->start_src
|| tmp
!= cmd
->start_src
)
1094 tmp
= cmd
->scan_begin_src
;
1095 cmd
->scan_begin_src
&= TRIG_FOLLOW
| TRIG_TIMER
| TRIG_EXT
;
1096 if (!cmd
->scan_begin_src
|| tmp
!= cmd
->scan_begin_src
)
1099 tmp
= cmd
->convert_src
;
1100 cmd
->convert_src
&= TRIG_TIMER
| TRIG_NOW
| TRIG_EXT
;
1101 if (!cmd
->convert_src
|| tmp
!= cmd
->convert_src
)
1104 tmp
= cmd
->scan_end_src
;
1105 cmd
->scan_end_src
&= TRIG_COUNT
;
1106 if (!cmd
->scan_end_src
|| tmp
!= cmd
->scan_end_src
)
1109 tmp
= cmd
->stop_src
;
1110 cmd
->stop_src
&= TRIG_COUNT
| TRIG_NONE
;
1111 if (!cmd
->stop_src
|| tmp
!= cmd
->stop_src
)
1117 /* step 2: make sure trigger sources are unique and mutually compatible */
1119 if (cmd
->start_src
!= TRIG_NOW
&& cmd
->start_src
!= TRIG_EXT
)
1121 if (cmd
->scan_begin_src
!= TRIG_FOLLOW
&&
1122 cmd
->scan_begin_src
!= TRIG_TIMER
&&
1123 cmd
->scan_begin_src
!= TRIG_EXT
)
1125 if (cmd
->convert_src
!= TRIG_TIMER
&&
1126 cmd
->convert_src
!= TRIG_EXT
&& cmd
->convert_src
!= TRIG_NOW
)
1128 if (cmd
->stop_src
!= TRIG_COUNT
&& cmd
->stop_src
!= TRIG_NONE
)
1131 /* make sure trigger sources are compatible with each other */
1132 if (cmd
->scan_begin_src
== TRIG_FOLLOW
&& cmd
->convert_src
== TRIG_NOW
)
1134 if (cmd
->scan_begin_src
!= TRIG_FOLLOW
&& cmd
->convert_src
!= TRIG_NOW
)
1136 if (cmd
->start_src
== TRIG_EXT
&&
1137 (cmd
->convert_src
== TRIG_EXT
|| cmd
->scan_begin_src
== TRIG_EXT
))
1143 /* step 3: make sure arguments are trivially compatible */
1145 switch (cmd
->start_src
) {
1147 /* External trigger, only CR_EDGE and CR_INVERT flags allowed */
1149 & (CR_FLAGS_MASK
& ~(CR_EDGE
| CR_INVERT
))) != 0) {
1151 ~(CR_FLAGS_MASK
& ~(CR_EDGE
| CR_INVERT
));
1154 if (!thisboard
->has_ai_trig_invert
&&
1155 (cmd
->start_arg
& CR_INVERT
)) {
1156 cmd
->start_arg
&= (CR_FLAGS_MASK
& ~CR_INVERT
);
1161 if (cmd
->start_arg
!= 0) {
1168 if (cmd
->scan_begin_src
== TRIG_TIMER
) {
1169 if (cmd
->scan_begin_arg
<
1170 thisboard
->ai_speed
* cmd
->chanlist_len
) {
1171 cmd
->scan_begin_arg
=
1172 thisboard
->ai_speed
* cmd
->chanlist_len
;
1176 if (cmd
->convert_src
== TRIG_TIMER
) {
1177 if (cmd
->convert_arg
< thisboard
->ai_speed
) {
1178 cmd
->convert_arg
= thisboard
->ai_speed
;
1183 if (cmd
->scan_end_arg
!= cmd
->chanlist_len
) {
1184 cmd
->scan_end_arg
= cmd
->chanlist_len
;
1187 if (cmd
->stop_src
== TRIG_NONE
) {
1189 if (cmd
->stop_arg
!= 0) {
1198 /* step 4: fix up any arguments */
1200 if (cmd
->scan_begin_src
== TRIG_TIMER
) {
1201 tmp
= cmd
->scan_begin_arg
;
1202 i8253_cascade_ns_to_timer_2div(TIMER_BASE
,
1203 &(devpriv
->divisor1
),
1204 &(devpriv
->divisor2
),
1205 &(cmd
->scan_begin_arg
),
1206 cmd
->flags
& TRIG_ROUND_MASK
);
1207 if (tmp
!= cmd
->scan_begin_arg
)
1210 if (cmd
->convert_src
== TRIG_TIMER
) {
1211 tmp
= cmd
->convert_arg
;
1212 i8253_cascade_ns_to_timer_2div(TIMER_BASE
,
1213 &(devpriv
->divisor1
),
1214 &(devpriv
->divisor2
),
1215 &(cmd
->convert_arg
),
1216 cmd
->flags
& TRIG_ROUND_MASK
);
1217 if (tmp
!= cmd
->convert_arg
)
1224 /* check channel/gain list against card's limitations */
1225 if (cmd
->chanlist
) {
1226 gain
= CR_RANGE(cmd
->chanlist
[0]);
1227 start_chan
= CR_CHAN(cmd
->chanlist
[0]);
1228 for (i
= 1; i
< cmd
->chanlist_len
; i
++) {
1229 if (CR_CHAN(cmd
->chanlist
[i
]) !=
1230 (start_chan
+ i
) % s
->n_chan
) {
1232 "entries in chanlist must be consecutive channels, counting upwards\n");
1235 if (CR_RANGE(cmd
->chanlist
[i
]) != gain
) {
1237 "entries in chanlist must all have the same gain\n");
1249 static int cb_pcidas_ai_cmd(struct comedi_device
*dev
,
1250 struct comedi_subdevice
*s
)
1252 struct comedi_async
*async
= s
->async
;
1253 struct comedi_cmd
*cmd
= &async
->cmd
;
1255 unsigned long flags
;
1257 /* make sure CAL_EN_BIT is disabled */
1258 outw(0, devpriv
->control_status
+ CALIBRATION_REG
);
1259 /* initialize before settings pacer source and count values */
1260 outw(0, devpriv
->control_status
+ TRIG_CONTSTAT
);
1262 outw(0, devpriv
->adc_fifo
+ ADCFIFOCLR
);
1264 /* set mux limits, gain and pacer source */
1265 bits
= BEGIN_SCAN(CR_CHAN(cmd
->chanlist
[0])) |
1266 END_SCAN(CR_CHAN(cmd
->chanlist
[cmd
->chanlist_len
- 1])) |
1267 GAIN_BITS(CR_RANGE(cmd
->chanlist
[0]));
1268 /* set unipolar/bipolar */
1269 if (CR_RANGE(cmd
->chanlist
[0]) & IS_UNIPOLAR
)
1271 /* set singleended/differential */
1272 if (CR_AREF(cmd
->chanlist
[0]) != AREF_DIFF
)
1274 /* set pacer source */
1275 if (cmd
->convert_src
== TRIG_EXT
|| cmd
->scan_begin_src
== TRIG_EXT
)
1276 bits
|= PACER_EXT_RISE
;
1279 outw(bits
, devpriv
->control_status
+ ADCMUX_CONT
);
1281 #ifdef CB_PCIDAS_DEBUG
1282 printk("comedi: sent 0x%x to adcmux control\n", bits
);
1286 if (cmd
->convert_src
== TRIG_TIMER
)
1287 cb_pcidas_load_counters(dev
, &cmd
->convert_arg
,
1288 cmd
->flags
& TRIG_ROUND_MASK
);
1289 else if (cmd
->scan_begin_src
== TRIG_TIMER
)
1290 cb_pcidas_load_counters(dev
, &cmd
->scan_begin_arg
,
1291 cmd
->flags
& TRIG_ROUND_MASK
);
1293 /* set number of conversions */
1294 if (cmd
->stop_src
== TRIG_COUNT
)
1295 devpriv
->count
= cmd
->chanlist_len
* cmd
->stop_arg
;
1296 /* enable interrupts */
1297 spin_lock_irqsave(&dev
->spinlock
, flags
);
1298 devpriv
->adc_fifo_bits
|= INTE
;
1299 devpriv
->adc_fifo_bits
&= ~INT_MASK
;
1300 if (cmd
->flags
& TRIG_WAKE_EOS
) {
1301 if (cmd
->convert_src
== TRIG_NOW
&& cmd
->chanlist_len
> 1)
1302 devpriv
->adc_fifo_bits
|= INT_EOS
; /* interrupt end of burst */
1304 devpriv
->adc_fifo_bits
|= INT_FNE
; /* interrupt fifo not empty */
1306 devpriv
->adc_fifo_bits
|= INT_FHF
; /* interrupt fifo half full */
1308 #ifdef CB_PCIDAS_DEBUG
1309 printk("comedi: adc_fifo_bits are 0x%x\n", devpriv
->adc_fifo_bits
);
1311 /* enable (and clear) interrupts */
1312 outw(devpriv
->adc_fifo_bits
| EOAI
| INT
| LADFUL
,
1313 devpriv
->control_status
+ INT_ADCFIFO
);
1314 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
1316 /* set start trigger and burst mode */
1318 if (cmd
->start_src
== TRIG_NOW
)
1320 else if (cmd
->start_src
== TRIG_EXT
) {
1321 bits
|= EXT_TRIGGER
| TGEN
| XTRCL
;
1322 if (thisboard
->has_ai_trig_invert
1323 && (cmd
->start_arg
& CR_INVERT
))
1325 if (thisboard
->has_ai_trig_gated
&& (cmd
->start_arg
& CR_EDGE
))
1328 comedi_error(dev
, "bug!");
1331 if (cmd
->convert_src
== TRIG_NOW
&& cmd
->chanlist_len
> 1)
1333 outw(bits
, devpriv
->control_status
+ TRIG_CONTSTAT
);
1334 #ifdef CB_PCIDAS_DEBUG
1335 printk("comedi: sent 0x%x to trig control\n", bits
);
1341 static int cb_pcidas_ao_cmdtest(struct comedi_device
*dev
,
1342 struct comedi_subdevice
*s
,
1343 struct comedi_cmd
*cmd
)
1348 /* cmdtest tests a particular command to see if it is valid.
1349 * Using the cmdtest ioctl, a user can create a valid cmd
1350 * and then have it executes by the cmd ioctl.
1352 * cmdtest returns 1,2,3,4 or 0, depending on which tests
1353 * the command passes. */
1355 /* step 1: make sure trigger sources are trivially valid */
1357 tmp
= cmd
->start_src
;
1358 cmd
->start_src
&= TRIG_INT
;
1359 if (!cmd
->start_src
|| tmp
!= cmd
->start_src
)
1362 tmp
= cmd
->scan_begin_src
;
1363 cmd
->scan_begin_src
&= TRIG_TIMER
| TRIG_EXT
;
1364 if (!cmd
->scan_begin_src
|| tmp
!= cmd
->scan_begin_src
)
1367 tmp
= cmd
->convert_src
;
1368 cmd
->convert_src
&= TRIG_NOW
;
1369 if (!cmd
->convert_src
|| tmp
!= cmd
->convert_src
)
1372 tmp
= cmd
->scan_end_src
;
1373 cmd
->scan_end_src
&= TRIG_COUNT
;
1374 if (!cmd
->scan_end_src
|| tmp
!= cmd
->scan_end_src
)
1377 tmp
= cmd
->stop_src
;
1378 cmd
->stop_src
&= TRIG_COUNT
| TRIG_NONE
;
1379 if (!cmd
->stop_src
|| tmp
!= cmd
->stop_src
)
1385 /* step 2: make sure trigger sources are unique and mutually compatible */
1387 if (cmd
->scan_begin_src
!= TRIG_TIMER
&&
1388 cmd
->scan_begin_src
!= TRIG_EXT
)
1390 if (cmd
->stop_src
!= TRIG_COUNT
&& cmd
->stop_src
!= TRIG_NONE
)
1396 /* step 3: make sure arguments are trivially compatible */
1398 if (cmd
->start_arg
!= 0) {
1403 if (cmd
->scan_begin_src
== TRIG_TIMER
) {
1404 if (cmd
->scan_begin_arg
< thisboard
->ao_scan_speed
) {
1405 cmd
->scan_begin_arg
= thisboard
->ao_scan_speed
;
1410 if (cmd
->scan_end_arg
!= cmd
->chanlist_len
) {
1411 cmd
->scan_end_arg
= cmd
->chanlist_len
;
1414 if (cmd
->stop_src
== TRIG_NONE
) {
1416 if (cmd
->stop_arg
!= 0) {
1425 /* step 4: fix up any arguments */
1427 if (cmd
->scan_begin_src
== TRIG_TIMER
) {
1428 tmp
= cmd
->scan_begin_arg
;
1429 i8253_cascade_ns_to_timer_2div(TIMER_BASE
,
1430 &(devpriv
->ao_divisor1
),
1431 &(devpriv
->ao_divisor2
),
1432 &(cmd
->scan_begin_arg
),
1433 cmd
->flags
& TRIG_ROUND_MASK
);
1434 if (tmp
!= cmd
->scan_begin_arg
)
1441 /* check channel/gain list against card's limitations */
1442 if (cmd
->chanlist
&& cmd
->chanlist_len
> 1) {
1443 if (CR_CHAN(cmd
->chanlist
[0]) != 0 ||
1444 CR_CHAN(cmd
->chanlist
[1]) != 1) {
1446 "channels must be ordered channel 0, channel 1 in chanlist\n");
1457 static int cb_pcidas_ao_cmd(struct comedi_device
*dev
,
1458 struct comedi_subdevice
*s
)
1460 struct comedi_async
*async
= s
->async
;
1461 struct comedi_cmd
*cmd
= &async
->cmd
;
1463 unsigned long flags
;
1465 /* set channel limits, gain */
1466 spin_lock_irqsave(&dev
->spinlock
, flags
);
1467 for (i
= 0; i
< cmd
->chanlist_len
; i
++) {
1468 /* enable channel */
1469 devpriv
->ao_control_bits
|=
1470 DAC_CHAN_EN(CR_CHAN(cmd
->chanlist
[i
]));
1472 devpriv
->ao_control_bits
|= DAC_RANGE(CR_CHAN(cmd
->chanlist
[i
]),
1477 /* disable analog out before settings pacer source and count values */
1478 outw(devpriv
->ao_control_bits
, devpriv
->control_status
+ DAC_CSR
);
1479 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
1482 outw(0, devpriv
->ao_registers
+ DACFIFOCLR
);
1485 if (cmd
->scan_begin_src
== TRIG_TIMER
) {
1486 i8253_cascade_ns_to_timer_2div(TIMER_BASE
,
1487 &(devpriv
->ao_divisor1
),
1488 &(devpriv
->ao_divisor2
),
1489 &(cmd
->scan_begin_arg
),
1492 /* Write the values of ctr1 and ctr2 into counters 1 and 2 */
1493 i8254_load(devpriv
->pacer_counter_dio
+ DAC8254
, 0, 1,
1494 devpriv
->ao_divisor1
, 2);
1495 i8254_load(devpriv
->pacer_counter_dio
+ DAC8254
, 0, 2,
1496 devpriv
->ao_divisor2
, 2);
1498 /* set number of conversions */
1499 if (cmd
->stop_src
== TRIG_COUNT
)
1500 devpriv
->ao_count
= cmd
->chanlist_len
* cmd
->stop_arg
;
1501 /* set pacer source */
1502 spin_lock_irqsave(&dev
->spinlock
, flags
);
1503 switch (cmd
->scan_begin_src
) {
1505 devpriv
->ao_control_bits
|= DAC_PACER_INT
;
1508 devpriv
->ao_control_bits
|= DAC_PACER_EXT_RISE
;
1511 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
1512 comedi_error(dev
, "error setting dac pacer source");
1516 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
1518 async
->inttrig
= cb_pcidas_ao_inttrig
;
1523 static int cb_pcidas_ao_inttrig(struct comedi_device
*dev
,
1524 struct comedi_subdevice
*s
,
1525 unsigned int trig_num
)
1527 unsigned int num_bytes
, num_points
= thisboard
->fifo_size
;
1528 struct comedi_async
*async
= s
->async
;
1529 struct comedi_cmd
*cmd
= &s
->async
->cmd
;
1530 unsigned long flags
;
1536 if (cmd
->stop_src
== TRIG_COUNT
&& devpriv
->ao_count
< num_points
)
1537 num_points
= devpriv
->ao_count
;
1539 num_bytes
= cfc_read_array_from_buffer(s
, devpriv
->ao_buffer
,
1540 num_points
* sizeof(short));
1541 num_points
= num_bytes
/ sizeof(short);
1543 if (cmd
->stop_src
== TRIG_COUNT
)
1544 devpriv
->ao_count
-= num_points
;
1545 /* write data to board's fifo */
1546 outsw(devpriv
->ao_registers
+ DACDATA
, devpriv
->ao_buffer
, num_bytes
);
1548 /* enable dac half-full and empty interrupts */
1549 spin_lock_irqsave(&dev
->spinlock
, flags
);
1550 devpriv
->adc_fifo_bits
|= DAEMIE
| DAHFIE
;
1551 #ifdef CB_PCIDAS_DEBUG
1552 printk("comedi: adc_fifo_bits are 0x%x\n", devpriv
->adc_fifo_bits
);
1554 /* enable and clear interrupts */
1555 outw(devpriv
->adc_fifo_bits
| DAEMI
| DAHFI
,
1556 devpriv
->control_status
+ INT_ADCFIFO
);
1559 devpriv
->ao_control_bits
|= DAC_START
| DACEN
| DAC_EMPTY
;
1560 outw(devpriv
->ao_control_bits
, devpriv
->control_status
+ DAC_CSR
);
1561 #ifdef CB_PCIDAS_DEBUG
1562 printk("comedi: sent 0x%x to dac control\n", devpriv
->ao_control_bits
);
1564 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
1566 async
->inttrig
= NULL
;
1571 static irqreturn_t
cb_pcidas_interrupt(int irq
, void *d
)
1573 struct comedi_device
*dev
= (struct comedi_device
*)d
;
1574 struct comedi_subdevice
*s
= dev
->read_subdev
;
1575 struct comedi_async
*async
;
1576 int status
, s5933_status
;
1577 int half_fifo
= thisboard
->fifo_size
/ 2;
1578 unsigned int num_samples
, i
;
1579 static const int timeout
= 10000;
1580 unsigned long flags
;
1582 if (dev
->attached
== 0)
1588 s5933_status
= inl(devpriv
->s5933_config
+ AMCC_OP_REG_INTCSR
);
1589 #ifdef CB_PCIDAS_DEBUG
1590 printk("intcsr 0x%x\n", s5933_status
);
1591 printk("mbef 0x%x\n", inl(devpriv
->s5933_config
+ AMCC_OP_REG_MBEF
));
1594 if ((INTCSR_INTR_ASSERTED
& s5933_status
) == 0)
1597 /* make sure mailbox 4 is empty */
1598 inl_p(devpriv
->s5933_config
+ AMCC_OP_REG_IMB4
);
1599 /* clear interrupt on amcc s5933 */
1600 outl(devpriv
->s5933_intcsr_bits
| INTCSR_INBOX_INTR_STATUS
,
1601 devpriv
->s5933_config
+ AMCC_OP_REG_INTCSR
);
1603 status
= inw(devpriv
->control_status
+ INT_ADCFIFO
);
1604 #ifdef CB_PCIDAS_DEBUG
1605 if ((status
& (INT
| EOAI
| LADFUL
| DAHFI
| DAEMI
)) == 0)
1606 comedi_error(dev
, "spurious interrupt");
1609 /* check for analog output interrupt */
1610 if (status
& (DAHFI
| DAEMI
))
1611 handle_ao_interrupt(dev
, status
);
1612 /* check for analog input interrupts */
1613 /* if fifo half-full */
1614 if (status
& ADHFI
) {
1616 num_samples
= half_fifo
;
1617 if (async
->cmd
.stop_src
== TRIG_COUNT
&&
1618 num_samples
> devpriv
->count
) {
1619 num_samples
= devpriv
->count
;
1621 insw(devpriv
->adc_fifo
+ ADCDATA
, devpriv
->ai_buffer
,
1623 cfc_write_array_to_buffer(s
, devpriv
->ai_buffer
,
1624 num_samples
* sizeof(short));
1625 devpriv
->count
-= num_samples
;
1626 if (async
->cmd
.stop_src
== TRIG_COUNT
&& devpriv
->count
== 0) {
1627 async
->events
|= COMEDI_CB_EOA
;
1628 cb_pcidas_cancel(dev
, s
);
1630 /* clear half-full interrupt latch */
1631 spin_lock_irqsave(&dev
->spinlock
, flags
);
1632 outw(devpriv
->adc_fifo_bits
| INT
,
1633 devpriv
->control_status
+ INT_ADCFIFO
);
1634 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
1635 /* else if fifo not empty */
1636 } else if (status
& (ADNEI
| EOBI
)) {
1637 for (i
= 0; i
< timeout
; i
++) {
1638 /* break if fifo is empty */
1639 if ((ADNE
& inw(devpriv
->control_status
+
1642 cfc_write_to_buffer(s
, inw(devpriv
->adc_fifo
));
1643 if (async
->cmd
.stop_src
== TRIG_COUNT
&& --devpriv
->count
== 0) { /* end of acquisition */
1644 cb_pcidas_cancel(dev
, s
);
1645 async
->events
|= COMEDI_CB_EOA
;
1649 /* clear not-empty interrupt latch */
1650 spin_lock_irqsave(&dev
->spinlock
, flags
);
1651 outw(devpriv
->adc_fifo_bits
| INT
,
1652 devpriv
->control_status
+ INT_ADCFIFO
);
1653 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
1654 } else if (status
& EOAI
) {
1656 "bug! encountered end of acquisition interrupt?");
1657 /* clear EOA interrupt latch */
1658 spin_lock_irqsave(&dev
->spinlock
, flags
);
1659 outw(devpriv
->adc_fifo_bits
| EOAI
,
1660 devpriv
->control_status
+ INT_ADCFIFO
);
1661 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
1663 /* check for fifo overflow */
1664 if (status
& LADFUL
) {
1665 comedi_error(dev
, "fifo overflow");
1666 /* clear overflow interrupt latch */
1667 spin_lock_irqsave(&dev
->spinlock
, flags
);
1668 outw(devpriv
->adc_fifo_bits
| LADFUL
,
1669 devpriv
->control_status
+ INT_ADCFIFO
);
1670 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
1671 cb_pcidas_cancel(dev
, s
);
1672 async
->events
|= COMEDI_CB_EOA
| COMEDI_CB_ERROR
;
1675 comedi_event(dev
, s
);
1680 static void handle_ao_interrupt(struct comedi_device
*dev
, unsigned int status
)
1682 struct comedi_subdevice
*s
= dev
->write_subdev
;
1683 struct comedi_async
*async
= s
->async
;
1684 struct comedi_cmd
*cmd
= &async
->cmd
;
1685 unsigned int half_fifo
= thisboard
->fifo_size
/ 2;
1686 unsigned int num_points
;
1687 unsigned long flags
;
1691 if (status
& DAEMI
) {
1692 /* clear dac empty interrupt latch */
1693 spin_lock_irqsave(&dev
->spinlock
, flags
);
1694 outw(devpriv
->adc_fifo_bits
| DAEMI
,
1695 devpriv
->control_status
+ INT_ADCFIFO
);
1696 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
1697 if (inw(devpriv
->ao_registers
+ DAC_CSR
) & DAC_EMPTY
) {
1698 if (cmd
->stop_src
== TRIG_NONE
||
1699 (cmd
->stop_src
== TRIG_COUNT
1700 && devpriv
->ao_count
)) {
1701 comedi_error(dev
, "dac fifo underflow");
1702 cb_pcidas_ao_cancel(dev
, s
);
1703 async
->events
|= COMEDI_CB_ERROR
;
1705 async
->events
|= COMEDI_CB_EOA
;
1707 } else if (status
& DAHFI
) {
1708 unsigned int num_bytes
;
1710 /* figure out how many points we are writing to fifo */
1711 num_points
= half_fifo
;
1712 if (cmd
->stop_src
== TRIG_COUNT
&&
1713 devpriv
->ao_count
< num_points
)
1714 num_points
= devpriv
->ao_count
;
1716 cfc_read_array_from_buffer(s
, devpriv
->ao_buffer
,
1717 num_points
* sizeof(short));
1718 num_points
= num_bytes
/ sizeof(short);
1720 if (async
->cmd
.stop_src
== TRIG_COUNT
)
1721 devpriv
->ao_count
-= num_points
;
1722 /* write data to board's fifo */
1723 outsw(devpriv
->ao_registers
+ DACDATA
, devpriv
->ao_buffer
,
1725 /* clear half-full interrupt latch */
1726 spin_lock_irqsave(&dev
->spinlock
, flags
);
1727 outw(devpriv
->adc_fifo_bits
| DAHFI
,
1728 devpriv
->control_status
+ INT_ADCFIFO
);
1729 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
1732 comedi_event(dev
, s
);
1735 /* cancel analog input command */
1736 static int cb_pcidas_cancel(struct comedi_device
*dev
,
1737 struct comedi_subdevice
*s
)
1739 unsigned long flags
;
1741 spin_lock_irqsave(&dev
->spinlock
, flags
);
1742 /* disable interrupts */
1743 devpriv
->adc_fifo_bits
&= ~INTE
& ~EOAIE
;
1744 outw(devpriv
->adc_fifo_bits
, devpriv
->control_status
+ INT_ADCFIFO
);
1745 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
1747 /* disable start trigger source and burst mode */
1748 outw(0, devpriv
->control_status
+ TRIG_CONTSTAT
);
1749 /* software pacer source */
1750 outw(0, devpriv
->control_status
+ ADCMUX_CONT
);
1755 /* cancel analog output command */
1756 static int cb_pcidas_ao_cancel(struct comedi_device
*dev
,
1757 struct comedi_subdevice
*s
)
1759 unsigned long flags
;
1761 spin_lock_irqsave(&dev
->spinlock
, flags
);
1762 /* disable interrupts */
1763 devpriv
->adc_fifo_bits
&= ~DAHFIE
& ~DAEMIE
;
1764 outw(devpriv
->adc_fifo_bits
, devpriv
->control_status
+ INT_ADCFIFO
);
1766 /* disable output */
1767 devpriv
->ao_control_bits
&= ~DACEN
& ~DAC_PACER_MASK
;
1768 outw(devpriv
->ao_control_bits
, devpriv
->control_status
+ DAC_CSR
);
1769 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
1774 static void cb_pcidas_load_counters(struct comedi_device
*dev
, unsigned int *ns
,
1777 i8253_cascade_ns_to_timer_2div(TIMER_BASE
, &(devpriv
->divisor1
),
1778 &(devpriv
->divisor2
), ns
,
1779 rounding_flags
& TRIG_ROUND_MASK
);
1781 /* Write the values of ctr1 and ctr2 into counters 1 and 2 */
1782 i8254_load(devpriv
->pacer_counter_dio
+ ADC8254
, 0, 1,
1783 devpriv
->divisor1
, 2);
1784 i8254_load(devpriv
->pacer_counter_dio
+ ADC8254
, 0, 2,
1785 devpriv
->divisor2
, 2);
1788 static void write_calibration_bitstream(struct comedi_device
*dev
,
1789 unsigned int register_bits
,
1790 unsigned int bitstream
,
1791 unsigned int bitstream_length
)
1793 static const int write_delay
= 1;
1796 for (bit
= 1 << (bitstream_length
- 1); bit
; bit
>>= 1) {
1797 if (bitstream
& bit
)
1798 register_bits
|= SERIAL_DATA_IN_BIT
;
1800 register_bits
&= ~SERIAL_DATA_IN_BIT
;
1801 udelay(write_delay
);
1802 outw(register_bits
, devpriv
->control_status
+ CALIBRATION_REG
);
1806 static int caldac_8800_write(struct comedi_device
*dev
, unsigned int address
,
1809 static const int num_caldac_channels
= 8;
1810 static const int bitstream_length
= 11;
1811 unsigned int bitstream
= ((address
& 0x7) << 8) | value
;
1812 static const int caldac_8800_udelay
= 1;
1814 if (address
>= num_caldac_channels
) {
1815 comedi_error(dev
, "illegal caldac channel");
1819 if (value
== devpriv
->caldac_value
[address
])
1822 devpriv
->caldac_value
[address
] = value
;
1824 write_calibration_bitstream(dev
, cal_enable_bits(dev
), bitstream
,
1827 udelay(caldac_8800_udelay
);
1828 outw(cal_enable_bits(dev
) | SELECT_8800_BIT
,
1829 devpriv
->control_status
+ CALIBRATION_REG
);
1830 udelay(caldac_8800_udelay
);
1831 outw(cal_enable_bits(dev
), devpriv
->control_status
+ CALIBRATION_REG
);
1836 static int trimpot_7376_write(struct comedi_device
*dev
, uint8_t value
)
1838 static const int bitstream_length
= 7;
1839 unsigned int bitstream
= value
& 0x7f;
1840 unsigned int register_bits
;
1841 static const int ad7376_udelay
= 1;
1843 register_bits
= cal_enable_bits(dev
) | SELECT_TRIMPOT_BIT
;
1844 udelay(ad7376_udelay
);
1845 outw(register_bits
, devpriv
->control_status
+ CALIBRATION_REG
);
1847 write_calibration_bitstream(dev
, register_bits
, bitstream
,
1850 udelay(ad7376_udelay
);
1851 outw(cal_enable_bits(dev
), devpriv
->control_status
+ CALIBRATION_REG
);
1858 * ch 1 : adc postgain offset */
1859 static int trimpot_8402_write(struct comedi_device
*dev
, unsigned int channel
,
1862 static const int bitstream_length
= 10;
1863 unsigned int bitstream
= ((channel
& 0x3) << 8) | (value
& 0xff);
1864 unsigned int register_bits
;
1865 static const int ad8402_udelay
= 1;
1867 register_bits
= cal_enable_bits(dev
) | SELECT_TRIMPOT_BIT
;
1868 udelay(ad8402_udelay
);
1869 outw(register_bits
, devpriv
->control_status
+ CALIBRATION_REG
);
1871 write_calibration_bitstream(dev
, register_bits
, bitstream
,
1874 udelay(ad8402_udelay
);
1875 outw(cal_enable_bits(dev
), devpriv
->control_status
+ CALIBRATION_REG
);
1880 static int wait_for_nvram_ready(unsigned long s5933_base_addr
)
1882 static const int timeout
= 1000;
1885 for (i
= 0; i
< timeout
; i
++) {
1886 if ((inb(s5933_base_addr
+
1887 AMCC_OP_REG_MCSR_NVCMD
) & MCSR_NV_BUSY
)
1895 static int nvram_read(struct comedi_device
*dev
, unsigned int address
,
1898 unsigned long iobase
= devpriv
->s5933_config
;
1900 if (wait_for_nvram_ready(iobase
) < 0)
1903 outb(MCSR_NV_ENABLE
| MCSR_NV_LOAD_LOW_ADDR
,
1904 iobase
+ AMCC_OP_REG_MCSR_NVCMD
);
1905 outb(address
& 0xff, iobase
+ AMCC_OP_REG_MCSR_NVDATA
);
1906 outb(MCSR_NV_ENABLE
| MCSR_NV_LOAD_HIGH_ADDR
,
1907 iobase
+ AMCC_OP_REG_MCSR_NVCMD
);
1908 outb((address
>> 8) & 0xff, iobase
+ AMCC_OP_REG_MCSR_NVDATA
);
1909 outb(MCSR_NV_ENABLE
| MCSR_NV_READ
, iobase
+ AMCC_OP_REG_MCSR_NVCMD
);
1911 if (wait_for_nvram_ready(iobase
) < 0)
1914 *data
= inb(iobase
+ AMCC_OP_REG_MCSR_NVDATA
);
1920 * A convenient macro that defines init_module() and cleanup_module(),
1923 static int __devinit
driver_cb_pcidas_pci_probe(struct pci_dev
*dev
,
1924 const struct pci_device_id
*ent
)
1926 return comedi_pci_auto_config(dev
, driver_cb_pcidas
.driver_name
);
1929 static void __devexit
driver_cb_pcidas_pci_remove(struct pci_dev
*dev
)
1931 comedi_pci_auto_unconfig(dev
);
1934 static struct pci_driver driver_cb_pcidas_pci_driver
= {
1935 .id_table
= cb_pcidas_pci_table
,
1936 .probe
= &driver_cb_pcidas_pci_probe
,
1937 .remove
= __devexit_p(&driver_cb_pcidas_pci_remove
)
1940 static int __init
driver_cb_pcidas_init_module(void)
1944 retval
= comedi_driver_register(&driver_cb_pcidas
);
1948 driver_cb_pcidas_pci_driver
.name
= (char *)driver_cb_pcidas
.driver_name
;
1949 return pci_register_driver(&driver_cb_pcidas_pci_driver
);
1952 static void __exit
driver_cb_pcidas_cleanup_module(void)
1954 pci_unregister_driver(&driver_cb_pcidas_pci_driver
);
1955 comedi_driver_unregister(&driver_cb_pcidas
);
1958 module_init(driver_cb_pcidas_init_module
);
1959 module_exit(driver_cb_pcidas_cleanup_module
);
1961 MODULE_AUTHOR("Comedi http://www.comedi.org");
1962 MODULE_DESCRIPTION("Comedi low-level driver");
1963 MODULE_LICENSE("GPL");