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