Merge tag 'tty-3.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty
[platform/adaptation/renesas_rcar/renesas_kernel.git] / drivers / staging / comedi / drivers / addi-data / addi_common.h
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
10  *      info@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/sched.h>
19 #include <linux/interrupt.h>
20
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))
27
28 #define ADDI_ENABLE             1
29 #define ADDI_DISABLE            0
30 #define APCI1710_SAVE_INTERRUPT 1
31
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"
38
39 /* ADDIDATA Enable Disable */
40 #define ADDIDATA_ENABLE         1
41 #define ADDIDATA_DISABLE        0
42
43 /* Structures */
44
45 /* structure for the boardtype */
46 struct addi_board {
47         const char *pc_DriverName;      /*  driver name */
48         int i_IorangeBase1;
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 */
59
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 */
63
64         int i_NbrTTLChannel;    /*  Number of TTL channels */
65
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 */
71
72         /* interrupt and reset */
73         void (*interrupt)(int irq, void *d);
74         int (*reset)(struct comedi_device *);
75
76         /* Subdevice functions */
77
78         /* ANALOG INPUT */
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 *,
88                           struct comedi_cmd *);
89         int (*ai_cmd)(struct comedi_device *, struct comedi_subdevice *);
90         int (*ai_cancel)(struct comedi_device *, struct comedi_subdevice *);
91
92         /* Analog Output */
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 *);
99
100         /* Digital Input */
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 *);
109
110         /* Digital Output */
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 *);
119
120         /* TIMER */
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 *);
129
130         /* TTL IO */
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 *);
139 };
140
141 /* MODULE INFO STRUCTURE */
142
143 union str_ModuleInfo {
144         /* Incremental counter infos */
145         struct {
146                 union {
147                         struct {
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;
154                 } s_ModeRegister;
155
156                 struct {
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;
164                 } s_InitFlag;
165
166         } s_SiemensCounterInfo;
167
168         /* SSI infos */
169         struct {
170                 unsigned char b_SSIProfile;
171                 unsigned char b_PositionTurnLength;
172                 unsigned char b_TurnCptLength;
173                 unsigned char b_SSIInit;
174         } s_SSICounterInfo;
175
176         /* TTL I/O infos */
177         struct {
178                 unsigned char b_TTLInit;
179                 unsigned char b_PortConfiguration[4];
180         } s_TTLIOInfo;
181
182         /* Digital I/O infos */
183         struct {
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;
189         } s_DigitalIOInfo;
190
191       /*********************/
192         /* 82X54 timer infos */
193       /*********************/
194
195         struct {
196                 struct {
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;
205         } s_82X54ModuleInfo;
206
207       /*********************/
208         /* Chronometer infos */
209       /*********************/
210
211         struct {
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;
220
221       /***********************/
222         /* Pulse encoder infos */
223       /***********************/
224
225         struct {
226                 struct {
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;
233
234         /* Tor conter infos */
235         struct {
236                 struct {
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;
245
246         /* PWM infos */
247         struct {
248                 struct {
249                         unsigned char b_PWMInit;
250                         unsigned char b_TimingUnit;
251                         unsigned char b_InterruptEnable;
252                         double d_LowTiming;
253                         double d_HighTiming;
254                         unsigned int ul_RealLowTiming;
255                         unsigned int ul_RealHighTiming;
256                 } s_PWMInfo[2];
257                 unsigned char b_ClockSelection;
258         } s_PWMModuleInfo;
259
260         /* ETM infos */
261         struct {
262                 struct {
263                         unsigned char b_ETMEnable;
264                         unsigned char b_ETMInterrupt;
265                 } s_ETMInfo[2];
266                 unsigned char b_ETMInit;
267                 unsigned char b_TimingUnit;
268                 unsigned char b_ClockSelection;
269                 double d_TimingInterval;
270                 unsigned int ul_Timing;
271         } s_ETMModuleInfo;
272
273         /* CDA infos */
274         struct {
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;
280         } s_CDAModuleInfo;
281
282 };
283
284 /* Private structure for the addi_apci3120 driver */
285 struct addi_private {
286
287         int iobase;
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 */
340
341         /* Pointer to the current process */
342         struct task_struct *tsk_Current;
343
344         /* Hardware board infos for 1710 */
345         struct {
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 */
352         } s_BoardInfos;
353
354         /* Interrupt infos */
355         struct {
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 */
360                 struct {
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;
366
367         union str_ModuleInfo s_ModuleInfo[4];
368         unsigned int ul_TTLPortConfiguration[10];
369
370         /* Parameters read from EEPROM overriding static board info */
371         struct {
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 */
385         } s_EeParameters;
386 };