Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
addi_common.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
3  *
4  * ADDI-DATA GmbH
5  * Dieselstrasse 3
6  * D-77833 Ottersweier
7  * Tel: +19(0)7223/9493-0
8  * Fax: +49(0)7223/9493-92
9  * http://www.addi-data.com
11  *
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)
15  * any later version.
16  */
17 
18 #include <linux/kernel.h>
19 #include <linux/module.h>
20 #include <linux/sched.h>
21 #include <linux/mm.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>
30 #include <linux/io.h>
31 #include <linux/kmod.h>
32 #include <linux/uaccess.h>
33 #include "../../comedidev.h"
34 #include "addi_amcc_s5933.h"
35 
36 #define ERROR -1
37 #define SUCCESS 1
38 
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))
45 
46 #define ADDI_ENABLE 1
47 #define ADDI_DISABLE 0
48 #define APCI1710_SAVE_INTERRUPT 1
49 
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"
56 
57 /* ADDIDATA Enable Disable */
58 #define ADDIDATA_ENABLE 1
59 #define ADDIDATA_DISABLE 0
60 
61 /* Structures */
62 
63 /* structure for the boardtype */
64 struct addi_board {
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 */
82 
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 */
86 
87  int i_NbrTTLChannel; /* Number of TTL channels */
88 
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 */
94 
95  /* interrupt and reset */
96  void (*interrupt)(int irq, void *d);
97  int (*reset)(struct comedi_device *);
98 
99  /* Subdevice functions */
100 
101  /* ANALOG INPUT */
103  struct comedi_insn *, unsigned int *);
104  int (*ai_read)(struct comedi_device *, struct comedi_subdevice *,
105  struct comedi_insn *, unsigned int *);
107  struct comedi_insn *, unsigned int *);
108  int (*ai_bits)(struct comedi_device *, struct comedi_subdevice *,
109  struct comedi_insn *, unsigned int *);
111  struct comedi_cmd *);
112  int (*ai_cmd)(struct comedi_device *, struct comedi_subdevice *);
113  int (*ai_cancel)(struct comedi_device *, struct comedi_subdevice *);
114 
115  /* Analog Output */
117  struct comedi_insn *, unsigned int *);
119  struct comedi_insn *, unsigned int *);
120  int (*ao_bits)(struct comedi_device *, struct comedi_subdevice *,
121  struct comedi_insn *, unsigned int *);
122 
123  /* Digital Input */
125  struct comedi_insn *, unsigned int *);
126  int (*di_read)(struct comedi_device *, struct comedi_subdevice *,
127  struct comedi_insn *, unsigned int *);
129  struct comedi_insn *, unsigned int *);
130  int (*di_bits)(struct comedi_device *, struct comedi_subdevice *,
131  struct comedi_insn *, unsigned int *);
132 
133  /* Digital Output */
135  struct comedi_insn *, unsigned int *);
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 *);
142 
143  /* TIMER */
145  struct comedi_insn *, unsigned int *);
147  struct comedi_insn *, unsigned int *);
149  struct comedi_insn *, unsigned int *);
151  struct comedi_insn *, unsigned int *);
152 
153  /* TTL IO */
155  struct comedi_insn *, unsigned int *);
157  struct comedi_insn *, unsigned int *);
159  struct comedi_insn *, unsigned int *);
161  struct comedi_insn *, unsigned int *);
162 };
163 
164 /* MODULE INFO STRUCTURE */
165 
167  /* Incremental counter infos */
168  struct {
169  union {
170  struct {
171  unsigned char b_ModeRegister1;
172  unsigned char b_ModeRegister2;
173  unsigned char b_ModeRegister3;
174  unsigned char b_ModeRegister4;
177  } s_ModeRegister;
178 
179  struct {
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;
187  } s_InitFlag;
188 
190 
191  /* SSI infos */
192  struct {
193  unsigned char b_SSIProfile;
194  unsigned char b_PositionTurnLength;
195  unsigned char b_TurnCptLength;
196  unsigned char b_SSIInit;
198 
199  /* TTL I/O infos */
200  struct {
201  unsigned char b_TTLInit;
202  unsigned char b_PortConfiguration[4];
203  } s_TTLIOInfo;
204 
205  /* Digital I/O infos */
206  struct {
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;
212  } s_DigitalIOInfo;
213 
214  /*********************/
215  /* 82X54 timer infos */
216  /*********************/
217 
218  struct {
219  struct {
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;
229 
230  /*********************/
231  /* Chronometer infos */
232  /*********************/
233 
234  struct {
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;
241  unsigned int dw_ConfigReg;
243 
244  /***********************/
245  /* Pulse encoder infos */
246  /***********************/
247 
248  struct {
249  struct {
250  unsigned char b_PulseEncoderInit;
251  } s_PulseEncoderInfo[4];
252  unsigned int dw_SetRegister;
253  unsigned int dw_ControlRegister;
254  unsigned int dw_StatusRegister;
256 
257  /* Tor conter infos */
258  struct {
259  struct {
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;
268 
269  /* PWM infos */
270  struct {
271  struct {
272  unsigned char b_PWMInit;
273  unsigned char b_TimingUnit;
274  unsigned char b_InterruptEnable;
275  double d_LowTiming;
276  double d_HighTiming;
277  unsigned int ul_RealLowTiming;
278  unsigned int ul_RealHighTiming;
279  } s_PWMInfo[2];
280  unsigned char b_ClockSelection;
281  } s_PWMModuleInfo;
282 
283  /* ETM infos */
284  struct {
285  struct {
286  unsigned char b_ETMEnable;
287  unsigned char b_ETMInterrupt;
288  } s_ETMInfo[2];
289  unsigned char b_ETMInit;
290  unsigned char b_TimingUnit;
291  unsigned char b_ClockSelection;
292  double d_TimingInterval;
293  unsigned int ul_Timing;
294  } s_ETMModuleInfo;
295 
296  /* CDA infos */
297  struct {
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;
303  } s_CDAModuleInfo;
304 
305 };
306 
307 /* Private structure for the addi_apci3120 driver */
308 struct addi_private {
309 
310  int iobase;
311  int i_IobaseAmcc; /* base+size for AMCC chip */
312  int i_IobaseAddon; /* addon base address */
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 */
364  unsigned char b_SingelDiff;
365  unsigned char b_ExttrigEnable; /* To enable or disable external trigger */
366 
367  /* Pointer to the current process */
369 
370  /* Hardware board infos for 1710 */
371  struct {
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 */
378  } s_BoardInfos;
379 
380  /* Interrupt infos */
381  struct {
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 */
386  struct {
387  unsigned char b_OldModuleMask;
388  unsigned int ul_OldInterruptMask; /* Interrupt mask */
389  unsigned int ul_OldCounterLatchValue; /* Interrupt counter value */
392 
394  unsigned int ul_TTLPortConfiguration[10];
395 
396  /* Parameters read from EEPROM overriding static board info */
397  struct {
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 */
408  /* Minimum Acquisition in Nano secs */
409  unsigned int ui_MinDelaytimeNs;
410  /* Minimum Delay in Nano secs */
411  } s_EeParameters;
412 };
413 
414 static unsigned short pci_list_builded; /* set to 1 when list of card is known */
415 
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);
420 
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);