Staging: comedi: Remove comedi_devconfig typedef
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / staging / comedi / drivers / addi-data / addi_common.h
CommitLineData
c995fe94 1/*
15d8826a
GKH
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 */
c995fe94
ADG
17
18#include <linux/kernel.h>
19#include <linux/module.h>
20#include <linux/sched.h>
21#include <linux/mm.h>
c995fe94
ADG
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>
15d8826a
GKH
30#include <linux/io.h>
31#include <linux/kmod.h>
32#include <linux/uaccess.h>
c995fe94
ADG
33#include "../../comedidev.h"
34#include "addi_amcc_s5933.h"
c995fe94 35
15d8826a
GKH
36#define ERROR -1
37#define SUCCESS 1
c995fe94 38
15d8826a 39/* variable type definition */
c995fe94
ADG
40typedef void VOID, *PVOID;
41typedef char CHAR, *PCHAR;
42typedef const CHAR *PCSTR;
43typedef unsigned char BYTE, *PBYTE;
44typedef short SHORT, *PSHORT;
45typedef unsigned short USHORT, *PUSHORT;
46typedef unsigned short WORD, *PWORD;
47typedef int INT, *PINT;;
48typedef unsigned int UINT, *PUINT;
15d8826a 49typedef int LONG, *PLONG; /* 32-bit */
c995fe94
ADG
50typedef unsigned int ULONG, *PULONG; /* 32-bit */
51typedef unsigned int DWORD, *PDWORD; /* 32-bit */
52typedef unsigned long ULONG_PTR;
53
9ced1de6 54typedef const struct comedi_lrange *PCRANGE;
c995fe94 55
15d8826a
GKH
56#define LOBYTE(W) (BYTE)((W) & 0xFF)
57#define HIBYTE(W) (BYTE)(((W) >> 8) & 0xFF)
58#define MAKEWORD(H, L) (USHORT)((L) | ((H) << 8))
59#define LOWORD(W) (USHORT)((W) & 0xFFFF)
60#define HIWORD(W) (USHORT)(((W) >> 16) & 0xFFFF)
61#define MAKEDWORD(H, L) (UINT)((L) | ((H) << 16))
62
63#define ADDI_ENABLE 1
64#define ADDI_DISABLE 0
65#define APCI1710_SAVE_INTERRUPT 1
66
67#define ADDIDATA_EEPROM 1
68#define ADDIDATA_NO_EEPROM 0
69#define ADDIDATA_93C76 "93C76"
70#define ADDIDATA_S5920 "S5920"
71#define ADDIDATA_S5933 "S5933"
72#define ADDIDATA_9054 "9054"
73
74/* ADDIDATA Enable Disable */
75#define ADDIDATA_ENABLE 1
76#define ADDIDATA_DISABLE 0
77
78/* Structures */
79
80/* structure for the boardtype */
81typedef struct {
c995fe94
ADG
82 PCSTR pc_DriverName; // driver name
83 INT i_VendorId; //PCI vendor a device ID of card
84 INT i_DeviceId;
85 INT i_IorangeBase0;
86 INT i_IorangeBase1;
87 INT i_IorangeBase2; // base 2 range
88 INT i_IorangeBase3; // base 3 range
89 INT i_PCIEeprom; // eeprom present or not
90 PCHAR pc_EepromChip; // type of chip
91 INT i_NbrAiChannel; // num of A/D chans
92 INT i_NbrAiChannelDiff; // num of A/D chans in diff mode
93 INT i_AiChannelList; // len of chanlist
94 INT i_NbrAoChannel; // num of D/A chans
95 INT i_AiMaxdata; // resolution of A/D
96 INT i_AoMaxdata; // resolution of D/A
97 PCRANGE pr_AiRangelist; // rangelist for A/D
98 PCRANGE pr_AoRangelist; // rangelist for D/A
99
100 INT i_NbrDiChannel; // Number of DI channels
101 INT i_NbrDoChannel; // Number of DO channels
102 INT i_DoMaxdata; // data to set all chanels high
103
104 INT i_NbrTTLChannel; // Number of TTL channels
105 PCRANGE pr_TTLRangelist; // rangelist for TTL
106
107 INT i_Dma; // dma present or not
108 INT i_Timer; // timer subdevice present or not
109 BYTE b_AvailableConvertUnit;
110 UINT ui_MinAcquisitiontimeNs; // Minimum Acquisition in Nano secs
111 UINT ui_MinDelaytimeNs; // Minimum Delay in Nano secs
112
15d8826a
GKH
113 /* interrupt and reset */
114 void (*v_hwdrv_Interrupt)(int irq, void *d);
71b5f4f1 115 int (*i_hwdrv_Reset)(struct comedi_device *dev);
15d8826a
GKH
116
117 /* Subdevice functions */
118
119 /* ANALOG INPUT */
71b5f4f1 120 int (*i_hwdrv_InsnConfigAnalogInput)(struct comedi_device *dev,
34c43922 121 struct comedi_subdevice *s,
90035c08 122 struct comedi_insn *insn,
790c5541 123 unsigned int *data);
71b5f4f1 124 int (*i_hwdrv_InsnReadAnalogInput)(struct comedi_device *dev,
34c43922 125 struct comedi_subdevice *s,
90035c08 126 struct comedi_insn *insn,
790c5541 127 unsigned int *data);
71b5f4f1 128 int (*i_hwdrv_InsnWriteAnalogInput)(struct comedi_device *dev,
34c43922 129 struct comedi_subdevice *s,
90035c08 130 struct comedi_insn *insn,
790c5541 131 unsigned int *data);
71b5f4f1 132 int (*i_hwdrv_InsnBitsAnalogInput)(struct comedi_device *dev,
34c43922 133 struct comedi_subdevice *s,
90035c08 134 struct comedi_insn *insn,
790c5541 135 unsigned int *data);
71b5f4f1 136 int (*i_hwdrv_CommandTestAnalogInput)(struct comedi_device *dev,
34c43922 137 struct comedi_subdevice *s,
ea6d0d4c 138 struct comedi_cmd *cmd);
71b5f4f1 139 int (*i_hwdrv_CommandAnalogInput)(struct comedi_device *dev,
34c43922 140 struct comedi_subdevice *s);
71b5f4f1 141 int (*i_hwdrv_CancelAnalogInput)(struct comedi_device *dev,
34c43922 142 struct comedi_subdevice *s);
15d8826a
GKH
143
144 /* Analog Output */
71b5f4f1 145 int (*i_hwdrv_InsnConfigAnalogOutput)(struct comedi_device *dev,
34c43922 146 struct comedi_subdevice *s,
90035c08 147 struct comedi_insn *insn,
790c5541 148 unsigned int *data);
71b5f4f1 149 int (*i_hwdrv_InsnWriteAnalogOutput)(struct comedi_device *dev,
34c43922 150 struct comedi_subdevice *s,
90035c08 151 struct comedi_insn *insn,
790c5541 152 unsigned int *data);
71b5f4f1 153 int (*i_hwdrv_InsnBitsAnalogOutput)(struct comedi_device *dev,
34c43922 154 struct comedi_subdevice *s,
90035c08 155 struct comedi_insn *insn,
790c5541 156 unsigned int *data);
15d8826a
GKH
157
158 /* Digital Input */
71b5f4f1 159 int (*i_hwdrv_InsnConfigDigitalInput) (struct comedi_device *dev,
34c43922 160 struct comedi_subdevice *s,
90035c08 161 struct comedi_insn *insn,
790c5541 162 unsigned int *data);
71b5f4f1 163 int (*i_hwdrv_InsnReadDigitalInput) (struct comedi_device *dev,
34c43922 164 struct comedi_subdevice *s,
90035c08 165 struct comedi_insn *insn,
790c5541 166 unsigned int *data);
71b5f4f1 167 int (*i_hwdrv_InsnWriteDigitalInput) (struct comedi_device *dev,
34c43922 168 struct comedi_subdevice *s,
90035c08 169 struct comedi_insn *insn,
790c5541 170 unsigned int *data);
71b5f4f1 171 int (*i_hwdrv_InsnBitsDigitalInput) (struct comedi_device *dev,
34c43922 172 struct comedi_subdevice *s,
90035c08 173 struct comedi_insn *insn,
790c5541 174 unsigned int *data);
15d8826a
GKH
175
176 /* Digital Output */
71b5f4f1 177 int (*i_hwdrv_InsnConfigDigitalOutput)(struct comedi_device *dev,
34c43922 178 struct comedi_subdevice *s,
90035c08 179 struct comedi_insn *insn,
790c5541 180 unsigned int *data);
71b5f4f1 181 int (*i_hwdrv_InsnWriteDigitalOutput)(struct comedi_device *dev,
34c43922 182 struct comedi_subdevice *s,
90035c08 183 struct comedi_insn *insn,
790c5541 184 unsigned int *data);
71b5f4f1 185 int (*i_hwdrv_InsnBitsDigitalOutput)(struct comedi_device *dev,
34c43922 186 struct comedi_subdevice *s,
90035c08 187 struct comedi_insn *insn,
790c5541 188 unsigned int *data);
71b5f4f1 189 int (*i_hwdrv_InsnReadDigitalOutput)(struct comedi_device *dev,
34c43922 190 struct comedi_subdevice *s,
90035c08 191 struct comedi_insn *insn,
790c5541 192 unsigned int *data);
15d8826a
GKH
193
194 /* TIMER */
71b5f4f1 195 int (*i_hwdrv_InsnConfigTimer)(struct comedi_device *dev,
34c43922 196 struct comedi_subdevice *s,
90035c08 197 struct comedi_insn *insn, unsigned int *data);
71b5f4f1 198 int (*i_hwdrv_InsnWriteTimer)(struct comedi_device *dev,
90035c08 199 struct comedi_subdevice *s, struct comedi_insn *insn,
790c5541 200 unsigned int *data);
34c43922 201 int (*i_hwdrv_InsnReadTimer)(struct comedi_device *dev, struct comedi_subdevice *s,
90035c08 202 struct comedi_insn *insn, unsigned int *data);
34c43922 203 int (*i_hwdrv_InsnBitsTimer)(struct comedi_device *dev, struct comedi_subdevice *s,
90035c08 204 struct comedi_insn *insn, unsigned int *data);
15d8826a
GKH
205
206 /* TTL IO */
71b5f4f1 207 int (*i_hwdr_ConfigInitTTLIO)(struct comedi_device *dev,
90035c08 208 struct comedi_subdevice *s, struct comedi_insn *insn,
790c5541 209 unsigned int *data);
34c43922 210 int (*i_hwdr_ReadTTLIOBits)(struct comedi_device *dev, struct comedi_subdevice *s,
90035c08 211 struct comedi_insn *insn, unsigned int *data);
71b5f4f1 212 int (*i_hwdr_ReadTTLIOAllPortValue)(struct comedi_device *dev,
34c43922 213 struct comedi_subdevice *s,
90035c08 214 struct comedi_insn *insn,
790c5541 215 unsigned int *data);
71b5f4f1 216 int (*i_hwdr_WriteTTLIOChlOnOff)(struct comedi_device *dev,
34c43922 217 struct comedi_subdevice *s,
90035c08 218 struct comedi_insn *insn, unsigned int *data);
c995fe94
ADG
219} boardtype;
220
221//MODULE INFO STRUCTURE
222
223typedef union {
c995fe94 224 /* Incremental counter infos */
c995fe94
ADG
225 struct {
226 union {
227 struct {
228 BYTE b_ModeRegister1;
229 BYTE b_ModeRegister2;
230 BYTE b_ModeRegister3;
231 BYTE b_ModeRegister4;
232 } s_ByteModeRegister;
233 DWORD dw_ModeRegister1_2_3_4;
234 } s_ModeRegister;
235
236 struct {
237 unsigned int b_IndexInit:1;
238 unsigned int b_CounterInit:1;
239 unsigned int b_ReferenceInit:1;
240 unsigned int b_IndexInterruptOccur:1;
241 unsigned int b_CompareLogicInit:1;
242 unsigned int b_FrequencyMeasurementInit:1;
243 unsigned int b_FrequencyMeasurementEnable:1;
244 } s_InitFlag;
245
246 } s_SiemensCounterInfo;
247
c995fe94 248 /* SSI infos */
c995fe94
ADG
249 struct {
250 BYTE b_SSIProfile;
251 BYTE b_PositionTurnLength;
252 BYTE b_TurnCptLength;
253 BYTE b_SSIInit;
254 } s_SSICounterInfo;
255
c995fe94 256 /* TTL I/O infos */
c995fe94
ADG
257 struct {
258 BYTE b_TTLInit;
259 BYTE b_PortConfiguration[4];
260 } s_TTLIOInfo;
261
c995fe94 262 /* Digital I/O infos */
c995fe94
ADG
263 struct {
264 BYTE b_DigitalInit;
265 BYTE b_ChannelAMode;
266 BYTE b_ChannelBMode;
267 BYTE b_OutputMemoryEnabled;
268 DWORD dw_OutputMemory;
269 } s_DigitalIOInfo;
270
271 /*********************/
272 /* 82X54 timer infos */
273 /*********************/
274
275 struct {
276 struct {
277 BYTE b_82X54Init;
278 BYTE b_InputClockSelection;
279 BYTE b_InputClockLevel;
280 BYTE b_OutputLevel;
281 BYTE b_HardwareGateLevel;
282 DWORD dw_ConfigurationWord;
283 } s_82X54TimerInfo[3];
284 BYTE b_InterruptMask;
285 } s_82X54ModuleInfo;
286
287 /*********************/
288 /* Chronometer infos */
289 /*********************/
290
291 struct {
292 BYTE b_ChronoInit;
293 BYTE b_InterruptMask;
294 BYTE b_PCIInputClock;
295 BYTE b_TimingUnit;
296 BYTE b_CycleMode;
297 double d_TimingInterval;
298 DWORD dw_ConfigReg;
299 } s_ChronoModuleInfo;
300
301 /***********************/
302 /* Pulse encoder infos */
303 /***********************/
304
305 struct {
306 struct {
307 BYTE b_PulseEncoderInit;
308 } s_PulseEncoderInfo[4];
309 DWORD dw_SetRegister;
310 DWORD dw_ControlRegister;
311 DWORD dw_StatusRegister;
312 } s_PulseEncoderModuleInfo;
313
c995fe94 314 /* Tor conter infos */
c995fe94
ADG
315 struct {
316 struct {
317 BYTE b_TorCounterInit;
318 BYTE b_TimingUnit;
319 BYTE b_InterruptEnable;
320 double d_TimingInterval;
321 ULONG ul_RealTimingInterval;
322 } s_TorCounterInfo[2];
323 BYTE b_PCIInputClock;
324 } s_TorCounterModuleInfo;
325
c995fe94 326 /* PWM infos */
c995fe94
ADG
327 struct {
328 struct {
329 BYTE b_PWMInit;
330 BYTE b_TimingUnit;
331 BYTE b_InterruptEnable;
332 double d_LowTiming;
333 double d_HighTiming;
334 ULONG ul_RealLowTiming;
335 ULONG ul_RealHighTiming;
336 } s_PWMInfo[2];
337 BYTE b_ClockSelection;
338 } s_PWMModuleInfo;
339
c995fe94 340 /* ETM infos */
c995fe94
ADG
341 struct {
342 struct {
343 BYTE b_ETMEnable;
344 BYTE b_ETMInterrupt;
345 } s_ETMInfo[2];
346 BYTE b_ETMInit;
347 BYTE b_TimingUnit;
348 BYTE b_ClockSelection;
349 double d_TimingInterval;
350 ULONG ul_Timing;
351 } s_ETMModuleInfo;
352
c995fe94 353 /* CDA infos */
c995fe94
ADG
354 struct {
355 BYTE b_CDAEnable;
356 BYTE b_CDAInterrupt;
357 BYTE b_CDAInit;
358 BYTE b_FctSelection;
359 BYTE b_CDAReadFIFOOverflow;
360 } s_CDAModuleInfo;
361
362} str_ModuleInfo;
c995fe94 363
15d8826a 364/* Private structure for the addi_apci3120 driver */
c995fe94
ADG
365typedef struct {
366
367 INT iobase;
368 INT i_IobaseAmcc; // base+size for AMCC chip
369 INT i_IobaseAddon; //addon base address
370 INT i_IobaseReserved;
371 ULONG_PTR dw_AiBase;
372 struct pcilst_struct *amcc; // ptr too AMCC data
373 BYTE allocated; // we have blocked card
374 BYTE b_ValidDriver; // driver is ok
375 BYTE b_AiContinuous; // we do unlimited AI
376 BYTE b_AiInitialisation;
377 UINT ui_AiActualScan; //how many scans we finished
378 UINT ui_AiBufferPtr; // data buffer ptr in samples
379 UINT ui_AiNbrofChannels; // how many channels is measured
380 UINT ui_AiScanLength; // Length of actual scanlist
381 UINT ui_AiActualScanPosition; // position in actual scan
382 PUINT pui_AiChannelList; // actual chanlist
383 UINT ui_AiChannelList[32]; // actual chanlist
384 BYTE b_AiChannelConfiguration[32]; // actual chanlist
385 UINT ui_AiReadData[32];
386 DWORD dw_AiInitialised;
387 UINT ui_AiTimer0; //Timer Constant for Timer0
388 UINT ui_AiTimer1; //Timer constant for Timer1
389 UINT ui_AiFlags;
390 UINT ui_AiDataLength;
790c5541 391 short *AiData; // Pointer to sample data
c995fe94
ADG
392 UINT ui_AiNbrofScans; // number of scans to do
393 USHORT us_UseDma; // To use Dma or not
394 BYTE b_DmaDoubleBuffer; // we can use double buffering
395 UINT ui_DmaActualBuffer; // which buffer is used now
396 //*UPDATE-0.7.57->0.7.68
397 //ULONG ul_DmaBufferVirtual[2];// pointers to begin of DMA buffer
790c5541 398 short *ul_DmaBufferVirtual[2]; // pointers to begin of DMA buffer
c995fe94
ADG
399 ULONG ul_DmaBufferHw[2]; // hw address of DMA buff
400 UINT ui_DmaBufferSize[2]; // size of dma buffer in bytes
401 UINT ui_DmaBufferUsesize[2]; // which size we may now used for transfer
402 UINT ui_DmaBufferSamples[2]; // size in samples
403 UINT ui_DmaBufferPages[2]; // number of pages in buffer
404 BYTE b_DigitalOutputRegister; // Digital Output Register
405 BYTE b_OutputMemoryStatus;
406 BYTE b_AnalogInputChannelNbr; // Analog input channel Nbr
407 BYTE b_AnalogOutputChannelNbr; // Analog input Output Nbr
408 BYTE b_TimerSelectMode; // Contain data written at iobase + 0C
409 BYTE b_ModeSelectRegister; // Contain data written at iobase + 0E
410 USHORT us_OutputRegister; // Contain data written at iobase + 0
411 BYTE b_InterruptState;
412 BYTE b_TimerInit; // Specify if InitTimerWatchdog was load
413 BYTE b_TimerStarted; // Specify if timer 2 is running or not
414 BYTE b_Timer2Mode; // Specify the timer 2 mode
415 BYTE b_Timer2Interrupt; //Timer2 interrupt enable or disable
416 BYTE b_AiCyclicAcquisition; // indicate cyclic acquisition
417 BYTE b_InterruptMode; // eoc eos or dma
418 BYTE b_EocEosInterrupt; // Enable disable eoc eos interrupt
419 UINT ui_EocEosConversionTime;
420 BYTE b_EocEosConversionTimeBase;
421 BYTE b_SingelDiff;
15d8826a 422 BYTE b_ExttrigEnable; /* To enable or disable external trigger */
c995fe94 423
15d8826a
GKH
424 /* Pointer to the current process */
425 struct task_struct *tsk_Current;
c995fe94
ADG
426 boardtype *ps_BoardInfo;
427
15d8826a 428 /* Hardware board infos for 1710 */
c995fe94 429 struct {
15d8826a 430 UINT ui_Address; /* Board address */
c995fe94 431 UINT ui_FlashAddress;
15d8826a
GKH
432 BYTE b_InterruptNbr; /* Board interrupt number */
433 BYTE b_SlotNumber; /* PCI slot number */
c995fe94 434 BYTE b_BoardVersion;
15d8826a 435 DWORD dw_MolduleConfiguration[4]; /* Module config */
c995fe94
ADG
436 } s_BoardInfos;
437
c995fe94 438 /* Interrupt infos */
c995fe94 439 struct {
15d8826a
GKH
440 ULONG ul_InterruptOccur; /* 0 : No interrupt occur */
441 /* > 0 : Interrupt occur */
442 UINT ui_Read; /* Read FIFO */
443 UINT ui_Write; /* Write FIFO */
c995fe94
ADG
444 struct {
445 BYTE b_OldModuleMask;
15d8826a 446 ULONG ul_OldInterruptMask; /* Interrupt mask */
c995fe94
ADG
447 ULONG ul_OldCounterLatchValue; /* Interrupt counter value */
448 } s_FIFOInterruptParameters[APCI1710_SAVE_INTERRUPT];
449 } s_InterruptParameters;
450
451 str_ModuleInfo s_ModuleInfo[4];
452 ULONG ul_TTLPortConfiguration[10];
453
454} addi_private;
455
15d8826a 456static unsigned short pci_list_builded; /* set to 1 when list of card is known */
c995fe94 457
15d8826a 458/* Function declarations */
0707bb04 459static int i_ADDI_Attach(struct comedi_device *dev, struct comedi_devconfig *it);
71b5f4f1
BP
460static int i_ADDI_Detach(struct comedi_device *dev);
461static int i_ADDI_Reset(struct comedi_device *dev);
c995fe94
ADG
462
463static irqreturn_t v_ADDI_Interrupt(int irq, void *d PT_REGS_ARG);
34c43922 464static int i_ADDIDATA_InsnReadEeprom(struct comedi_device *dev, struct comedi_subdevice *s,
90035c08 465 struct comedi_insn *insn, unsigned int *data);