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 */
49 int i_PCIEeprom; /* eeprom present or not */
50 char *pc_EepromChip; /* type of chip */
51 int i_NbrAiChannel; /* num of A/D chans */
52 int i_NbrAiChannelDiff; /* num of A/D chans in diff mode */
53 int i_AiChannelList; /* len of chanlist */
54 int i_NbrAoChannel; /* num of D/A chans */
55 int i_AiMaxdata; /* resolution of A/D */
56 int i_AoMaxdata; /* resolution of D/A */
57 const struct comedi_lrange *pr_AiRangelist; /* rangelist for A/D */
58 const struct comedi_lrange *pr_AoRangelist; /* rangelist for D/A */
60 int i_NbrDiChannel; /* Number of DI channels */
61 int i_NbrDoChannel; /* Number of DO channels */
62 int i_DoMaxdata; /* data to set all channels high */
64 int i_NbrTTLChannel; /* Number of TTL channels */
66 int i_Dma; /* dma present or not */
67 int i_Timer; /* timer subdevice present or not */
68 unsigned char b_AvailableConvertUnit;
69 unsigned int ui_MinAcquisitiontimeNs; /* Minimum Acquisition in Nano secs */
70 unsigned int ui_MinDelaytimeNs; /* Minimum Delay in Nano secs */
72 /* interrupt and reset */
73 void (*interrupt)(int irq, void *d);
74 int (*reset)(struct comedi_device *);
76 /* Subdevice functions */
79 int (*ai_config)(struct comedi_device *, struct comedi_subdevice *,
80 struct comedi_insn *, unsigned int *);
81 int (*ai_read)(struct comedi_device *, struct comedi_subdevice *,
82 struct comedi_insn *, unsigned int *);
83 int (*ai_write)(struct comedi_device *, struct comedi_subdevice *,
84 struct comedi_insn *, unsigned int *);
85 int (*ai_bits)(struct comedi_device *, struct comedi_subdevice *,
86 struct comedi_insn *, unsigned int *);
87 int (*ai_cmdtest)(struct comedi_device *, struct comedi_subdevice *,
89 int (*ai_cmd)(struct comedi_device *, struct comedi_subdevice *);
90 int (*ai_cancel)(struct comedi_device *, struct comedi_subdevice *);
93 int (*ao_config)(struct comedi_device *, struct comedi_subdevice *,
94 struct comedi_insn *, unsigned int *);
95 int (*ao_write)(struct comedi_device *, struct comedi_subdevice *,
96 struct comedi_insn *, unsigned int *);
97 int (*ao_bits)(struct comedi_device *, struct comedi_subdevice *,
98 struct comedi_insn *, unsigned int *);
101 int (*di_config)(struct comedi_device *, struct comedi_subdevice *,
102 struct comedi_insn *, unsigned int *);
103 int (*di_read)(struct comedi_device *, struct comedi_subdevice *,
104 struct comedi_insn *, unsigned int *);
105 int (*di_write)(struct comedi_device *, struct comedi_subdevice *,
106 struct comedi_insn *, unsigned int *);
107 int (*di_bits)(struct comedi_device *, struct comedi_subdevice *,
108 struct comedi_insn *, unsigned int *);
111 int (*do_config)(struct comedi_device *, struct comedi_subdevice *,
112 struct comedi_insn *, unsigned int *);
113 int (*do_write)(struct comedi_device *, struct comedi_subdevice *,
114 struct comedi_insn *, unsigned int *);
115 int (*do_bits)(struct comedi_device *, struct comedi_subdevice *,
116 struct comedi_insn *, unsigned int *);
117 int (*do_read)(struct comedi_device *, struct comedi_subdevice *,
118 struct comedi_insn *, unsigned int *);
121 int (*timer_config)(struct comedi_device *, struct comedi_subdevice *,
122 struct comedi_insn *, unsigned int *);
123 int (*timer_write)(struct comedi_device *, struct comedi_subdevice *,
124 struct comedi_insn *, unsigned int *);
125 int (*timer_read)(struct comedi_device *, struct comedi_subdevice *,
126 struct comedi_insn *, unsigned int *);
127 int (*timer_bits)(struct comedi_device *, struct comedi_subdevice *,
128 struct comedi_insn *, unsigned int *);
131 int (*ttl_config)(struct comedi_device *, struct comedi_subdevice *,
132 struct comedi_insn *, unsigned int *);
133 int (*ttl_bits)(struct comedi_device *, struct comedi_subdevice *,
134 struct comedi_insn *, unsigned int *);
135 int (*ttl_read)(struct comedi_device *, struct comedi_subdevice *,
136 struct comedi_insn *, unsigned int *);
137 int (*ttl_write)(struct comedi_device *, struct comedi_subdevice *,
138 struct comedi_insn *, unsigned int *);
141 /* MODULE INFO STRUCTURE */
143 union str_ModuleInfo {
144 /* Incremental counter infos */
148 unsigned char b_ModeRegister1;
149 unsigned char b_ModeRegister2;
150 unsigned char b_ModeRegister3;
151 unsigned char b_ModeRegister4;
152 } s_ByteModeRegister;
153 unsigned int dw_ModeRegister1_2_3_4;
157 unsigned int b_IndexInit:1;
158 unsigned int b_CounterInit:1;
159 unsigned int b_ReferenceInit:1;
160 unsigned int b_IndexInterruptOccur:1;
161 unsigned int b_CompareLogicInit:1;
162 unsigned int b_FrequencyMeasurementInit:1;
163 unsigned int b_FrequencyMeasurementEnable:1;
166 } s_SiemensCounterInfo;
170 unsigned char b_SSIProfile;
171 unsigned char b_PositionTurnLength;
172 unsigned char b_TurnCptLength;
173 unsigned char b_SSIInit;
178 unsigned char b_TTLInit;
179 unsigned char b_PortConfiguration[4];
182 /* Digital I/O infos */
184 unsigned char b_DigitalInit;
185 unsigned char b_ChannelAMode;
186 unsigned char b_ChannelBMode;
187 unsigned char b_OutputMemoryEnabled;
188 unsigned int dw_OutputMemory;
191 /*********************/
192 /* 82X54 timer infos */
193 /*********************/
197 unsigned char b_82X54Init;
198 unsigned char b_InputClockSelection;
199 unsigned char b_InputClockLevel;
200 unsigned char b_OutputLevel;
201 unsigned char b_HardwareGateLevel;
202 unsigned int dw_ConfigurationWord;
203 } s_82X54TimerInfo[3];
204 unsigned char b_InterruptMask;
207 /*********************/
208 /* Chronometer infos */
209 /*********************/
212 unsigned char b_ChronoInit;
213 unsigned char b_InterruptMask;
214 unsigned char b_PCIInputClock;
215 unsigned char b_TimingUnit;
216 unsigned char b_CycleMode;
217 double d_TimingInterval;
218 unsigned int dw_ConfigReg;
219 } s_ChronoModuleInfo;
221 /***********************/
222 /* Pulse encoder infos */
223 /***********************/
227 unsigned char b_PulseEncoderInit;
228 } s_PulseEncoderInfo[4];
229 unsigned int dw_SetRegister;
230 unsigned int dw_ControlRegister;
231 unsigned int dw_StatusRegister;
232 } s_PulseEncoderModuleInfo;
234 /* Tor conter infos */
237 unsigned char b_TorCounterInit;
238 unsigned char b_TimingUnit;
239 unsigned char b_InterruptEnable;
240 double d_TimingInterval;
241 unsigned int ul_RealTimingInterval;
242 } s_TorCounterInfo[2];
243 unsigned char b_PCIInputClock;
244 } s_TorCounterModuleInfo;
249 unsigned char b_PWMInit;
250 unsigned char b_TimingUnit;
251 unsigned char b_InterruptEnable;
254 unsigned int ul_RealLowTiming;
255 unsigned int ul_RealHighTiming;
257 unsigned char b_ClockSelection;
263 unsigned char b_ETMEnable;
264 unsigned char b_ETMInterrupt;
266 unsigned char b_ETMInit;
267 unsigned char b_TimingUnit;
268 unsigned char b_ClockSelection;
269 double d_TimingInterval;
270 unsigned int ul_Timing;
275 unsigned char b_CDAEnable;
276 unsigned char b_CDAInterrupt;
277 unsigned char b_CDAInit;
278 unsigned char b_FctSelection;
279 unsigned char b_CDAReadFIFOOverflow;
284 /* Private structure for the addi_apci3120 driver */
285 struct addi_private {
288 int i_IobaseAmcc; /* base+size for AMCC chip */
289 int i_IobaseAddon; /* addon base address */
290 int i_IobaseReserved;
291 void __iomem *dw_AiBase;
292 unsigned char b_AiContinuous; /* we do unlimited AI */
293 unsigned char b_AiInitialisation;
294 unsigned int ui_AiActualScan; /* how many scans we finished */
295 unsigned int ui_AiBufferPtr; /* data buffer ptr in samples */
296 unsigned int ui_AiNbrofChannels; /* how many channels is measured */
297 unsigned int ui_AiScanLength; /* Length of actual scanlist */
298 unsigned int ui_AiActualScanPosition; /* position in actual scan */
299 unsigned int *pui_AiChannelList; /* actual chanlist */
300 unsigned int ui_AiChannelList[32]; /* actual chanlist */
301 unsigned char b_AiChannelConfiguration[32]; /* actual chanlist */
302 unsigned int ui_AiReadData[32];
303 unsigned int dw_AiInitialised;
304 unsigned int ui_AiTimer0; /* Timer Constant for Timer0 */
305 unsigned int ui_AiTimer1; /* Timer constant for Timer1 */
306 unsigned int ui_AiFlags;
307 unsigned int ui_AiDataLength;
308 short *AiData; /* Pointer to sample data */
309 unsigned int ui_AiNbrofScans; /* number of scans to do */
310 unsigned short us_UseDma; /* To use Dma or not */
311 unsigned char b_DmaDoubleBuffer; /* we can use double buffering */
312 unsigned int ui_DmaActualBuffer; /* which buffer is used now */
313 /* UPDATE-0.7.57->0.7.68 */
314 /* unsigned int ul_DmaBufferVirtual[2]; pointers to begin of DMA buffer */
315 short *ul_DmaBufferVirtual[2]; /* pointers to begin of DMA buffer */
316 unsigned int ul_DmaBufferHw[2]; /* hw address of DMA buff */
317 unsigned int ui_DmaBufferSize[2]; /* size of dma buffer in bytes */
318 unsigned int ui_DmaBufferUsesize[2]; /* which size we may now used for transfer */
319 unsigned int ui_DmaBufferSamples[2]; /* size in samples */
320 unsigned int ui_DmaBufferPages[2]; /* number of pages in buffer */
321 unsigned char b_DigitalOutputRegister; /* Digital Output Register */
322 unsigned char b_OutputMemoryStatus;
323 unsigned char b_AnalogInputChannelNbr; /* Analog input channel Nbr */
324 unsigned char b_AnalogOutputChannelNbr; /* Analog input Output Nbr */
325 unsigned char b_TimerSelectMode; /* Contain data written at iobase + 0C */
326 unsigned char b_ModeSelectRegister; /* Contain data written at iobase + 0E */
327 unsigned short us_OutputRegister; /* Contain data written at iobase + 0 */
328 unsigned char b_InterruptState;
329 unsigned char b_TimerInit; /* Specify if InitTimerWatchdog was load */
330 unsigned char b_TimerStarted; /* Specify if timer 2 is running or not */
331 unsigned char b_Timer2Mode; /* Specify the timer 2 mode */
332 unsigned char b_Timer2Interrupt; /* Timer2 interrupt enable or disable */
333 unsigned char b_AiCyclicAcquisition; /* indicate cyclic acquisition */
334 unsigned char b_InterruptMode; /* eoc eos or dma */
335 unsigned char b_EocEosInterrupt; /* Enable disable eoc eos interrupt */
336 unsigned int ui_EocEosConversionTime;
337 unsigned char b_EocEosConversionTimeBase;
338 unsigned char b_SingelDiff;
339 unsigned char b_ExttrigEnable; /* To enable or disable external trigger */
341 /* Pointer to the current process */
342 struct task_struct *tsk_Current;
344 /* Hardware board infos for 1710 */
346 unsigned int ui_Address; /* Board address */
347 unsigned int ui_FlashAddress;
348 unsigned char b_InterruptNbr; /* Board interrupt number */
349 unsigned char b_SlotNumber; /* PCI slot number */
350 unsigned char b_BoardVersion;
351 unsigned int dw_MolduleConfiguration[4]; /* Module config */
354 /* Interrupt infos */
356 unsigned int ul_InterruptOccur; /* 0 : No interrupt occur */
357 /* > 0 : Interrupt occur */
358 unsigned int ui_Read; /* Read FIFO */
359 unsigned int ui_Write; /* Write FIFO */
361 unsigned char b_OldModuleMask;
362 unsigned int ul_OldInterruptMask; /* Interrupt mask */
363 unsigned int ul_OldCounterLatchValue; /* Interrupt counter value */
364 } s_FIFOInterruptParameters[APCI1710_SAVE_INTERRUPT];
365 } s_InterruptParameters;
367 union str_ModuleInfo s_ModuleInfo[4];
368 unsigned int ul_TTLPortConfiguration[10];
370 /* Parameters read from EEPROM overriding static board info */
372 int i_NbrAiChannel; /* num of A/D chans */
373 int i_NbrAoChannel; /* num of D/A chans */
374 int i_AiMaxdata; /* resolution of A/D */
375 int i_AoMaxdata; /* resolution of D/A */
376 int i_NbrDiChannel; /* Number of DI channels */
377 int i_NbrDoChannel; /* Number of DO channels */
378 int i_DoMaxdata; /* data to set all channels high */
379 int i_Dma; /* dma present or not */
380 int i_Timer; /* timer subdevice present or not */
381 unsigned int ui_MinAcquisitiontimeNs;
382 /* Minimum Acquisition in Nano secs */
383 unsigned int ui_MinDelaytimeNs;
384 /* Minimum Delay in Nano secs */