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/kernel.h>
19 #include <linux/module.h>
20 #include <linux/sched.h>
22 #include <linux/slab.h>
23 #include <linux/errno.h>
24 #include <linux/ioport.h>
25 #include <linux/delay.h>
26 #include <linux/interrupt.h>
27 #include <linux/timex.h>
28 #include <linux/timer.h>
29 #include <linux/pci.h>
31 #include <linux/kmod.h>
32 #include <linux/uaccess.h>
33 #include "../../comedidev.h"
34 #include "addi_amcc_s5933.h"
39 #define LOBYTE(W) (unsigned char)((W) & 0xFF)
40 #define HIBYTE(W) (unsigned char)(((W) >> 8) & 0xFF)
41 #define MAKEWORD(H, L) (unsigned short)((L) | ((H) << 8))
42 #define LOWORD(W) (unsigned short)((W) & 0xFFFF)
43 #define HIWORD(W) (unsigned short)(((W) >> 16) & 0xFFFF)
44 #define MAKEDWORD(H, L) (unsigned int)((L) | ((H) << 16))
47 #define ADDI_DISABLE 0
48 #define APCI1710_SAVE_INTERRUPT 1
50 #define ADDIDATA_EEPROM 1
51 #define ADDIDATA_NO_EEPROM 0
52 #define ADDIDATA_93C76 "93C76"
53 #define ADDIDATA_S5920 "S5920"
54 #define ADDIDATA_S5933 "S5933"
55 #define ADDIDATA_9054 "9054"
57 /* ADDIDATA Enable Disable */
58 #define ADDIDATA_ENABLE 1
59 #define ADDIDATA_DISABLE 0
63 /* structure for the boardtype */
65 const char *pc_DriverName; /* driver name */
66 int i_VendorId; /* PCI vendor a device ID of card */
70 int i_IorangeBase2; /* base 2 range */
71 int i_IorangeBase3; /* base 3 range */
72 int i_PCIEeprom; /* eeprom present or not */
73 char *pc_EepromChip; /* type of chip */
74 int i_NbrAiChannel; /* num of A/D chans */
75 int i_NbrAiChannelDiff; /* num of A/D chans in diff mode */
76 int i_AiChannelList; /* len of chanlist */
77 int i_NbrAoChannel; /* num of D/A chans */
78 int i_AiMaxdata; /* resolution of A/D */
79 int i_AoMaxdata; /* resolution of D/A */
80 const struct comedi_lrange *pr_AiRangelist; /* rangelist for A/D */
81 const struct comedi_lrange *pr_AoRangelist; /* rangelist for D/A */
83 int i_NbrDiChannel; /* Number of DI channels */
84 int i_NbrDoChannel; /* Number of DO channels */
85 int i_DoMaxdata; /* data to set all channels high */
87 int i_NbrTTLChannel; /* Number of TTL channels */
89 int i_Dma; /* dma present or not */
90 int i_Timer; /* timer subdevice present or not */
91 unsigned char b_AvailableConvertUnit;
92 unsigned int ui_MinAcquisitiontimeNs; /* Minimum Acquisition in Nano secs */
93 unsigned int ui_MinDelaytimeNs; /* Minimum Delay in Nano secs */
95 /* interrupt and reset */
96 void (*interrupt)(int irq, void *d);
97 int (*reset)(struct comedi_device *);
99 /* Subdevice functions */
102 int (*ai_config)(struct comedi_device *, struct comedi_subdevice *,
103 struct comedi_insn *, unsigned int *);
104 int (*ai_read)(struct comedi_device *, struct comedi_subdevice *,
105 struct comedi_insn *, unsigned int *);
106 int (*ai_write)(struct comedi_device *, struct comedi_subdevice *,
107 struct comedi_insn *, unsigned int *);
108 int (*ai_bits)(struct comedi_device *, struct comedi_subdevice *,
109 struct comedi_insn *, unsigned int *);
110 int (*ai_cmdtest)(struct comedi_device *, struct comedi_subdevice *,
111 struct comedi_cmd *);
112 int (*ai_cmd)(struct comedi_device *, struct comedi_subdevice *);
113 int (*ai_cancel)(struct comedi_device *, struct comedi_subdevice *);
116 int (*ao_config)(struct comedi_device *, struct comedi_subdevice *,
117 struct comedi_insn *, unsigned int *);
118 int (*ao_write)(struct comedi_device *, struct comedi_subdevice *,
119 struct comedi_insn *, unsigned int *);
120 int (*ao_bits)(struct comedi_device *, struct comedi_subdevice *,
121 struct comedi_insn *, unsigned int *);
124 int (*di_config)(struct comedi_device *, struct comedi_subdevice *,
125 struct comedi_insn *, unsigned int *);
126 int (*di_read)(struct comedi_device *, struct comedi_subdevice *,
127 struct comedi_insn *, unsigned int *);
128 int (*di_write)(struct comedi_device *, struct comedi_subdevice *,
129 struct comedi_insn *, unsigned int *);
130 int (*di_bits)(struct comedi_device *, struct comedi_subdevice *,
131 struct comedi_insn *, unsigned int *);
134 int (*do_config)(struct comedi_device *, struct comedi_subdevice *,
135 struct comedi_insn *, unsigned int *);
136 int (*do_write)(struct comedi_device *, struct comedi_subdevice *,
137 struct comedi_insn *, unsigned int *);
138 int (*do_bits)(struct comedi_device *, struct comedi_subdevice *,
139 struct comedi_insn *, unsigned int *);
140 int (*do_read)(struct comedi_device *, struct comedi_subdevice *,
141 struct comedi_insn *, unsigned int *);
144 int (*timer_config)(struct comedi_device *, struct comedi_subdevice *,
145 struct comedi_insn *, unsigned int *);
146 int (*timer_write)(struct comedi_device *, struct comedi_subdevice *,
147 struct comedi_insn *, unsigned int *);
148 int (*timer_read)(struct comedi_device *, struct comedi_subdevice *,
149 struct comedi_insn *, unsigned int *);
150 int (*timer_bits)(struct comedi_device *, struct comedi_subdevice *,
151 struct comedi_insn *, unsigned int *);
154 int (*ttl_config)(struct comedi_device *, struct comedi_subdevice *,
155 struct comedi_insn *, unsigned int *);
156 int (*ttl_bits)(struct comedi_device *, struct comedi_subdevice *,
157 struct comedi_insn *, unsigned int *);
158 int (*ttl_read)(struct comedi_device *, struct comedi_subdevice *,
159 struct comedi_insn *, unsigned int *);
160 int (*ttl_write)(struct comedi_device *, struct comedi_subdevice *,
161 struct comedi_insn *, unsigned int *);
164 /* MODULE INFO STRUCTURE */
166 union str_ModuleInfo {
167 /* Incremental counter infos */
171 unsigned char b_ModeRegister1;
172 unsigned char b_ModeRegister2;
173 unsigned char b_ModeRegister3;
174 unsigned char b_ModeRegister4;
175 } s_ByteModeRegister;
176 unsigned int dw_ModeRegister1_2_3_4;
180 unsigned int b_IndexInit:1;
181 unsigned int b_CounterInit:1;
182 unsigned int b_ReferenceInit:1;
183 unsigned int b_IndexInterruptOccur:1;
184 unsigned int b_CompareLogicInit:1;
185 unsigned int b_FrequencyMeasurementInit:1;
186 unsigned int b_FrequencyMeasurementEnable:1;
189 } s_SiemensCounterInfo;
193 unsigned char b_SSIProfile;
194 unsigned char b_PositionTurnLength;
195 unsigned char b_TurnCptLength;
196 unsigned char b_SSIInit;
201 unsigned char b_TTLInit;
202 unsigned char b_PortConfiguration[4];
205 /* Digital I/O infos */
207 unsigned char b_DigitalInit;
208 unsigned char b_ChannelAMode;
209 unsigned char b_ChannelBMode;
210 unsigned char b_OutputMemoryEnabled;
211 unsigned int dw_OutputMemory;
214 /*********************/
215 /* 82X54 timer infos */
216 /*********************/
220 unsigned char b_82X54Init;
221 unsigned char b_InputClockSelection;
222 unsigned char b_InputClockLevel;
223 unsigned char b_OutputLevel;
224 unsigned char b_HardwareGateLevel;
225 unsigned int dw_ConfigurationWord;
226 } s_82X54TimerInfo[3];
227 unsigned char b_InterruptMask;
230 /*********************/
231 /* Chronometer infos */
232 /*********************/
235 unsigned char b_ChronoInit;
236 unsigned char b_InterruptMask;
237 unsigned char b_PCIInputClock;
238 unsigned char b_TimingUnit;
239 unsigned char b_CycleMode;
240 double d_TimingInterval;
241 unsigned int dw_ConfigReg;
242 } s_ChronoModuleInfo;
244 /***********************/
245 /* Pulse encoder infos */
246 /***********************/
250 unsigned char b_PulseEncoderInit;
251 } s_PulseEncoderInfo[4];
252 unsigned int dw_SetRegister;
253 unsigned int dw_ControlRegister;
254 unsigned int dw_StatusRegister;
255 } s_PulseEncoderModuleInfo;
257 /* Tor conter infos */
260 unsigned char b_TorCounterInit;
261 unsigned char b_TimingUnit;
262 unsigned char b_InterruptEnable;
263 double d_TimingInterval;
264 unsigned int ul_RealTimingInterval;
265 } s_TorCounterInfo[2];
266 unsigned char b_PCIInputClock;
267 } s_TorCounterModuleInfo;
272 unsigned char b_PWMInit;
273 unsigned char b_TimingUnit;
274 unsigned char b_InterruptEnable;
277 unsigned int ul_RealLowTiming;
278 unsigned int ul_RealHighTiming;
280 unsigned char b_ClockSelection;
286 unsigned char b_ETMEnable;
287 unsigned char b_ETMInterrupt;
289 unsigned char b_ETMInit;
290 unsigned char b_TimingUnit;
291 unsigned char b_ClockSelection;
292 double d_TimingInterval;
293 unsigned int ul_Timing;
298 unsigned char b_CDAEnable;
299 unsigned char b_CDAInterrupt;
300 unsigned char b_CDAInit;
301 unsigned char b_FctSelection;
302 unsigned char b_CDAReadFIFOOverflow;
307 /* Private structure for the addi_apci3120 driver */
308 struct addi_private {
311 int i_IobaseAmcc; /* base+size for AMCC chip */
312 int i_IobaseAddon; /* addon base address */
313 int i_IobaseReserved;
314 void __iomem *dw_AiBase;
315 struct pcilst_struct *amcc; /* ptr too AMCC data */
316 unsigned char allocated; /* we have blocked card */
317 unsigned char b_ValidDriver; /* driver is ok */
318 unsigned char b_AiContinuous; /* we do unlimited AI */
319 unsigned char b_AiInitialisation;
320 unsigned int ui_AiActualScan; /* how many scans we finished */
321 unsigned int ui_AiBufferPtr; /* data buffer ptr in samples */
322 unsigned int ui_AiNbrofChannels; /* how many channels is measured */
323 unsigned int ui_AiScanLength; /* Length of actual scanlist */
324 unsigned int ui_AiActualScanPosition; /* position in actual scan */
325 unsigned int *pui_AiChannelList; /* actual chanlist */
326 unsigned int ui_AiChannelList[32]; /* actual chanlist */
327 unsigned char b_AiChannelConfiguration[32]; /* actual chanlist */
328 unsigned int ui_AiReadData[32];
329 unsigned int dw_AiInitialised;
330 unsigned int ui_AiTimer0; /* Timer Constant for Timer0 */
331 unsigned int ui_AiTimer1; /* Timer constant for Timer1 */
332 unsigned int ui_AiFlags;
333 unsigned int ui_AiDataLength;
334 short *AiData; /* Pointer to sample data */
335 unsigned int ui_AiNbrofScans; /* number of scans to do */
336 unsigned short us_UseDma; /* To use Dma or not */
337 unsigned char b_DmaDoubleBuffer; /* we can use double buffering */
338 unsigned int ui_DmaActualBuffer; /* which buffer is used now */
339 /* UPDATE-0.7.57->0.7.68 */
340 /* unsigned int ul_DmaBufferVirtual[2]; pointers to begin of DMA buffer */
341 short *ul_DmaBufferVirtual[2]; /* pointers to begin of DMA buffer */
342 unsigned int ul_DmaBufferHw[2]; /* hw address of DMA buff */
343 unsigned int ui_DmaBufferSize[2]; /* size of dma buffer in bytes */
344 unsigned int ui_DmaBufferUsesize[2]; /* which size we may now used for transfer */
345 unsigned int ui_DmaBufferSamples[2]; /* size in samples */
346 unsigned int ui_DmaBufferPages[2]; /* number of pages in buffer */
347 unsigned char b_DigitalOutputRegister; /* Digital Output Register */
348 unsigned char b_OutputMemoryStatus;
349 unsigned char b_AnalogInputChannelNbr; /* Analog input channel Nbr */
350 unsigned char b_AnalogOutputChannelNbr; /* Analog input Output Nbr */
351 unsigned char b_TimerSelectMode; /* Contain data written at iobase + 0C */
352 unsigned char b_ModeSelectRegister; /* Contain data written at iobase + 0E */
353 unsigned short us_OutputRegister; /* Contain data written at iobase + 0 */
354 unsigned char b_InterruptState;
355 unsigned char b_TimerInit; /* Specify if InitTimerWatchdog was load */
356 unsigned char b_TimerStarted; /* Specify if timer 2 is running or not */
357 unsigned char b_Timer2Mode; /* Specify the timer 2 mode */
358 unsigned char b_Timer2Interrupt; /* Timer2 interrupt enable or disable */
359 unsigned char b_AiCyclicAcquisition; /* indicate cyclic acquisition */
360 unsigned char b_InterruptMode; /* eoc eos or dma */
361 unsigned char b_EocEosInterrupt; /* Enable disable eoc eos interrupt */
362 unsigned int ui_EocEosConversionTime;
363 unsigned char b_EocEosConversionTimeBase;
364 unsigned char b_SingelDiff;
365 unsigned char b_ExttrigEnable; /* To enable or disable external trigger */
367 /* Pointer to the current process */
368 struct task_struct *tsk_Current;
370 /* Hardware board infos for 1710 */
372 unsigned int ui_Address; /* Board address */
373 unsigned int ui_FlashAddress;
374 unsigned char b_InterruptNbr; /* Board interrupt number */
375 unsigned char b_SlotNumber; /* PCI slot number */
376 unsigned char b_BoardVersion;
377 unsigned int dw_MolduleConfiguration[4]; /* Module config */
380 /* Interrupt infos */
382 unsigned int ul_InterruptOccur; /* 0 : No interrupt occur */
383 /* > 0 : Interrupt occur */
384 unsigned int ui_Read; /* Read FIFO */
385 unsigned int ui_Write; /* Write FIFO */
387 unsigned char b_OldModuleMask;
388 unsigned int ul_OldInterruptMask; /* Interrupt mask */
389 unsigned int ul_OldCounterLatchValue; /* Interrupt counter value */
390 } s_FIFOInterruptParameters[APCI1710_SAVE_INTERRUPT];
391 } s_InterruptParameters;
393 union str_ModuleInfo s_ModuleInfo[4];
394 unsigned int ul_TTLPortConfiguration[10];
396 /* Parameters read from EEPROM overriding static board info */
398 int i_NbrAiChannel; /* num of A/D chans */
399 int i_NbrAoChannel; /* num of D/A chans */
400 int i_AiMaxdata; /* resolution of A/D */
401 int i_AoMaxdata; /* resolution of D/A */
402 int i_NbrDiChannel; /* Number of DI channels */
403 int i_NbrDoChannel; /* Number of DO channels */
404 int i_DoMaxdata; /* data to set all channels high */
405 int i_Dma; /* dma present or not */
406 int i_Timer; /* timer subdevice present or not */
407 unsigned int ui_MinAcquisitiontimeNs;
408 /* Minimum Acquisition in Nano secs */
409 unsigned int ui_MinDelaytimeNs;
410 /* Minimum Delay in Nano secs */
414 static unsigned short pci_list_builded; /* set to 1 when list of card is known */
416 /* Function declarations */
417 static int i_ADDI_Attach(struct comedi_device *dev, struct comedi_devconfig *it);
418 static void i_ADDI_Detach(struct comedi_device *dev);
419 static int i_ADDI_Reset(struct comedi_device *dev);
421 static irqreturn_t v_ADDI_Interrupt(int irq, void *d);
422 static int i_ADDIDATA_InsnReadEeprom(struct comedi_device *dev, struct comedi_subdevice *s,
423 struct comedi_insn *insn, unsigned int *data);