110 #include "../comedidev.h"
118 #define DAQBOARD2000_FIRMWARE "daqboard2000_firmware.bin"
120 #define PCI_VENDOR_ID_IOTECH 0x1616
122 #define DAQBOARD2000_SUBSYSTEM_IDS2 0x0002
123 #define DAQBOARD2000_SUBSYSTEM_IDS4 0x0004
126 #define DAQBOARD2000_SECRProgPinHi 0x8001767e
127 #define DAQBOARD2000_SECRProgPinLo 0x8000767e
128 #define DAQBOARD2000_SECRLocalBusHi 0xc000767e
129 #define DAQBOARD2000_SECRLocalBusLo 0x8000767e
130 #define DAQBOARD2000_SECRReloadHi 0xa000767e
131 #define DAQBOARD2000_SECRReloadLo 0x8000767e
134 #define DAQBOARD2000_EEPROM_PRESENT 0x10000000
137 #define DAQBOARD2000_CPLD_INIT 0x0002
138 #define DAQBOARD2000_CPLD_DONE 0x0004
161 #define acqControl 0x00
162 #define acqScanListFIFO 0x02
163 #define acqPacerClockDivLow 0x04
164 #define acqScanCounter 0x08
165 #define acqPacerClockDivHigh 0x0a
166 #define acqTriggerCount 0x0c
167 #define acqResultsFIFO 0x10
168 #define acqResultsShadow 0x14
169 #define acqAdcResult 0x18
170 #define dacScanCounter 0x1c
171 #define dacControl 0x20
173 #define dacPacerClockDiv 0x2a
175 #define dioControl 0x30
176 #define dioP3hsioData 0x32
177 #define dioP3Control 0x34
178 #define calEepromControl 0x36
179 #define dacSetting(x) (0x38 + (x)*2)
180 #define dioP2ExpansionIO8Bit 0x40
181 #define ctrTmrControl 0x80
182 #define ctrInput(x) (0x88 + (x)*2)
183 #define timerDivisor(x) (0xa0 + (x)*2)
184 #define dmaControl 0xb0
185 #define trigControl 0xb2
186 #define calEeprom 0xb8
187 #define acqDigitalMark 0xba
188 #define trigDacs 0xbc
189 #define dioP2ExpansionIO16Bit(x) (0xc0 + (x)*2)
192 #define DAQBOARD2000_SeqStartScanList 0x0011
193 #define DAQBOARD2000_SeqStopScanList 0x0010
196 #define DAQBOARD2000_AcqResetScanListFifo 0x0004
197 #define DAQBOARD2000_AcqResetResultsFifo 0x0002
198 #define DAQBOARD2000_AcqResetConfigPipe 0x0001
201 #define DAQBOARD2000_AcqResultsFIFOMore1Sample 0x0001
202 #define DAQBOARD2000_AcqResultsFIFOHasValidData 0x0002
203 #define DAQBOARD2000_AcqResultsFIFOOverrun 0x0004
204 #define DAQBOARD2000_AcqLogicScanning 0x0008
205 #define DAQBOARD2000_AcqConfigPipeFull 0x0010
206 #define DAQBOARD2000_AcqScanListFIFOEmpty 0x0020
207 #define DAQBOARD2000_AcqAdcNotReady 0x0040
208 #define DAQBOARD2000_ArbitrationFailure 0x0080
209 #define DAQBOARD2000_AcqPacerOverrun 0x0100
210 #define DAQBOARD2000_DacPacerOverrun 0x0200
211 #define DAQBOARD2000_AcqHardwareError 0x01c0
214 #define DAQBOARD2000_SeqStartScanList 0x0011
215 #define DAQBOARD2000_SeqStopScanList 0x0010
218 #define DAQBOARD2000_AdcPacerInternal 0x0030
219 #define DAQBOARD2000_AdcPacerExternal 0x0032
220 #define DAQBOARD2000_AdcPacerEnable 0x0031
221 #define DAQBOARD2000_AdcPacerEnableDacPacer 0x0034
222 #define DAQBOARD2000_AdcPacerDisable 0x0030
223 #define DAQBOARD2000_AdcPacerNormalMode 0x0060
224 #define DAQBOARD2000_AdcPacerCompatibilityMode 0x0061
225 #define DAQBOARD2000_AdcPacerInternalOutEnable 0x0008
226 #define DAQBOARD2000_AdcPacerExternalRising 0x0100
229 #define DAQBOARD2000_DacFull 0x0001
230 #define DAQBOARD2000_RefBusy 0x0002
231 #define DAQBOARD2000_TrgBusy 0x0004
232 #define DAQBOARD2000_CalBusy 0x0008
233 #define DAQBOARD2000_Dac0Busy 0x0010
234 #define DAQBOARD2000_Dac1Busy 0x0020
235 #define DAQBOARD2000_Dac2Busy 0x0040
236 #define DAQBOARD2000_Dac3Busy 0x0080
239 #define DAQBOARD2000_Dac0Enable 0x0021
240 #define DAQBOARD2000_Dac1Enable 0x0031
241 #define DAQBOARD2000_Dac2Enable 0x0041
242 #define DAQBOARD2000_Dac3Enable 0x0051
243 #define DAQBOARD2000_DacEnableBit 0x0001
244 #define DAQBOARD2000_Dac0Disable 0x0020
245 #define DAQBOARD2000_Dac1Disable 0x0030
246 #define DAQBOARD2000_Dac2Disable 0x0040
247 #define DAQBOARD2000_Dac3Disable 0x0050
248 #define DAQBOARD2000_DacResetFifo 0x0004
249 #define DAQBOARD2000_DacPatternDisable 0x0060
250 #define DAQBOARD2000_DacPatternEnable 0x0061
251 #define DAQBOARD2000_DacSelectSignedData 0x0002
252 #define DAQBOARD2000_DacSelectUnsignedData 0x0000
255 #define DAQBOARD2000_TrigAnalog 0x0000
256 #define DAQBOARD2000_TrigTTL 0x0010
257 #define DAQBOARD2000_TrigTransHiLo 0x0004
258 #define DAQBOARD2000_TrigTransLoHi 0x0000
259 #define DAQBOARD2000_TrigAbove 0x0000
260 #define DAQBOARD2000_TrigBelow 0x0004
261 #define DAQBOARD2000_TrigLevelSense 0x0002
262 #define DAQBOARD2000_TrigEdgeSense 0x0000
263 #define DAQBOARD2000_TrigEnable 0x0001
264 #define DAQBOARD2000_TrigDisable 0x0000
267 #define DAQBOARD2000_PosRefDacSelect 0x0100
268 #define DAQBOARD2000_NegRefDacSelect 0x0000
300 u16 word0, word1, word2, word3;
305 word2 = (chan << 6) & 0x00c0;
336 writeAcqScanListEntry(dev, word0);
337 writeAcqScanListEntry(dev, word1);
338 writeAcqScanListEntry(dev, word2);
339 writeAcqScanListEntry(dev, word3);
342 static int daqboard2000_ai_insn_read(
struct comedi_device *dev,
371 for (i = 0; i < insn->
n; i++) {
372 setup_sampling(dev, chan, gain);
376 for (timeout = 0; timeout < 20; timeout++) {
383 for (timeout = 0; timeout < 20; timeout++) {
389 for (timeout = 0; timeout < 20; timeout++) {
403 static int daqboard2000_ao_insn_read(
struct comedi_device *dev,
412 for (i = 0; i < insn->
n; i++)
418 static int daqboard2000_ao_insn_write(
struct comedi_device *dev,
429 for (i = 0; i < insn->
n; i++) {
435 writew((chan + 2) * 0x0010 | 0x0001,
440 for (timeout = 0; timeout < 20; timeout++) {
442 if ((val & ((chan + 1) * 0x0010)) == 0)
452 writew((chan + 2) * 0x0010 | 0x0000,
461 static void daqboard2000_resetLocalBus(
struct comedi_device *dev)
471 static void daqboard2000_reloadPLX(
struct comedi_device *dev)
483 static void daqboard2000_pulseProgPin(
struct comedi_device *dev)
501 for (i = 0; i < 50; i++) {
502 cpld =
readw(devpriv->
daq + 0x1000);
503 if ((cpld & mask) == mask) {
513 static int daqboard2000_writeCPLD(
struct comedi_device *dev,
int data)
521 DAQBOARD2000_CPLD_INIT) {
527 static int initialize_daqboard2000(
struct comedi_device *dev,
528 const u8 *cpld_array,
size_t len)
542 for (retry = 0; retry < 3; retry++) {
543 daqboard2000_resetLocalBus(dev);
544 daqboard2000_reloadPLX(dev);
545 daqboard2000_pulseProgPin(dev);
547 for (i = 0; i < len; i++) {
548 if (cpld_array[i] == 0xff &&
549 cpld_array[i + 1] == 0x20)
552 for (; i < len; i += 2) {
554 (cpld_array[
i] << 8) + cpld_array[i + 1];
555 if (!daqboard2000_writeCPLD(dev, data))
559 daqboard2000_resetLocalBus(dev);
560 daqboard2000_reloadPLX(dev);
569 static int daqboard2000_upload_firmware(
struct comedi_device *dev)
579 ret = initialize_daqboard2000(dev, fw->
data, fw->
size);
585 static void daqboard2000_adcStopDmaTransfer(
struct comedi_device *dev)
589 static void daqboard2000_adcDisarm(
struct comedi_device *dev)
610 daqboard2000_adcStopDmaTransfer(dev);
613 static void daqboard2000_activateReferenceDacs(
struct comedi_device *dev)
621 for (timeout = 0; timeout < 20; timeout++) {
630 for (timeout = 0; timeout < 20; timeout++) {
638 static void daqboard2000_initializeCtrs(
struct comedi_device *dev)
642 static void daqboard2000_initializeTmrs(
struct comedi_device *dev)
646 static void daqboard2000_dacDisarm(
struct comedi_device *dev)
650 static void daqboard2000_initializeAdc(
struct comedi_device *dev)
652 daqboard2000_adcDisarm(dev);
653 daqboard2000_activateReferenceDacs(dev);
654 daqboard2000_initializeCtrs(dev);
655 daqboard2000_initializeTmrs(dev);
658 static void daqboard2000_initializeDac(
struct comedi_device *dev)
660 daqboard2000_dacDisarm(dev);
663 static int daqboard2000_8255_cb(
int dir,
int port,
int data,
664 unsigned long ioaddr)
669 writew(data, mmio_base + port * 2);
672 return readw(mmio_base + port * 2);
676 static const void *daqboard2000_find_boardinfo(
struct comedi_device *dev,
685 for (i = 0; i <
ARRAY_SIZE(boardtypes); i++) {
686 board = &boardtypes[
i];
693 static int daqboard2000_attach_pci(
struct comedi_device *dev,
701 comedi_set_hw_dev(dev, &pcidev->
dev);
703 board = daqboard2000_find_boardinfo(dev, pcidev);
709 result = alloc_private(dev,
sizeof(*devpriv));
723 if (!devpriv->
plx || !devpriv->
daq)
732 result = daqboard2000_upload_firmware(dev);
736 daqboard2000_initializeAdc(dev);
737 daqboard2000_initializeDac(dev);
745 s->
insn_read = daqboard2000_ai_insn_read;
754 s->
insn_read = daqboard2000_ao_insn_read;
772 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
793 .driver_name =
"daqboard2000",
795 .attach_pci = daqboard2000_attach_pci,
796 .detach = daqboard2000_detach,
816 static struct pci_driver daqboard2000_pci_driver = {
817 .name =
"daqboard2000",
818 .id_table = daqboard2000_pci_table,
819 .probe = daqboard2000_pci_probe,