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