2 * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
7 * Tel: +19(0)7223/9493-0
8 * Fax: +49(0)7223/9493-92
9 * http://www.addi-data.com
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the Free
14 * Software Foundation; either version 2 of the License, or (at your option)
18 #include <linux/sched.h>
19 #include <linux/interrupt.h>
21 #define LOBYTE(W) (unsigned char)((W) & 0xFF)
22 #define HIBYTE(W) (unsigned char)(((W) >> 8) & 0xFF)
23 #define MAKEWORD(H, L) (unsigned short)((L) | ((H) << 8))
24 #define LOWORD(W) (unsigned short)((W) & 0xFFFF)
25 #define HIWORD(W) (unsigned short)(((W) >> 16) & 0xFFFF)
26 #define MAKEDWORD(H, L) (unsigned int)((L) | ((H) << 16))
29 #define ADDI_DISABLE 0
30 #define APCI1710_SAVE_INTERRUPT 1
32 #define ADDIDATA_EEPROM 1
33 #define ADDIDATA_NO_EEPROM 0
34 #define ADDIDATA_93C76 "93C76"
35 #define ADDIDATA_S5920 "S5920"
36 #define ADDIDATA_S5933 "S5933"
37 #define ADDIDATA_9054 "9054"
39 /* ADDIDATA Enable Disable */
40 #define ADDIDATA_ENABLE 1
41 #define ADDIDATA_DISABLE 0
45 /* structure for the boardtype */
47 const char *pc_DriverName; /* driver name */
48 int i_VendorId; /* PCI vendor a device ID of card */
52 int i_IorangeBase2; /* base 2 range */
53 int i_IorangeBase3; /* base 3 range */
54 int i_PCIEeprom; /* eeprom present or not */
55 char *pc_EepromChip; /* type of chip */
56 int i_NbrAiChannel; /* num of A/D chans */
57 int i_NbrAiChannelDiff; /* num of A/D chans in diff mode */
58 int i_AiChannelList; /* len of chanlist */
59 int i_NbrAoChannel; /* num of D/A chans */
60 int i_AiMaxdata; /* resolution of A/D */
61 int i_AoMaxdata; /* resolution of D/A */
62 const struct comedi_lrange *pr_AiRangelist; /* rangelist for A/D */
63 const struct comedi_lrange *pr_AoRangelist; /* rangelist for D/A */
65 int i_NbrDiChannel; /* Number of DI channels */
66 int i_NbrDoChannel; /* Number of DO channels */
67 int i_DoMaxdata; /* data to set all channels high */
69 int i_NbrTTLChannel; /* Number of TTL channels */
71 int i_Dma; /* dma present or not */
72 int i_Timer; /* timer subdevice present or not */
73 unsigned char b_AvailableConvertUnit;
74 unsigned int ui_MinAcquisitiontimeNs; /* Minimum Acquisition in Nano secs */
75 unsigned int ui_MinDelaytimeNs; /* Minimum Delay in Nano secs */
77 /* interrupt and reset */
78 void (*interrupt)(int irq, void *d);
79 int (*reset)(struct comedi_device *);
81 /* Subdevice functions */
84 int (*ai_config)(struct comedi_device *, struct comedi_subdevice *,
85 struct comedi_insn *, unsigned int *);
86 int (*ai_read)(struct comedi_device *, struct comedi_subdevice *,
87 struct comedi_insn *, unsigned int *);
88 int (*ai_write)(struct comedi_device *, struct comedi_subdevice *,
89 struct comedi_insn *, unsigned int *);
90 int (*ai_bits)(struct comedi_device *, struct comedi_subdevice *,
91 struct comedi_insn *, unsigned int *);
92 int (*ai_cmdtest)(struct comedi_device *, struct comedi_subdevice *,
94 int (*ai_cmd)(struct comedi_device *, struct comedi_subdevice *);
95 int (*ai_cancel)(struct comedi_device *, struct comedi_subdevice *);
98 int (*ao_config)(struct comedi_device *, struct comedi_subdevice *,
99 struct comedi_insn *, unsigned int *);
100 int (*ao_write)(struct comedi_device *, struct comedi_subdevice *,
101 struct comedi_insn *, unsigned int *);
102 int (*ao_bits)(struct comedi_device *, struct comedi_subdevice *,
103 struct comedi_insn *, unsigned int *);
106 int (*di_config)(struct comedi_device *, struct comedi_subdevice *,
107 struct comedi_insn *, unsigned int *);
108 int (*di_read)(struct comedi_device *, struct comedi_subdevice *,
109 struct comedi_insn *, unsigned int *);
110 int (*di_write)(struct comedi_device *, struct comedi_subdevice *,
111 struct comedi_insn *, unsigned int *);
112 int (*di_bits)(struct comedi_device *, struct comedi_subdevice *,
113 struct comedi_insn *, unsigned int *);
116 int (*do_config)(struct comedi_device *, struct comedi_subdevice *,
117 struct comedi_insn *, unsigned int *);
118 int (*do_write)(struct comedi_device *, struct comedi_subdevice *,
119 struct comedi_insn *, unsigned int *);
120 int (*do_bits)(struct comedi_device *, struct comedi_subdevice *,
121 struct comedi_insn *, unsigned int *);
122 int (*do_read)(struct comedi_device *, struct comedi_subdevice *,
123 struct comedi_insn *, unsigned int *);
126 int (*timer_config)(struct comedi_device *, struct comedi_subdevice *,
127 struct comedi_insn *, unsigned int *);
128 int (*timer_write)(struct comedi_device *, struct comedi_subdevice *,
129 struct comedi_insn *, unsigned int *);
130 int (*timer_read)(struct comedi_device *, struct comedi_subdevice *,
131 struct comedi_insn *, unsigned int *);
132 int (*timer_bits)(struct comedi_device *, struct comedi_subdevice *,
133 struct comedi_insn *, unsigned int *);
136 int (*ttl_config)(struct comedi_device *, struct comedi_subdevice *,
137 struct comedi_insn *, unsigned int *);
138 int (*ttl_bits)(struct comedi_device *, struct comedi_subdevice *,
139 struct comedi_insn *, unsigned int *);
140 int (*ttl_read)(struct comedi_device *, struct comedi_subdevice *,
141 struct comedi_insn *, unsigned int *);
142 int (*ttl_write)(struct comedi_device *, struct comedi_subdevice *,
143 struct comedi_insn *, unsigned int *);
146 /* MODULE INFO STRUCTURE */
148 union str_ModuleInfo {
149 /* Incremental counter infos */
153 unsigned char b_ModeRegister1;
154 unsigned char b_ModeRegister2;
155 unsigned char b_ModeRegister3;
156 unsigned char b_ModeRegister4;
157 } s_ByteModeRegister;
158 unsigned int dw_ModeRegister1_2_3_4;
162 unsigned int b_IndexInit:1;
163 unsigned int b_CounterInit:1;
164 unsigned int b_ReferenceInit:1;
165 unsigned int b_IndexInterruptOccur:1;
166 unsigned int b_CompareLogicInit:1;
167 unsigned int b_FrequencyMeasurementInit:1;
168 unsigned int b_FrequencyMeasurementEnable:1;
171 } s_SiemensCounterInfo;
175 unsigned char b_SSIProfile;
176 unsigned char b_PositionTurnLength;
177 unsigned char b_TurnCptLength;
178 unsigned char b_SSIInit;
183 unsigned char b_TTLInit;
184 unsigned char b_PortConfiguration[4];
187 /* Digital I/O infos */
189 unsigned char b_DigitalInit;
190 unsigned char b_ChannelAMode;
191 unsigned char b_ChannelBMode;
192 unsigned char b_OutputMemoryEnabled;
193 unsigned int dw_OutputMemory;
196 /*********************/
197 /* 82X54 timer infos */
198 /*********************/
202 unsigned char b_82X54Init;
203 unsigned char b_InputClockSelection;
204 unsigned char b_InputClockLevel;
205 unsigned char b_OutputLevel;
206 unsigned char b_HardwareGateLevel;
207 unsigned int dw_ConfigurationWord;
208 } s_82X54TimerInfo[3];
209 unsigned char b_InterruptMask;
212 /*********************/
213 /* Chronometer infos */
214 /*********************/
217 unsigned char b_ChronoInit;
218 unsigned char b_InterruptMask;
219 unsigned char b_PCIInputClock;
220 unsigned char b_TimingUnit;
221 unsigned char b_CycleMode;
222 double d_TimingInterval;
223 unsigned int dw_ConfigReg;
224 } s_ChronoModuleInfo;
226 /***********************/
227 /* Pulse encoder infos */
228 /***********************/
232 unsigned char b_PulseEncoderInit;
233 } s_PulseEncoderInfo[4];
234 unsigned int dw_SetRegister;
235 unsigned int dw_ControlRegister;
236 unsigned int dw_StatusRegister;
237 } s_PulseEncoderModuleInfo;
239 /* Tor conter infos */
242 unsigned char b_TorCounterInit;
243 unsigned char b_TimingUnit;
244 unsigned char b_InterruptEnable;
245 double d_TimingInterval;
246 unsigned int ul_RealTimingInterval;
247 } s_TorCounterInfo[2];
248 unsigned char b_PCIInputClock;
249 } s_TorCounterModuleInfo;
254 unsigned char b_PWMInit;
255 unsigned char b_TimingUnit;
256 unsigned char b_InterruptEnable;
259 unsigned int ul_RealLowTiming;
260 unsigned int ul_RealHighTiming;
262 unsigned char b_ClockSelection;
268 unsigned char b_ETMEnable;
269 unsigned char b_ETMInterrupt;
271 unsigned char b_ETMInit;
272 unsigned char b_TimingUnit;
273 unsigned char b_ClockSelection;
274 double d_TimingInterval;
275 unsigned int ul_Timing;
280 unsigned char b_CDAEnable;
281 unsigned char b_CDAInterrupt;
282 unsigned char b_CDAInit;
283 unsigned char b_FctSelection;
284 unsigned char b_CDAReadFIFOOverflow;
289 /* Private structure for the addi_apci3120 driver */
290 struct addi_private {
293 int i_IobaseAmcc; /* base+size for AMCC chip */
294 int i_IobaseAddon; /* addon base address */
295 int i_IobaseReserved;
296 void __iomem *dw_AiBase;
297 unsigned char b_AiContinuous; /* we do unlimited AI */
298 unsigned char b_AiInitialisation;
299 unsigned int ui_AiActualScan; /* how many scans we finished */
300 unsigned int ui_AiBufferPtr; /* data buffer ptr in samples */
301 unsigned int ui_AiNbrofChannels; /* how many channels is measured */
302 unsigned int ui_AiScanLength; /* Length of actual scanlist */
303 unsigned int ui_AiActualScanPosition; /* position in actual scan */
304 unsigned int *pui_AiChannelList; /* actual chanlist */
305 unsigned int ui_AiChannelList[32]; /* actual chanlist */
306 unsigned char b_AiChannelConfiguration[32]; /* actual chanlist */
307 unsigned int ui_AiReadData[32];
308 unsigned int dw_AiInitialised;
309 unsigned int ui_AiTimer0; /* Timer Constant for Timer0 */
310 unsigned int ui_AiTimer1; /* Timer constant for Timer1 */
311 unsigned int ui_AiFlags;
312 unsigned int ui_AiDataLength;
313 short *AiData; /* Pointer to sample data */
314 unsigned int ui_AiNbrofScans; /* number of scans to do */
315 unsigned short us_UseDma; /* To use Dma or not */
316 unsigned char b_DmaDoubleBuffer; /* we can use double buffering */
317 unsigned int ui_DmaActualBuffer; /* which buffer is used now */
318 /* UPDATE-0.7.57->0.7.68 */
319 /* unsigned int ul_DmaBufferVirtual[2]; pointers to begin of DMA buffer */
320 short *ul_DmaBufferVirtual[2]; /* pointers to begin of DMA buffer */
321 unsigned int ul_DmaBufferHw[2]; /* hw address of DMA buff */
322 unsigned int ui_DmaBufferSize[2]; /* size of dma buffer in bytes */
323 unsigned int ui_DmaBufferUsesize[2]; /* which size we may now used for transfer */
324 unsigned int ui_DmaBufferSamples[2]; /* size in samples */
325 unsigned int ui_DmaBufferPages[2]; /* number of pages in buffer */
326 unsigned char b_DigitalOutputRegister; /* Digital Output Register */
327 unsigned char b_OutputMemoryStatus;
328 unsigned char b_AnalogInputChannelNbr; /* Analog input channel Nbr */
329 unsigned char b_AnalogOutputChannelNbr; /* Analog input Output Nbr */
330 unsigned char b_TimerSelectMode; /* Contain data written at iobase + 0C */
331 unsigned char b_ModeSelectRegister; /* Contain data written at iobase + 0E */
332 unsigned short us_OutputRegister; /* Contain data written at iobase + 0 */
333 unsigned char b_InterruptState;
334 unsigned char b_TimerInit; /* Specify if InitTimerWatchdog was load */
335 unsigned char b_TimerStarted; /* Specify if timer 2 is running or not */
336 unsigned char b_Timer2Mode; /* Specify the timer 2 mode */
337 unsigned char b_Timer2Interrupt; /* Timer2 interrupt enable or disable */
338 unsigned char b_AiCyclicAcquisition; /* indicate cyclic acquisition */
339 unsigned char b_InterruptMode; /* eoc eos or dma */
340 unsigned char b_EocEosInterrupt; /* Enable disable eoc eos interrupt */
341 unsigned int ui_EocEosConversionTime;
342 unsigned char b_EocEosConversionTimeBase;
343 unsigned char b_SingelDiff;
344 unsigned char b_ExttrigEnable; /* To enable or disable external trigger */
346 /* Pointer to the current process */
347 struct task_struct *tsk_Current;
349 /* Hardware board infos for 1710 */
351 unsigned int ui_Address; /* Board address */
352 unsigned int ui_FlashAddress;
353 unsigned char b_InterruptNbr; /* Board interrupt number */
354 unsigned char b_SlotNumber; /* PCI slot number */
355 unsigned char b_BoardVersion;
356 unsigned int dw_MolduleConfiguration[4]; /* Module config */
359 /* Interrupt infos */
361 unsigned int ul_InterruptOccur; /* 0 : No interrupt occur */
362 /* > 0 : Interrupt occur */
363 unsigned int ui_Read; /* Read FIFO */
364 unsigned int ui_Write; /* Write FIFO */
366 unsigned char b_OldModuleMask;
367 unsigned int ul_OldInterruptMask; /* Interrupt mask */
368 unsigned int ul_OldCounterLatchValue; /* Interrupt counter value */
369 } s_FIFOInterruptParameters[APCI1710_SAVE_INTERRUPT];
370 } s_InterruptParameters;
372 union str_ModuleInfo s_ModuleInfo[4];
373 unsigned int ul_TTLPortConfiguration[10];
375 /* Parameters read from EEPROM overriding static board info */
377 int i_NbrAiChannel; /* num of A/D chans */
378 int i_NbrAoChannel; /* num of D/A chans */
379 int i_AiMaxdata; /* resolution of A/D */
380 int i_AoMaxdata; /* resolution of D/A */
381 int i_NbrDiChannel; /* Number of DI channels */
382 int i_NbrDoChannel; /* Number of DO channels */
383 int i_DoMaxdata; /* data to set all channels high */
384 int i_Dma; /* dma present or not */
385 int i_Timer; /* timer subdevice present or not */
386 unsigned int ui_MinAcquisitiontimeNs;
387 /* Minimum Acquisition in Nano secs */
388 unsigned int ui_MinDelaytimeNs;
389 /* Minimum Delay in Nano secs */