59 #include <linux/sched.h>
61 #include "../comedidev.h"
68 #define DPRINTK(format, args...) pr_debug(format, ## args)
70 #define DPRINTK(format, args...) do { } while (0)
73 #define PCI_DIO_SIZE 4096
74 #define PCI_MITE_SIZE 4096
78 #define Window_Address 4
79 #define Interrupt_And_Window_Status 4
80 #define IntStatus1 (1<<0)
81 #define IntStatus2 (1<<1)
82 #define WindowAddressStatus_mask 0x7c
84 #define Master_DMA_And_Interrupt_Control 5
85 #define InterruptLine(x) ((x)&3)
86 #define OpenInt (1<<2)
87 #define Group_Status 5
88 #define DataLeft (1<<0)
90 #define StopTrig (1<<3)
92 #define Group_1_Flags 6
93 #define Group_2_Flags 7
94 #define TransferReady (1<<0)
95 #define CountExpired (1<<1)
97 #define PrimaryTC (1<<6)
98 #define SecondaryTC (1<<7)
103 #define Group_1_First_Clear 6
104 #define Group_2_First_Clear 7
105 #define ClearWaited (1<<3)
106 #define ClearPrimaryTC (1<<4)
107 #define ClearSecondaryTC (1<<5)
108 #define DMAReset (1<<6)
109 #define FIFOReset (1<<7)
110 #define ClearAll 0xf8
112 #define Group_1_FIFO 8
113 #define Group_2_FIFO 12
115 #define Transfer_Count 20
119 #define Chip_Version 27
120 #define Port_IO(x) (28+(x))
121 #define Port_Pin_Directions(x) (32+(x))
122 #define Port_Pin_Mask(x) (36+(x))
123 #define Port_Pin_Polarities(x) (40+(x))
125 #define Master_Clock_Routing 45
126 #define RTSIClocking(x) (((x)&3)<<4)
128 #define Group_1_Second_Clear 46
129 #define Group_2_Second_Clear 47
130 #define ClearExpired (1<<0)
132 #define Port_Pattern(x) (48+(x))
135 #define FIFOEnableA (1<<0)
136 #define FIFOEnableB (1<<1)
137 #define FIFOEnableC (1<<2)
138 #define FIFOEnableD (1<<3)
139 #define Funneling(x) (((x)&3)<<4)
140 #define GroupDirection (1<<7)
142 #define Protocol_Register_1 65
143 #define OpMode Protocol_Register_1
144 #define RunMode(x) ((x)&7)
145 #define Numbered (1<<3)
147 #define Protocol_Register_2 66
148 #define ClockReg Protocol_Register_2
149 #define ClockLine(x) (((x)&3)<<5)
150 #define InvertStopTrig (1<<7)
151 #define DataLatching(x) (((x)&3)<<5)
153 #define Protocol_Register_3 67
154 #define Sequence Protocol_Register_3
156 #define Protocol_Register_14 68
157 #define ClockSpeed Protocol_Register_14
159 #define Protocol_Register_4 70
160 #define ReqReg Protocol_Register_4
161 #define ReqConditioning(x) (((x)&7)<<3)
163 #define Protocol_Register_5 71
164 #define BlockMode Protocol_Register_5
166 #define FIFO_Control 72
167 #define ReadyLevel(x) ((x)&7)
169 #define Protocol_Register_6 73
170 #define LinePolarities Protocol_Register_6
171 #define InvertAck (1<<0)
172 #define InvertReq (1<<1)
173 #define InvertClock (1<<2)
174 #define InvertSerial (1<<3)
175 #define OpenAck (1<<4)
176 #define OpenClock (1<<5)
178 #define Protocol_Register_7 74
179 #define AckSer Protocol_Register_7
180 #define AckLine(x) (((x)&3)<<2)
181 #define ExchangePins (1<<7)
183 #define Interrupt_Control 75
186 #define DMA_Line_Control_Group1 76
187 #define DMA_Line_Control_Group2 108
189 static inline unsigned primary_DMAChannel_bits(
unsigned channel)
191 return channel & 0x3;
194 static inline unsigned secondary_DMAChannel_bits(
unsigned channel)
196 return (channel << 2) & 0xc;
199 #define Transfer_Size_Control 77
200 #define TransferWidth(x) ((x)&3)
201 #define TransferLength(x) (((x)&3)<<3)
202 #define RequireRLevel (1<<5)
204 #define Protocol_Register_15 79
205 #define DAQOptions Protocol_Register_15
206 #define StartSource(x) ((x)&0x3)
207 #define InvertStart (1<<2)
208 #define StopSource(x) (((x)&0x3)<<3)
209 #define ReqStart (1<<6)
210 #define PreStart (1<<7)
212 #define Pattern_Detection 81
213 #define DetectionMethod (1<<0)
214 #define InvertMatch (1<<1)
215 #define IE_Pattern_Detection (1<<2)
217 #define Protocol_Register_9 82
218 #define ReqDelay Protocol_Register_9
220 #define Protocol_Register_10 83
221 #define ReqNotDelay Protocol_Register_10
223 #define Protocol_Register_11 84
224 #define AckDelay Protocol_Register_11
226 #define Protocol_Register_12 85
227 #define AckNotDelay Protocol_Register_12
229 #define Protocol_Register_13 86
230 #define Data1Delay Protocol_Register_13
232 #define Protocol_Register_8 88
233 #define StartDelay Protocol_Register_8
236 #define FW_PCI_6534_MAIN "ni6534a.bin"
237 #define FW_PCI_6534_SCARAB_DI "niscrb01.bin"
238 #define FW_PCI_6534_SCARAB_DO "niscrb02.bin"
270 #define TIMER_BASE 50
273 #define IntEn (CountExpired|Waited|PrimaryTC|SecondaryTC)
275 #define IntEn (TransferReady|CountExpired|Waited|PrimaryTC|SecondaryTC)
290 .name =
"pci-dio-32hs",
301 #define n_nidio_boards ARRAY_SIZE(nidio_boards)
302 #define this_board ((const struct nidio_board *)dev->board_ptr)
313 #define devpriv ((struct nidio96_private *)dev->private)
321 static int ni_pcidio_ns_to_timer(
int *nanosec,
int round_mode);
329 #define ni_pcidio_print_flags(x)
330 #define ni_pcidio_print_status(x)
343 spin_unlock_irqrestore(&
devpriv->mite_channel_lock, flags);
344 comedi_error(dev,
"failed to reserve mite dma channel.");
348 writeb(primary_DMAChannel_bits(
devpriv->di_mite_chan->channel) |
349 secondary_DMAChannel_bits(
devpriv->di_mite_chan->channel),
352 spin_unlock_irqrestore(&
devpriv->mite_channel_lock, flags);
363 mite_dma_reset(
devpriv->di_mite_chan);
366 writeb(primary_DMAChannel_bits(0) |
367 secondary_DMAChannel_bits(0),
371 spin_unlock_irqrestore(&
devpriv->mite_channel_lock, flags);
380 ni_pcidio_cancel(dev, s);
387 unsigned long irq_flags;
391 spin_lock(&
devpriv->mite_channel_lock);
394 spin_unlock(&
devpriv->mite_channel_lock);
395 count = s->
async->buf_write_count - s->
async->buf_read_count;
396 spin_unlock_irqrestore(&dev->
spinlock, irq_flags);
408 long int AuxData = 0;
414 unsigned int m_status = 0;
429 DPRINTK(
"ni_pcidio_interrupt: status=0x%02x,flags=0x%02x\n",
434 spin_lock(&
devpriv->mite_channel_lock);
438 mite_print_chsr(m_status);
446 MITE_CHOR(
devpriv->di_mite_chan->channel));
452 DPRINTK(
"unknown mite interrupt, disabling IRQ\n");
457 spin_unlock(&
devpriv->mite_channel_lock);
462 DPRINTK(
"too much work in interrupt\n");
473 while (flags & TransferReady) {
476 DPRINTK(
"too much work in interrupt\n");
486 data1 = AuxData & 0xffff;
487 data2 = (AuxData & 0xffff0000) >> 16;
512 }
else if (flags &
Waited) {
534 DPRINTK(
"ni_pcidio: unknown interrupt\n");
551 ni_pcidio_event(dev, s);
565 static const char *bit_set_string(
unsigned int bits,
unsigned int bit,
566 const char *
const strings[])
568 return (bits & (1
U << bit)) ? strings[
bit] :
"";
571 static const char *
const flags_strings[] = {
572 " TransferReady",
" CountExpired",
" 2",
" 3",
573 " 4",
" Waited",
" PrimaryTC",
" SecondaryTC",
579 pr_debug(
"group_1_flags:%s%s%s%s%s%s%s%s\n",
580 bit_set_string(flags, 7, flags_strings),
581 bit_set_string(flags, 6, flags_strings),
582 bit_set_string(flags, 5, flags_strings),
583 bit_set_string(flags, 4, flags_strings),
584 bit_set_string(flags, 3, flags_strings),
585 bit_set_string(flags, 2, flags_strings),
586 bit_set_string(flags, 1, flags_strings),
587 bit_set_string(flags, 0, flags_strings));
590 static const char *
const status_strings[] = {
591 " DataLeft1",
" Reserved1",
" Req1",
" StopTrig1",
592 " DataLeft2",
" Reserved2",
" Req2",
" StopTrig2",
597 pr_debug(
"group_status:%s%s%s%s%s%s%s%s\n",
598 bit_set_string(flags, 7, status_strings),
599 bit_set_string(flags, 6, status_strings),
600 bit_set_string(flags, 5, status_strings),
601 bit_set_string(flags, 4, status_strings),
602 bit_set_string(flags, 3, status_strings),
603 bit_set_string(flags, 2, status_strings),
604 bit_set_string(flags, 1, status_strings),
605 bit_set_string(flags, 0, status_strings));
621 DPRINTK(
"status 0x%02x flags 0x%02x time %06d\n", a, b,
633 DPRINTK(
"new status 0x%02x\n", b);
672 s->
state &= ~data[0];
673 s->
state |= (data[0] & data[1]);
701 err |= cfc_check_trigger_is_unique(cmd->
start_src);
703 err |= cfc_check_trigger_is_unique(cmd->
stop_src);
717 #define MAX_SPEED (TIMER_BASE)
771 static int ni_pcidio_ns_to_timer(
int *nanosec,
int round_mode)
777 switch (round_mode) {
780 divider = (*nanosec + base / 2) / base;
783 divider = (*nanosec) / base;
786 divider = (*nanosec + base - 1) / base;
790 *nanosec = base * divider;
874 int retval = setup_mite_dma(dev, s);
904 s->
async->inttrig = ni_pcidio_inttrig;
907 DPRINTK(
"ni_pcidio: command started\n");
916 retval = ni_pcidio_request_di_mite_channel(dev);
929 spin_unlock_irqrestore(&
devpriv->mite_channel_lock, flags);
951 ni_pcidio_release_di_mite_channel(dev);
970 static int pci_6534_load_fpga(
struct comedi_device *dev,
int fpga_index,
973 static const int timeout = 1000;
988 "ni_pcidio: failed to load fpga %i, waiting for status 0x2\n",
996 0x3 && i < timeout; ++
i) {
1001 "ni_pcidio: failed to load fpga %i, waiting for status 0x3\n",
1006 unsigned int value = data[j++];
1007 value |= data[j++] << 8;
1013 && i < timeout; ++
i) {
1018 "ni_pcidio: failed to load word into fpga %i\n",
1029 static int pci_6534_reset_fpga(
struct comedi_device *dev,
int fpga_index)
1031 return pci_6534_load_fpga(dev, fpga_index,
NULL, 0);
1039 for (i = 0; i < 3; ++
i) {
1040 ret = pci_6534_reset_fpga(dev, i);
1048 static void pci_6534_init_main_fpga(
struct comedi_device *dev)
1058 static int pci_6534_upload_firmware(
struct comedi_device *dev)
1062 static const char *
const fw_file[3] = {
1069 ret = pci_6534_reset_fpgas(dev);
1073 for (n = 2; n >= 0; n--) {
1077 ret = pci_6534_load_fpga(dev, n, fw->
data, fw->
size);
1078 if (ret == 0 && n == 2)
1079 pci_6534_init_main_fpga(dev);
1094 for (n = 0; n <
ARRAY_SIZE(nidio_boards); n++) {
1096 if (board->
dev_id == dev_id)
1114 dev->
board_ptr = nidio_find_boardinfo(pcidev);
1126 comedi_set_hw_dev(dev, &
devpriv->mite->pcidev->dev);
1132 irq = mite_irq(
devpriv->mite);
1134 ret = pci_6534_upload_firmware(dev);
1158 s->
do_cmd = &ni_pcidio_cmd;
1160 s->
cancel = &ni_pcidio_cancel;
1164 s->
poll = &ni_pcidio_poll;
1202 .driver_name =
"ni_pcidio",
1204 .attach_pci = nidio_attach_pci,
1205 .detach = nidio_detach,
1227 static struct pci_driver ni_pcidio_pci_driver = {
1228 .name =
"ni_pcidio",
1229 .id_table = ni_pcidio_pci_table,
1230 .probe = ni_pcidio_pci_probe,