1 /* SPDX-License-Identifier: LGPL-2.0+ */ 2 /* 3 * comedi.h 4 * header file for COMEDI user API 5 * 6 * COMEDI - Linux Control and Measurement Device Interface 7 * Copyright (C) 1998-2001 David A. Schleef <ds@schleef.org> 8 */ 9 10 #ifndef _COMEDI_H 11 #define _COMEDI_H 12 13 #define COMEDI_MAJORVERSION 0 14 #define COMEDI_MINORVERSION 7 15 #define COMEDI_MICROVERSION 76 16 #define VERSION "0.7.76" 17 18 /* comedi's major device number */ 19 #define COMEDI_MAJOR 98 20 21 /* 22 * maximum number of minor devices. This can be increased, although 23 * kernel structures are currently statically allocated, thus you 24 * don't want this to be much more than you actually use. 25 */ 26 #define COMEDI_NDEVICES 16 27 28 /* number of config options in the config structure */ 29 #define COMEDI_NDEVCONFOPTS 32 30 31 /* 32 * NOTE: 'comedi_config --init-data' is deprecated 33 * 34 * The following indexes in the config options were used by 35 * comedi_config to pass firmware blobs from user space to the 36 * comedi drivers. The request_firmware() hotplug interface is 37 * now used by all comedi drivers instead. 38 */ 39 40 /* length of nth chunk of firmware data -*/ 41 #define COMEDI_DEVCONF_AUX_DATA3_LENGTH 25 42 #define COMEDI_DEVCONF_AUX_DATA2_LENGTH 26 43 #define COMEDI_DEVCONF_AUX_DATA1_LENGTH 27 44 #define COMEDI_DEVCONF_AUX_DATA0_LENGTH 28 45 /* most significant 32 bits of pointer address (if needed) */ 46 #define COMEDI_DEVCONF_AUX_DATA_HI 29 47 /* least significant 32 bits of pointer address */ 48 #define COMEDI_DEVCONF_AUX_DATA_LO 30 49 #define COMEDI_DEVCONF_AUX_DATA_LENGTH 31 /* total data length */ 50 51 /* max length of device and driver names */ 52 #define COMEDI_NAMELEN 20 53 54 /* packs and unpacks a channel/range number */ 55 56 #define CR_PACK(chan, rng, aref) \ 57 ((((aref) & 0x3) << 24) | (((rng) & 0xff) << 16) | (chan)) 58 #define CR_PACK_FLAGS(chan, range, aref, flags) \ 59 (CR_PACK(chan, range, aref) | ((flags) & CR_FLAGS_MASK)) 60 61 #define CR_CHAN(a) ((a) & 0xffff) 62 #define CR_RANGE(a) (((a) >> 16) & 0xff) 63 #define CR_AREF(a) (((a) >> 24) & 0x03) 64 65 #define CR_FLAGS_MASK 0xfc000000 66 #define CR_ALT_FILTER 0x04000000 67 #define CR_DITHER CR_ALT_FILTER 68 #define CR_DEGLITCH CR_ALT_FILTER 69 #define CR_ALT_SOURCE 0x08000000 70 #define CR_EDGE 0x40000000 71 #define CR_INVERT 0x80000000 72 73 #define AREF_GROUND 0x00 /* analog ref = analog ground */ 74 #define AREF_COMMON 0x01 /* analog ref = analog common */ 75 #define AREF_DIFF 0x02 /* analog ref = differential */ 76 #define AREF_OTHER 0x03 /* analog ref = other (undefined) */ 77 78 /* counters -- these are arbitrary values */ 79 #define GPCT_RESET 0x0001 80 #define GPCT_SET_SOURCE 0x0002 81 #define GPCT_SET_GATE 0x0004 82 #define GPCT_SET_DIRECTION 0x0008 83 #define GPCT_SET_OPERATION 0x0010 84 #define GPCT_ARM 0x0020 85 #define GPCT_DISARM 0x0040 86 #define GPCT_GET_INT_CLK_FRQ 0x0080 87 88 #define GPCT_INT_CLOCK 0x0001 89 #define GPCT_EXT_PIN 0x0002 90 #define GPCT_NO_GATE 0x0004 91 #define GPCT_UP 0x0008 92 #define GPCT_DOWN 0x0010 93 #define GPCT_HWUD 0x0020 94 #define GPCT_SIMPLE_EVENT 0x0040 95 #define GPCT_SINGLE_PERIOD 0x0080 96 #define GPCT_SINGLE_PW 0x0100 97 #define GPCT_CONT_PULSE_OUT 0x0200 98 #define GPCT_SINGLE_PULSE_OUT 0x0400 99 100 /* instructions */ 101 102 #define INSN_MASK_WRITE 0x8000000 103 #define INSN_MASK_READ 0x4000000 104 #define INSN_MASK_SPECIAL 0x2000000 105 106 #define INSN_READ (0 | INSN_MASK_READ) 107 #define INSN_WRITE (1 | INSN_MASK_WRITE) 108 #define INSN_BITS (2 | INSN_MASK_READ | INSN_MASK_WRITE) 109 #define INSN_CONFIG (3 | INSN_MASK_READ | INSN_MASK_WRITE) 110 #define INSN_GTOD (4 | INSN_MASK_READ | INSN_MASK_SPECIAL) 111 #define INSN_WAIT (5 | INSN_MASK_WRITE | INSN_MASK_SPECIAL) 112 #define INSN_INTTRIG (6 | INSN_MASK_WRITE | INSN_MASK_SPECIAL) 113 114 /* command flags */ 115 /* These flags are used in comedi_cmd structures */ 116 117 #define CMDF_BOGUS 0x00000001 /* do the motions */ 118 119 /* try to use a real-time interrupt while performing command */ 120 #define CMDF_PRIORITY 0x00000008 121 122 /* wake up on end-of-scan events */ 123 #define CMDF_WAKE_EOS 0x00000020 124 125 #define CMDF_WRITE 0x00000040 126 127 #define CMDF_RAWDATA 0x00000080 128 129 /* timer rounding definitions */ 130 #define CMDF_ROUND_MASK 0x00030000 131 #define CMDF_ROUND_NEAREST 0x00000000 132 #define CMDF_ROUND_DOWN 0x00010000 133 #define CMDF_ROUND_UP 0x00020000 134 #define CMDF_ROUND_UP_NEXT 0x00030000 135 136 #define COMEDI_EV_START 0x00040000 137 #define COMEDI_EV_SCAN_BEGIN 0x00080000 138 #define COMEDI_EV_CONVERT 0x00100000 139 #define COMEDI_EV_SCAN_END 0x00200000 140 #define COMEDI_EV_STOP 0x00400000 141 142 /* compatibility definitions */ 143 #define TRIG_BOGUS CMDF_BOGUS 144 #define TRIG_RT CMDF_PRIORITY 145 #define TRIG_WAKE_EOS CMDF_WAKE_EOS 146 #define TRIG_WRITE CMDF_WRITE 147 #define TRIG_ROUND_MASK CMDF_ROUND_MASK 148 #define TRIG_ROUND_NEAREST CMDF_ROUND_NEAREST 149 #define TRIG_ROUND_DOWN CMDF_ROUND_DOWN 150 #define TRIG_ROUND_UP CMDF_ROUND_UP 151 #define TRIG_ROUND_UP_NEXT CMDF_ROUND_UP_NEXT 152 153 /* trigger sources */ 154 155 #define TRIG_ANY 0xffffffff 156 #define TRIG_INVALID 0x00000000 157 158 #define TRIG_NONE 0x00000001 /* never trigger */ 159 #define TRIG_NOW 0x00000002 /* trigger now + N ns */ 160 #define TRIG_FOLLOW 0x00000004 /* trigger on next lower level trig */ 161 #define TRIG_TIME 0x00000008 /* trigger at time N ns */ 162 #define TRIG_TIMER 0x00000010 /* trigger at rate N ns */ 163 #define TRIG_COUNT 0x00000020 /* trigger when count reaches N */ 164 #define TRIG_EXT 0x00000040 /* trigger on external signal N */ 165 #define TRIG_INT 0x00000080 /* trigger on comedi-internal signal N */ 166 #define TRIG_OTHER 0x00000100 /* driver defined */ 167 168 /* subdevice flags */ 169 170 #define SDF_BUSY 0x0001 /* device is busy */ 171 #define SDF_BUSY_OWNER 0x0002 /* device is busy with your job */ 172 #define SDF_LOCKED 0x0004 /* subdevice is locked */ 173 #define SDF_LOCK_OWNER 0x0008 /* you own lock */ 174 #define SDF_MAXDATA 0x0010 /* maxdata depends on channel */ 175 #define SDF_FLAGS 0x0020 /* flags depend on channel */ 176 #define SDF_RANGETYPE 0x0040 /* range type depends on channel */ 177 #define SDF_PWM_COUNTER 0x0080 /* PWM can automatically switch off */ 178 #define SDF_PWM_HBRIDGE 0x0100 /* PWM is signed (H-bridge) */ 179 #define SDF_CMD 0x1000 /* can do commands (deprecated) */ 180 #define SDF_SOFT_CALIBRATED 0x2000 /* subdevice uses software calibration */ 181 #define SDF_CMD_WRITE 0x4000 /* can do output commands */ 182 #define SDF_CMD_READ 0x8000 /* can do input commands */ 183 184 /* subdevice can be read (e.g. analog input) */ 185 #define SDF_READABLE 0x00010000 186 /* subdevice can be written (e.g. analog output) */ 187 #define SDF_WRITABLE 0x00020000 188 #define SDF_WRITEABLE SDF_WRITABLE /* spelling error in API */ 189 /* subdevice does not have externally visible lines */ 190 #define SDF_INTERNAL 0x00040000 191 #define SDF_GROUND 0x00100000 /* can do aref=ground */ 192 #define SDF_COMMON 0x00200000 /* can do aref=common */ 193 #define SDF_DIFF 0x00400000 /* can do aref=diff */ 194 #define SDF_OTHER 0x00800000 /* can do aref=other */ 195 #define SDF_DITHER 0x01000000 /* can do dithering */ 196 #define SDF_DEGLITCH 0x02000000 /* can do deglitching */ 197 #define SDF_MMAP 0x04000000 /* can do mmap() */ 198 #define SDF_RUNNING 0x08000000 /* subdevice is acquiring data */ 199 #define SDF_LSAMPL 0x10000000 /* subdevice uses 32-bit samples */ 200 #define SDF_PACKED 0x20000000 /* subdevice can do packed DIO */ 201 202 /* subdevice types */ 203 204 /** 205 * enum comedi_subdevice_type - COMEDI subdevice types 206 * @COMEDI_SUBD_UNUSED: Unused subdevice. 207 * @COMEDI_SUBD_AI: Analog input. 208 * @COMEDI_SUBD_AO: Analog output. 209 * @COMEDI_SUBD_DI: Digital input. 210 * @COMEDI_SUBD_DO: Digital output. 211 * @COMEDI_SUBD_DIO: Digital input/output. 212 * @COMEDI_SUBD_COUNTER: Counter. 213 * @COMEDI_SUBD_TIMER: Timer. 214 * @COMEDI_SUBD_MEMORY: Memory, EEPROM, DPRAM. 215 * @COMEDI_SUBD_CALIB: Calibration DACs. 216 * @COMEDI_SUBD_PROC: Processor, DSP. 217 * @COMEDI_SUBD_SERIAL: Serial I/O. 218 * @COMEDI_SUBD_PWM: Pulse-Width Modulation output. 219 */ 220 enum comedi_subdevice_type { 221 COMEDI_SUBD_UNUSED, 222 COMEDI_SUBD_AI, 223 COMEDI_SUBD_AO, 224 COMEDI_SUBD_DI, 225 COMEDI_SUBD_DO, 226 COMEDI_SUBD_DIO, 227 COMEDI_SUBD_COUNTER, 228 COMEDI_SUBD_TIMER, 229 COMEDI_SUBD_MEMORY, 230 COMEDI_SUBD_CALIB, 231 COMEDI_SUBD_PROC, 232 COMEDI_SUBD_SERIAL, 233 COMEDI_SUBD_PWM 234 }; 235 236 /* configuration instructions */ 237 238 /** 239 * enum comedi_io_direction - COMEDI I/O directions 240 * @COMEDI_INPUT: Input. 241 * @COMEDI_OUTPUT: Output. 242 * @COMEDI_OPENDRAIN: Open-drain (or open-collector) output. 243 * 244 * These are used by the %INSN_CONFIG_DIO_QUERY configuration instruction to 245 * report a direction. They may also be used in other places where a direction 246 * needs to be specified. 247 */ 248 enum comedi_io_direction { 249 COMEDI_INPUT = 0, 250 COMEDI_OUTPUT = 1, 251 COMEDI_OPENDRAIN = 2 252 }; 253 254 /** 255 * enum configuration_ids - COMEDI configuration instruction codes 256 * @INSN_CONFIG_DIO_INPUT: Configure digital I/O as input. 257 * @INSN_CONFIG_DIO_OUTPUT: Configure digital I/O as output. 258 * @INSN_CONFIG_DIO_OPENDRAIN: Configure digital I/O as open-drain (or open 259 * collector) output. 260 * @INSN_CONFIG_ANALOG_TRIG: Configure analog trigger. 261 * @INSN_CONFIG_ALT_SOURCE: Configure alternate input source. 262 * @INSN_CONFIG_DIGITAL_TRIG: Configure digital trigger. 263 * @INSN_CONFIG_BLOCK_SIZE: Configure block size for DMA transfers. 264 * @INSN_CONFIG_TIMER_1: Configure divisor for external clock. 265 * @INSN_CONFIG_FILTER: Configure a filter. 266 * @INSN_CONFIG_CHANGE_NOTIFY: Configure change notification for digital 267 * inputs. (New drivers should use 268 * %INSN_CONFIG_DIGITAL_TRIG instead.) 269 * @INSN_CONFIG_SERIAL_CLOCK: Configure clock for serial I/O. 270 * @INSN_CONFIG_BIDIRECTIONAL_DATA: Send and receive byte over serial I/O. 271 * @INSN_CONFIG_DIO_QUERY: Query direction of digital I/O channel. 272 * @INSN_CONFIG_PWM_OUTPUT: Configure pulse-width modulator output. 273 * @INSN_CONFIG_GET_PWM_OUTPUT: Get pulse-width modulator output configuration. 274 * @INSN_CONFIG_ARM: Arm a subdevice or channel. 275 * @INSN_CONFIG_DISARM: Disarm a subdevice or channel. 276 * @INSN_CONFIG_GET_COUNTER_STATUS: Get counter status. 277 * @INSN_CONFIG_RESET: Reset a subdevice or channel. 278 * @INSN_CONFIG_GPCT_SINGLE_PULSE_GENERATOR: Configure counter/timer as 279 * single pulse generator. 280 * @INSN_CONFIG_GPCT_PULSE_TRAIN_GENERATOR: Configure counter/timer as 281 * pulse train generator. 282 * @INSN_CONFIG_GPCT_QUADRATURE_ENCODER: Configure counter as a quadrature 283 * encoder. 284 * @INSN_CONFIG_SET_GATE_SRC: Set counter/timer gate source. 285 * @INSN_CONFIG_GET_GATE_SRC: Get counter/timer gate source. 286 * @INSN_CONFIG_SET_CLOCK_SRC: Set counter/timer master clock source. 287 * @INSN_CONFIG_GET_CLOCK_SRC: Get counter/timer master clock source. 288 * @INSN_CONFIG_SET_OTHER_SRC: Set counter/timer "other" source. 289 * @INSN_CONFIG_GET_HARDWARE_BUFFER_SIZE: Get size (in bytes) of subdevice's 290 * on-board FIFOs used during streaming 291 * input/output. 292 * @INSN_CONFIG_SET_COUNTER_MODE: Set counter/timer mode. 293 * @INSN_CONFIG_8254_SET_MODE: (Deprecated) Same as 294 * %INSN_CONFIG_SET_COUNTER_MODE. 295 * @INSN_CONFIG_8254_READ_STATUS: Read status of 8254 counter channel. 296 * @INSN_CONFIG_SET_ROUTING: Set routing for a channel. 297 * @INSN_CONFIG_GET_ROUTING: Get routing for a channel. 298 * @INSN_CONFIG_PWM_SET_PERIOD: Set PWM period in nanoseconds. 299 * @INSN_CONFIG_PWM_GET_PERIOD: Get PWM period in nanoseconds. 300 * @INSN_CONFIG_GET_PWM_STATUS: Get PWM status. 301 * @INSN_CONFIG_PWM_SET_H_BRIDGE: Set PWM H bridge duty cycle and polarity for 302 * a relay simultaneously. 303 * @INSN_CONFIG_PWM_GET_H_BRIDGE: Get PWM H bridge duty cycle and polarity. 304 */ 305 enum configuration_ids { 306 INSN_CONFIG_DIO_INPUT = COMEDI_INPUT, 307 INSN_CONFIG_DIO_OUTPUT = COMEDI_OUTPUT, 308 INSN_CONFIG_DIO_OPENDRAIN = COMEDI_OPENDRAIN, 309 INSN_CONFIG_ANALOG_TRIG = 16, 310 /* INSN_CONFIG_WAVEFORM = 17, */ 311 /* INSN_CONFIG_TRIG = 18, */ 312 /* INSN_CONFIG_COUNTER = 19, */ 313 INSN_CONFIG_ALT_SOURCE = 20, 314 INSN_CONFIG_DIGITAL_TRIG = 21, 315 INSN_CONFIG_BLOCK_SIZE = 22, 316 INSN_CONFIG_TIMER_1 = 23, 317 INSN_CONFIG_FILTER = 24, 318 INSN_CONFIG_CHANGE_NOTIFY = 25, 319 320 INSN_CONFIG_SERIAL_CLOCK = 26, /*ALPHA*/ 321 INSN_CONFIG_BIDIRECTIONAL_DATA = 27, 322 INSN_CONFIG_DIO_QUERY = 28, 323 INSN_CONFIG_PWM_OUTPUT = 29, 324 INSN_CONFIG_GET_PWM_OUTPUT = 30, 325 INSN_CONFIG_ARM = 31, 326 INSN_CONFIG_DISARM = 32, 327 INSN_CONFIG_GET_COUNTER_STATUS = 33, 328 INSN_CONFIG_RESET = 34, 329 INSN_CONFIG_GPCT_SINGLE_PULSE_GENERATOR = 1001, 330 INSN_CONFIG_GPCT_PULSE_TRAIN_GENERATOR = 1002, 331 INSN_CONFIG_GPCT_QUADRATURE_ENCODER = 1003, 332 INSN_CONFIG_SET_GATE_SRC = 2001, 333 INSN_CONFIG_GET_GATE_SRC = 2002, 334 INSN_CONFIG_SET_CLOCK_SRC = 2003, 335 INSN_CONFIG_GET_CLOCK_SRC = 2004, 336 INSN_CONFIG_SET_OTHER_SRC = 2005, 337 INSN_CONFIG_GET_HARDWARE_BUFFER_SIZE = 2006, 338 INSN_CONFIG_SET_COUNTER_MODE = 4097, 339 INSN_CONFIG_8254_SET_MODE = INSN_CONFIG_SET_COUNTER_MODE, 340 INSN_CONFIG_8254_READ_STATUS = 4098, 341 INSN_CONFIG_SET_ROUTING = 4099, 342 INSN_CONFIG_GET_ROUTING = 4109, 343 INSN_CONFIG_PWM_SET_PERIOD = 5000, 344 INSN_CONFIG_PWM_GET_PERIOD = 5001, 345 INSN_CONFIG_GET_PWM_STATUS = 5002, 346 INSN_CONFIG_PWM_SET_H_BRIDGE = 5003, 347 INSN_CONFIG_PWM_GET_H_BRIDGE = 5004 348 }; 349 350 /** 351 * enum comedi_digital_trig_op - operations for configuring a digital trigger 352 * @COMEDI_DIGITAL_TRIG_DISABLE: Return digital trigger to its default, 353 * inactive, unconfigured state. 354 * @COMEDI_DIGITAL_TRIG_ENABLE_EDGES: Set rising and/or falling edge inputs 355 * that each can fire the trigger. 356 * @COMEDI_DIGITAL_TRIG_ENABLE_LEVELS: Set a combination of high and/or low 357 * level inputs that can fire the trigger. 358 * 359 * These are used with the %INSN_CONFIG_DIGITAL_TRIG configuration instruction. 360 * The data for the configuration instruction is as follows... 361 * 362 * data[%0] = %INSN_CONFIG_DIGITAL_TRIG 363 * 364 * data[%1] = trigger ID 365 * 366 * data[%2] = configuration operation 367 * 368 * data[%3] = configuration parameter 1 369 * 370 * data[%4] = configuration parameter 2 371 * 372 * data[%5] = configuration parameter 3 373 * 374 * The trigger ID (data[%1]) is used to differentiate multiple digital triggers 375 * belonging to the same subdevice. The configuration operation (data[%2]) is 376 * one of the enum comedi_digital_trig_op values. The configuration 377 * parameters (data[%3], data[%4], and data[%5]) depend on the operation; they 378 * are not used with %COMEDI_DIGITAL_TRIG_DISABLE. 379 * 380 * For %COMEDI_DIGITAL_TRIG_ENABLE_EDGES and %COMEDI_DIGITAL_TRIG_ENABLE_LEVELS, 381 * configuration parameter 1 (data[%3]) contains a "left-shift" value that 382 * specifies the input corresponding to bit 0 of configuration parameters 2 383 * and 3. This is useful if the trigger has more than 32 inputs. 384 * 385 * For %COMEDI_DIGITAL_TRIG_ENABLE_EDGES, configuration parameter 2 (data[%4]) 386 * specifies which of up to 32 inputs have rising-edge sensitivity, and 387 * configuration parameter 3 (data[%5]) specifies which of up to 32 inputs 388 * have falling-edge sensitivity that can fire the trigger. 389 * 390 * For %COMEDI_DIGITAL_TRIG_ENABLE_LEVELS, configuration parameter 2 (data[%4]) 391 * specifies which of up to 32 inputs must be at a high level, and 392 * configuration parameter 3 (data[%5]) specifies which of up to 32 inputs 393 * must be at a low level for the trigger to fire. 394 * 395 * Some sequences of %INSN_CONFIG_DIGITAL_TRIG instructions may have a (partly) 396 * accumulative effect, depending on the low-level driver. This is useful 397 * when setting up a trigger that has more than 32 inputs, or has a combination 398 * of edge- and level-triggered inputs. 399 */ 400 enum comedi_digital_trig_op { 401 COMEDI_DIGITAL_TRIG_DISABLE = 0, 402 COMEDI_DIGITAL_TRIG_ENABLE_EDGES = 1, 403 COMEDI_DIGITAL_TRIG_ENABLE_LEVELS = 2 404 }; 405 406 /** 407 * enum comedi_support_level - support level for a COMEDI feature 408 * @COMEDI_UNKNOWN_SUPPORT: Unspecified support for feature. 409 * @COMEDI_SUPPORTED: Feature is supported. 410 * @COMEDI_UNSUPPORTED: Feature is unsupported. 411 */ 412 enum comedi_support_level { 413 COMEDI_UNKNOWN_SUPPORT = 0, 414 COMEDI_SUPPORTED, 415 COMEDI_UNSUPPORTED 416 }; 417 418 /** 419 * enum comedi_counter_status_flags - counter status bits 420 * @COMEDI_COUNTER_ARMED: Counter is armed. 421 * @COMEDI_COUNTER_COUNTING: Counter is counting. 422 * @COMEDI_COUNTER_TERMINAL_COUNT: Counter reached terminal count. 423 * 424 * These bitwise values are used by the %INSN_CONFIG_GET_COUNTER_STATUS 425 * configuration instruction to report the status of a counter. 426 */ 427 enum comedi_counter_status_flags { 428 COMEDI_COUNTER_ARMED = 0x1, 429 COMEDI_COUNTER_COUNTING = 0x2, 430 COMEDI_COUNTER_TERMINAL_COUNT = 0x4, 431 }; 432 433 /* ioctls */ 434 435 #define CIO 'd' 436 #define COMEDI_DEVCONFIG _IOW(CIO, 0, struct comedi_devconfig) 437 #define COMEDI_DEVINFO _IOR(CIO, 1, struct comedi_devinfo) 438 #define COMEDI_SUBDINFO _IOR(CIO, 2, struct comedi_subdinfo) 439 #define COMEDI_CHANINFO _IOR(CIO, 3, struct comedi_chaninfo) 440 /* _IOWR(CIO, 4, ...) is reserved */ 441 #define COMEDI_LOCK _IO(CIO, 5) 442 #define COMEDI_UNLOCK _IO(CIO, 6) 443 #define COMEDI_CANCEL _IO(CIO, 7) 444 #define COMEDI_RANGEINFO _IOR(CIO, 8, struct comedi_rangeinfo) 445 #define COMEDI_CMD _IOR(CIO, 9, struct comedi_cmd) 446 #define COMEDI_CMDTEST _IOR(CIO, 10, struct comedi_cmd) 447 #define COMEDI_INSNLIST _IOR(CIO, 11, struct comedi_insnlist) 448 #define COMEDI_INSN _IOR(CIO, 12, struct comedi_insn) 449 #define COMEDI_BUFCONFIG _IOR(CIO, 13, struct comedi_bufconfig) 450 #define COMEDI_BUFINFO _IOWR(CIO, 14, struct comedi_bufinfo) 451 #define COMEDI_POLL _IO(CIO, 15) 452 #define COMEDI_SETRSUBD _IO(CIO, 16) 453 #define COMEDI_SETWSUBD _IO(CIO, 17) 454 455 /* structures */ 456 457 /** 458 * struct comedi_insn - COMEDI instruction 459 * @insn: COMEDI instruction type (%INSN_xxx). 460 * @n: Length of @data[]. 461 * @data: Pointer to data array operated on by the instruction. 462 * @subdev: Subdevice index. 463 * @chanspec: A packed "chanspec" value consisting of channel number, 464 * analog range index, analog reference type, and flags. 465 * @unused: Reserved for future use. 466 * 467 * This is used with the %COMEDI_INSN ioctl, and indirectly with the 468 * %COMEDI_INSNLIST ioctl. 469 */ 470 struct comedi_insn { 471 unsigned int insn; 472 unsigned int n; 473 unsigned int __user *data; 474 unsigned int subdev; 475 unsigned int chanspec; 476 unsigned int unused[3]; 477 }; 478 479 /** 480 * struct comedi_insnlist - list of COMEDI instructions 481 * @n_insns: Number of COMEDI instructions. 482 * @insns: Pointer to array COMEDI instructions. 483 * 484 * This is used with the %COMEDI_INSNLIST ioctl. 485 */ 486 struct comedi_insnlist { 487 unsigned int n_insns; 488 struct comedi_insn __user *insns; 489 }; 490 491 /** 492 * struct comedi_cmd - COMEDI asynchronous acquisition command details 493 * @subdev: Subdevice index. 494 * @flags: Command flags (%CMDF_xxx). 495 * @start_src: "Start acquisition" trigger source (%TRIG_xxx). 496 * @start_arg: "Start acquisition" trigger argument. 497 * @scan_begin_src: "Scan begin" trigger source. 498 * @scan_begin_arg: "Scan begin" trigger argument. 499 * @convert_src: "Convert" trigger source. 500 * @convert_arg: "Convert" trigger argument. 501 * @scan_end_src: "Scan end" trigger source. 502 * @scan_end_arg: "Scan end" trigger argument. 503 * @stop_src: "Stop acquisition" trigger source. 504 * @stop_arg: "Stop acquisition" trigger argument. 505 * @chanlist: Pointer to array of "chanspec" values, containing a 506 * sequence of channel numbers packed with analog range 507 * index, etc. 508 * @chanlist_len: Number of channels in sequence. 509 * @data: Pointer to miscellaneous set-up data (not used). 510 * @data_len: Length of miscellaneous set-up data. 511 * 512 * This is used with the %COMEDI_CMD or %COMEDI_CMDTEST ioctl to set-up 513 * or validate an asynchronous acquisition command. The ioctl may modify 514 * the &struct comedi_cmd and copy it back to the caller. 515 * 516 * Optional command @flags values that can be ORed together... 517 * 518 * %CMDF_BOGUS - makes %COMEDI_CMD ioctl return error %EAGAIN instead of 519 * starting the command. 520 * 521 * %CMDF_PRIORITY - requests "hard real-time" processing (which is not 522 * supported in this version of COMEDI). 523 * 524 * %CMDF_WAKE_EOS - requests the command makes data available for reading 525 * after every "scan" period. 526 * 527 * %CMDF_WRITE - marks the command as being in the "write" (to device) 528 * direction. This does not need to be specified by the caller unless the 529 * subdevice supports commands in either direction. 530 * 531 * %CMDF_RAWDATA - prevents the command from "munging" the data between the 532 * COMEDI sample format and the raw hardware sample format. 533 * 534 * %CMDF_ROUND_NEAREST - requests timing periods to be rounded to nearest 535 * supported values. 536 * 537 * %CMDF_ROUND_DOWN - requests timing periods to be rounded down to supported 538 * values (frequencies rounded up). 539 * 540 * %CMDF_ROUND_UP - requests timing periods to be rounded up to supported 541 * values (frequencies rounded down). 542 * 543 * Trigger source values for @start_src, @scan_begin_src, @convert_src, 544 * @scan_end_src, and @stop_src... 545 * 546 * %TRIG_ANY - "all ones" value used to test which trigger sources are 547 * supported. 548 * 549 * %TRIG_INVALID - "all zeroes" value used to indicate that all requested 550 * trigger sources are invalid. 551 * 552 * %TRIG_NONE - never trigger (often used as a @stop_src value). 553 * 554 * %TRIG_NOW - trigger after '_arg' nanoseconds. 555 * 556 * %TRIG_FOLLOW - trigger follows another event. 557 * 558 * %TRIG_TIMER - trigger every '_arg' nanoseconds. 559 * 560 * %TRIG_COUNT - trigger when count '_arg' is reached. 561 * 562 * %TRIG_EXT - trigger on external signal specified by '_arg'. 563 * 564 * %TRIG_INT - trigger on internal, software trigger specified by '_arg'. 565 * 566 * %TRIG_OTHER - trigger on other, driver-defined signal specified by '_arg'. 567 */ 568 struct comedi_cmd { 569 unsigned int subdev; 570 unsigned int flags; 571 572 unsigned int start_src; 573 unsigned int start_arg; 574 575 unsigned int scan_begin_src; 576 unsigned int scan_begin_arg; 577 578 unsigned int convert_src; 579 unsigned int convert_arg; 580 581 unsigned int scan_end_src; 582 unsigned int scan_end_arg; 583 584 unsigned int stop_src; 585 unsigned int stop_arg; 586 587 unsigned int *chanlist; 588 unsigned int chanlist_len; 589 590 short __user *data; 591 unsigned int data_len; 592 }; 593 594 /** 595 * struct comedi_chaninfo - used to retrieve per-channel information 596 * @subdev: Subdevice index. 597 * @maxdata_list: Optional pointer to per-channel maximum data values. 598 * @flaglist: Optional pointer to per-channel flags. 599 * @rangelist: Optional pointer to per-channel range types. 600 * @unused: Reserved for future use. 601 * 602 * This is used with the %COMEDI_CHANINFO ioctl to get per-channel information 603 * for the subdevice. Use of this requires knowledge of the number of channels 604 * and subdevice flags obtained using the %COMEDI_SUBDINFO ioctl. 605 * 606 * The @maxdata_list member must be %NULL unless the %SDF_MAXDATA subdevice 607 * flag is set. The @flaglist member must be %NULL unless the %SDF_FLAGS 608 * subdevice flag is set. The @rangelist member must be %NULL unless the 609 * %SDF_RANGETYPE subdevice flag is set. Otherwise, the arrays they point to 610 * must be at least as long as the number of channels. 611 */ 612 struct comedi_chaninfo { 613 unsigned int subdev; 614 unsigned int __user *maxdata_list; 615 unsigned int __user *flaglist; 616 unsigned int __user *rangelist; 617 unsigned int unused[4]; 618 }; 619 620 /** 621 * struct comedi_rangeinfo - used to retrieve the range table for a channel 622 * @range_type: Encodes subdevice index (bits 27:24), channel index 623 * (bits 23:16) and range table length (bits 15:0). 624 * @range_ptr: Pointer to array of @struct comedi_krange to be filled 625 * in with the range table for the channel or subdevice. 626 * 627 * This is used with the %COMEDI_RANGEINFO ioctl to retrieve the range table 628 * for a specific channel (if the subdevice has the %SDF_RANGETYPE flag set to 629 * indicate that the range table depends on the channel), or for the subdevice 630 * as a whole (if the %SDF_RANGETYPE flag is clear, indicating the range table 631 * is shared by all channels). 632 * 633 * The @range_type value is an input to the ioctl and comes from a previous 634 * use of the %COMEDI_SUBDINFO ioctl (if the %SDF_RANGETYPE flag is clear), 635 * or the %COMEDI_CHANINFO ioctl (if the %SDF_RANGETYPE flag is set). 636 */ 637 struct comedi_rangeinfo { 638 unsigned int range_type; 639 void __user *range_ptr; 640 }; 641 642 /** 643 * struct comedi_krange - describes a range in a range table 644 * @min: Minimum value in millionths (1e-6) of a unit. 645 * @max: Maximum value in millionths (1e-6) of a unit. 646 * @flags: Indicates the units (in bits 7:0) OR'ed with optional flags. 647 * 648 * A range table is associated with a single channel, or with all channels in a 649 * subdevice, and a list of one or more ranges. A %struct comedi_krange 650 * describes the physical range of units for one of those ranges. Sample 651 * values in COMEDI are unsigned from %0 up to some 'maxdata' value. The 652 * mapping from sample values to physical units is assumed to be nomimally 653 * linear (for the purpose of describing the range), with sample value %0 654 * mapping to @min, and the 'maxdata' sample value mapping to @max. 655 * 656 * The currently defined units are %UNIT_volt (%0), %UNIT_mA (%1), and 657 * %UNIT_none (%2). The @min and @max values are the physical range multiplied 658 * by 1e6, so a @max value of %1000000 (with %UNIT_volt) represents a maximal 659 * value of 1 volt. 660 * 661 * The only defined flag value is %RF_EXTERNAL (%0x100), indicating that the 662 * the range needs to be multiplied by an external reference. 663 */ 664 struct comedi_krange { 665 int min; 666 int max; 667 unsigned int flags; 668 }; 669 670 /** 671 * struct comedi_subdinfo - used to retrieve information about a subdevice 672 * @type: Type of subdevice from &enum comedi_subdevice_type. 673 * @n_chan: Number of channels the subdevice supports. 674 * @subd_flags: A mixture of static and dynamic flags describing 675 * aspects of the subdevice and its current state. 676 * @timer_type: Timer type. Always set to %5 ("nanosecond timer"). 677 * @len_chanlist: Maximum length of a channel list if the subdevice 678 * supports asynchronous acquisition commands. 679 * @maxdata: Maximum sample value for all channels if the 680 * %SDF_MAXDATA subdevice flag is clear. 681 * @flags: Channel flags for all channels if the %SDF_FLAGS 682 * subdevice flag is clear. 683 * @range_type: The range type for all channels if the %SDF_RANGETYPE 684 * subdevice flag is clear. Encodes the subdevice index 685 * (bits 27:24), a dummy channel index %0 (bits 23:16), 686 * and the range table length (bits 15:0). 687 * @settling_time_0: Not used. 688 * @insn_bits_support: Set to %COMEDI_SUPPORTED if the subdevice supports the 689 * %INSN_BITS instruction, or to %COMEDI_UNSUPPORTED if it 690 * does not. 691 * @unused: Reserved for future use. 692 * 693 * This is used with the %COMEDI_SUBDINFO ioctl which copies an array of 694 * &struct comedi_subdinfo back to user space, with one element per subdevice. 695 * Use of this requires knowledge of the number of subdevices obtained from 696 * the %COMEDI_DEVINFO ioctl. 697 * 698 * These are the @subd_flags values that may be ORed together... 699 * 700 * %SDF_BUSY - the subdevice is busy processing an asynchronous command or a 701 * synchronous instruction. 702 * 703 * %SDF_BUSY_OWNER - the subdevice is busy processing an asynchronous 704 * acquisition command started on the current file object (the file object 705 * issuing the %COMEDI_SUBDINFO ioctl). 706 * 707 * %SDF_LOCKED - the subdevice is locked by a %COMEDI_LOCK ioctl. 708 * 709 * %SDF_LOCK_OWNER - the subdevice is locked by a %COMEDI_LOCK ioctl from the 710 * current file object. 711 * 712 * %SDF_MAXDATA - maximum sample values are channel-specific. 713 * 714 * %SDF_FLAGS - channel flags are channel-specific. 715 * 716 * %SDF_RANGETYPE - range types are channel-specific. 717 * 718 * %SDF_PWM_COUNTER - PWM can switch off automatically. 719 * 720 * %SDF_PWM_HBRIDGE - or PWM is signed (H-bridge). 721 * 722 * %SDF_CMD - the subdevice supports asynchronous commands. 723 * 724 * %SDF_SOFT_CALIBRATED - the subdevice uses software calibration. 725 * 726 * %SDF_CMD_WRITE - the subdevice supports asynchronous commands in the output 727 * ("write") direction. 728 * 729 * %SDF_CMD_READ - the subdevice supports asynchronous commands in the input 730 * ("read") direction. 731 * 732 * %SDF_READABLE - the subdevice is readable (e.g. analog input). 733 * 734 * %SDF_WRITABLE (aliased as %SDF_WRITEABLE) - the subdevice is writable (e.g. 735 * analog output). 736 * 737 * %SDF_INTERNAL - the subdevice has no externally visible lines. 738 * 739 * %SDF_GROUND - the subdevice can use ground as an analog reference. 740 * 741 * %SDF_COMMON - the subdevice can use a common analog reference. 742 * 743 * %SDF_DIFF - the subdevice can use differential inputs (or outputs). 744 * 745 * %SDF_OTHER - the subdevice can use some other analog reference. 746 * 747 * %SDF_DITHER - the subdevice can do dithering. 748 * 749 * %SDF_DEGLITCH - the subdevice can do deglitching. 750 * 751 * %SDF_MMAP - this is never set. 752 * 753 * %SDF_RUNNING - an asynchronous command is still running. 754 * 755 * %SDF_LSAMPL - the subdevice uses "long" (32-bit) samples (for asynchronous 756 * command data). 757 * 758 * %SDF_PACKED - the subdevice packs several DIO samples into a single sample 759 * (for asynchronous command data). 760 * 761 * No "channel flags" (@flags) values are currently defined. 762 */ 763 struct comedi_subdinfo { 764 unsigned int type; 765 unsigned int n_chan; 766 unsigned int subd_flags; 767 unsigned int timer_type; 768 unsigned int len_chanlist; 769 unsigned int maxdata; 770 unsigned int flags; 771 unsigned int range_type; 772 unsigned int settling_time_0; 773 unsigned int insn_bits_support; 774 unsigned int unused[8]; 775 }; 776 777 /** 778 * struct comedi_devinfo - used to retrieve information about a COMEDI device 779 * @version_code: COMEDI version code. 780 * @n_subdevs: Number of subdevices the device has. 781 * @driver_name: Null-terminated COMEDI driver name. 782 * @board_name: Null-terminated COMEDI board name. 783 * @read_subdevice: Index of the current "read" subdevice (%-1 if none). 784 * @write_subdevice: Index of the current "write" subdevice (%-1 if none). 785 * @unused: Reserved for future use. 786 * 787 * This is used with the %COMEDI_DEVINFO ioctl to get basic information about 788 * the device. 789 */ 790 struct comedi_devinfo { 791 unsigned int version_code; 792 unsigned int n_subdevs; 793 char driver_name[COMEDI_NAMELEN]; 794 char board_name[COMEDI_NAMELEN]; 795 int read_subdevice; 796 int write_subdevice; 797 int unused[30]; 798 }; 799 800 /** 801 * struct comedi_devconfig - used to configure a legacy COMEDI device 802 * @board_name: Null-terminated string specifying the type of board 803 * to configure. 804 * @options: An array of integer configuration options. 805 * 806 * This is used with the %COMEDI_DEVCONFIG ioctl to configure a "legacy" COMEDI 807 * device, such as an ISA card. Not all COMEDI drivers support this. Those 808 * that do either expect the specified board name to match one of a list of 809 * names registered with the COMEDI core, or expect the specified board name 810 * to match the COMEDI driver name itself. The configuration options are 811 * handled in a driver-specific manner. 812 */ 813 struct comedi_devconfig { 814 char board_name[COMEDI_NAMELEN]; 815 int options[COMEDI_NDEVCONFOPTS]; 816 }; 817 818 /** 819 * struct comedi_bufconfig - used to set or get buffer size for a subdevice 820 * @subdevice: Subdevice index. 821 * @flags: Not used. 822 * @maximum_size: Maximum allowed buffer size. 823 * @size: Buffer size. 824 * @unused: Reserved for future use. 825 * 826 * This is used with the %COMEDI_BUFCONFIG ioctl to get or configure the 827 * maximum buffer size and current buffer size for a COMEDI subdevice that 828 * supports asynchronous commands. If the subdevice does not support 829 * asynchronous commands, @maximum_size and @size are ignored and set to 0. 830 * 831 * On ioctl input, non-zero values of @maximum_size and @size specify a 832 * new maximum size and new current size (in bytes), respectively. These 833 * will by rounded up to a multiple of %PAGE_SIZE. Specifying a new maximum 834 * size requires admin capabilities. 835 * 836 * On ioctl output, @maximum_size and @size and set to the current maximum 837 * buffer size and current buffer size, respectively. 838 */ 839 struct comedi_bufconfig { 840 unsigned int subdevice; 841 unsigned int flags; 842 843 unsigned int maximum_size; 844 unsigned int size; 845 846 unsigned int unused[4]; 847 }; 848 849 /** 850 * struct comedi_bufinfo - used to manipulate buffer position for a subdevice 851 * @subdevice: Subdevice index. 852 * @bytes_read: Specify amount to advance read position for an 853 * asynchronous command in the input ("read") direction. 854 * @buf_write_ptr: Current write position (index) within the buffer. 855 * @buf_read_ptr: Current read position (index) within the buffer. 856 * @buf_write_count: Total amount written, modulo 2^32. 857 * @buf_read_count: Total amount read, modulo 2^32. 858 * @bytes_written: Specify amount to advance write position for an 859 * asynchronous command in the output ("write") direction. 860 * @unused: Reserved for future use. 861 * 862 * This is used with the %COMEDI_BUFINFO ioctl to optionally advance the 863 * current read or write position in an asynchronous acquisition data buffer, 864 * and to get the current read and write positions in the buffer. 865 */ 866 struct comedi_bufinfo { 867 unsigned int subdevice; 868 unsigned int bytes_read; 869 870 unsigned int buf_write_ptr; 871 unsigned int buf_read_ptr; 872 unsigned int buf_write_count; 873 unsigned int buf_read_count; 874 875 unsigned int bytes_written; 876 877 unsigned int unused[4]; 878 }; 879 880 /* range stuff */ 881 882 #define __RANGE(a, b) ((((a) & 0xffff) << 16) | ((b) & 0xffff)) 883 884 #define RANGE_OFFSET(a) (((a) >> 16) & 0xffff) 885 #define RANGE_LENGTH(b) ((b) & 0xffff) 886 887 #define RF_UNIT(flags) ((flags) & 0xff) 888 #define RF_EXTERNAL 0x100 889 890 #define UNIT_volt 0 891 #define UNIT_mA 1 892 #define UNIT_none 2 893 894 #define COMEDI_MIN_SPEED 0xffffffffu 895 896 /**********************************************************/ 897 /* everything after this line is ALPHA */ 898 /**********************************************************/ 899 900 /* 901 * 8254 specific configuration. 902 * 903 * It supports two config commands: 904 * 905 * 0 ID: INSN_CONFIG_SET_COUNTER_MODE 906 * 1 8254 Mode 907 * I8254_MODE0, I8254_MODE1, ..., I8254_MODE5 908 * OR'ed with: 909 * I8254_BCD, I8254_BINARY 910 * 911 * 0 ID: INSN_CONFIG_8254_READ_STATUS 912 * 1 <-- Status byte returned here. 913 * B7 = Output 914 * B6 = NULL Count 915 * B5 - B0 Current mode. 916 */ 917 918 enum i8254_mode { 919 I8254_MODE0 = (0 << 1), /* Interrupt on terminal count */ 920 I8254_MODE1 = (1 << 1), /* Hardware retriggerable one-shot */ 921 I8254_MODE2 = (2 << 1), /* Rate generator */ 922 I8254_MODE3 = (3 << 1), /* Square wave mode */ 923 I8254_MODE4 = (4 << 1), /* Software triggered strobe */ 924 /* Hardware triggered strobe (retriggerable) */ 925 I8254_MODE5 = (5 << 1), 926 /* Use binary-coded decimal instead of binary (pretty useless) */ 927 I8254_BCD = 1, 928 I8254_BINARY = 0 929 }; 930 931 #define NI_USUAL_PFI_SELECT(x) (((x) < 10) ? (0x1 + (x)) : (0xb + (x))) 932 #define NI_USUAL_RTSI_SELECT(x) (((x) < 7) ? (0xb + (x)) : 0x1b) 933 934 /* 935 * mode bits for NI general-purpose counters, set with 936 * INSN_CONFIG_SET_COUNTER_MODE 937 */ 938 #define NI_GPCT_COUNTING_MODE_SHIFT 16 939 #define NI_GPCT_INDEX_PHASE_BITSHIFT 20 940 #define NI_GPCT_COUNTING_DIRECTION_SHIFT 24 941 enum ni_gpct_mode_bits { 942 NI_GPCT_GATE_ON_BOTH_EDGES_BIT = 0x4, 943 NI_GPCT_EDGE_GATE_MODE_MASK = 0x18, 944 NI_GPCT_EDGE_GATE_STARTS_STOPS_BITS = 0x0, 945 NI_GPCT_EDGE_GATE_STOPS_STARTS_BITS = 0x8, 946 NI_GPCT_EDGE_GATE_STARTS_BITS = 0x10, 947 NI_GPCT_EDGE_GATE_NO_STARTS_NO_STOPS_BITS = 0x18, 948 NI_GPCT_STOP_MODE_MASK = 0x60, 949 NI_GPCT_STOP_ON_GATE_BITS = 0x00, 950 NI_GPCT_STOP_ON_GATE_OR_TC_BITS = 0x20, 951 NI_GPCT_STOP_ON_GATE_OR_SECOND_TC_BITS = 0x40, 952 NI_GPCT_LOAD_B_SELECT_BIT = 0x80, 953 NI_GPCT_OUTPUT_MODE_MASK = 0x300, 954 NI_GPCT_OUTPUT_TC_PULSE_BITS = 0x100, 955 NI_GPCT_OUTPUT_TC_TOGGLE_BITS = 0x200, 956 NI_GPCT_OUTPUT_TC_OR_GATE_TOGGLE_BITS = 0x300, 957 NI_GPCT_HARDWARE_DISARM_MASK = 0xc00, 958 NI_GPCT_NO_HARDWARE_DISARM_BITS = 0x000, 959 NI_GPCT_DISARM_AT_TC_BITS = 0x400, 960 NI_GPCT_DISARM_AT_GATE_BITS = 0x800, 961 NI_GPCT_DISARM_AT_TC_OR_GATE_BITS = 0xc00, 962 NI_GPCT_LOADING_ON_TC_BIT = 0x1000, 963 NI_GPCT_LOADING_ON_GATE_BIT = 0x4000, 964 NI_GPCT_COUNTING_MODE_MASK = 0x7 << NI_GPCT_COUNTING_MODE_SHIFT, 965 NI_GPCT_COUNTING_MODE_NORMAL_BITS = 966 0x0 << NI_GPCT_COUNTING_MODE_SHIFT, 967 NI_GPCT_COUNTING_MODE_QUADRATURE_X1_BITS = 968 0x1 << NI_GPCT_COUNTING_MODE_SHIFT, 969 NI_GPCT_COUNTING_MODE_QUADRATURE_X2_BITS = 970 0x2 << NI_GPCT_COUNTING_MODE_SHIFT, 971 NI_GPCT_COUNTING_MODE_QUADRATURE_X4_BITS = 972 0x3 << NI_GPCT_COUNTING_MODE_SHIFT, 973 NI_GPCT_COUNTING_MODE_TWO_PULSE_BITS = 974 0x4 << NI_GPCT_COUNTING_MODE_SHIFT, 975 NI_GPCT_COUNTING_MODE_SYNC_SOURCE_BITS = 976 0x6 << NI_GPCT_COUNTING_MODE_SHIFT, 977 NI_GPCT_INDEX_PHASE_MASK = 0x3 << NI_GPCT_INDEX_PHASE_BITSHIFT, 978 NI_GPCT_INDEX_PHASE_LOW_A_LOW_B_BITS = 979 0x0 << NI_GPCT_INDEX_PHASE_BITSHIFT, 980 NI_GPCT_INDEX_PHASE_LOW_A_HIGH_B_BITS = 981 0x1 << NI_GPCT_INDEX_PHASE_BITSHIFT, 982 NI_GPCT_INDEX_PHASE_HIGH_A_LOW_B_BITS = 983 0x2 << NI_GPCT_INDEX_PHASE_BITSHIFT, 984 NI_GPCT_INDEX_PHASE_HIGH_A_HIGH_B_BITS = 985 0x3 << NI_GPCT_INDEX_PHASE_BITSHIFT, 986 NI_GPCT_INDEX_ENABLE_BIT = 0x400000, 987 NI_GPCT_COUNTING_DIRECTION_MASK = 988 0x3 << NI_GPCT_COUNTING_DIRECTION_SHIFT, 989 NI_GPCT_COUNTING_DIRECTION_DOWN_BITS = 990 0x00 << NI_GPCT_COUNTING_DIRECTION_SHIFT, 991 NI_GPCT_COUNTING_DIRECTION_UP_BITS = 992 0x1 << NI_GPCT_COUNTING_DIRECTION_SHIFT, 993 NI_GPCT_COUNTING_DIRECTION_HW_UP_DOWN_BITS = 994 0x2 << NI_GPCT_COUNTING_DIRECTION_SHIFT, 995 NI_GPCT_COUNTING_DIRECTION_HW_GATE_BITS = 996 0x3 << NI_GPCT_COUNTING_DIRECTION_SHIFT, 997 NI_GPCT_RELOAD_SOURCE_MASK = 0xc000000, 998 NI_GPCT_RELOAD_SOURCE_FIXED_BITS = 0x0, 999 NI_GPCT_RELOAD_SOURCE_SWITCHING_BITS = 0x4000000, 1000 NI_GPCT_RELOAD_SOURCE_GATE_SELECT_BITS = 0x8000000, 1001 NI_GPCT_OR_GATE_BIT = 0x10000000, 1002 NI_GPCT_INVERT_OUTPUT_BIT = 0x20000000 1003 }; 1004 1005 /* 1006 * Bits for setting a clock source with 1007 * INSN_CONFIG_SET_CLOCK_SRC when using NI general-purpose counters. 1008 */ 1009 enum ni_gpct_clock_source_bits { 1010 NI_GPCT_CLOCK_SRC_SELECT_MASK = 0x3f, 1011 NI_GPCT_TIMEBASE_1_CLOCK_SRC_BITS = 0x0, 1012 NI_GPCT_TIMEBASE_2_CLOCK_SRC_BITS = 0x1, 1013 NI_GPCT_TIMEBASE_3_CLOCK_SRC_BITS = 0x2, 1014 NI_GPCT_LOGIC_LOW_CLOCK_SRC_BITS = 0x3, 1015 NI_GPCT_NEXT_GATE_CLOCK_SRC_BITS = 0x4, 1016 NI_GPCT_NEXT_TC_CLOCK_SRC_BITS = 0x5, 1017 /* NI 660x-specific */ 1018 NI_GPCT_SOURCE_PIN_i_CLOCK_SRC_BITS = 0x6, 1019 NI_GPCT_PXI10_CLOCK_SRC_BITS = 0x7, 1020 NI_GPCT_PXI_STAR_TRIGGER_CLOCK_SRC_BITS = 0x8, 1021 NI_GPCT_ANALOG_TRIGGER_OUT_CLOCK_SRC_BITS = 0x9, 1022 NI_GPCT_PRESCALE_MODE_CLOCK_SRC_MASK = 0x30000000, 1023 NI_GPCT_NO_PRESCALE_CLOCK_SRC_BITS = 0x0, 1024 /* divide source by 2 */ 1025 NI_GPCT_PRESCALE_X2_CLOCK_SRC_BITS = 0x10000000, 1026 /* divide source by 8 */ 1027 NI_GPCT_PRESCALE_X8_CLOCK_SRC_BITS = 0x20000000, 1028 NI_GPCT_INVERT_CLOCK_SRC_BIT = 0x80000000 1029 }; 1030 1031 /* NI 660x-specific */ 1032 #define NI_GPCT_SOURCE_PIN_CLOCK_SRC_BITS(x) (0x10 + (x)) 1033 1034 #define NI_GPCT_RTSI_CLOCK_SRC_BITS(x) (0x18 + (x)) 1035 1036 /* no pfi on NI 660x */ 1037 #define NI_GPCT_PFI_CLOCK_SRC_BITS(x) (0x20 + (x)) 1038 1039 /* 1040 * Possibilities for setting a gate source with 1041 * INSN_CONFIG_SET_GATE_SRC when using NI general-purpose counters. 1042 * May be bitwise-or'd with CR_EDGE or CR_INVERT. 1043 */ 1044 enum ni_gpct_gate_select { 1045 /* m-series gates */ 1046 NI_GPCT_TIMESTAMP_MUX_GATE_SELECT = 0x0, 1047 NI_GPCT_AI_START2_GATE_SELECT = 0x12, 1048 NI_GPCT_PXI_STAR_TRIGGER_GATE_SELECT = 0x13, 1049 NI_GPCT_NEXT_OUT_GATE_SELECT = 0x14, 1050 NI_GPCT_AI_START1_GATE_SELECT = 0x1c, 1051 NI_GPCT_NEXT_SOURCE_GATE_SELECT = 0x1d, 1052 NI_GPCT_ANALOG_TRIGGER_OUT_GATE_SELECT = 0x1e, 1053 NI_GPCT_LOGIC_LOW_GATE_SELECT = 0x1f, 1054 /* more gates for 660x */ 1055 NI_GPCT_SOURCE_PIN_i_GATE_SELECT = 0x100, 1056 NI_GPCT_GATE_PIN_i_GATE_SELECT = 0x101, 1057 /* more gates for 660x "second gate" */ 1058 NI_GPCT_UP_DOWN_PIN_i_GATE_SELECT = 0x201, 1059 NI_GPCT_SELECTED_GATE_GATE_SELECT = 0x21e, 1060 /* 1061 * m-series "second gate" sources are unknown, 1062 * we should add them here with an offset of 0x300 when 1063 * known. 1064 */ 1065 NI_GPCT_DISABLED_GATE_SELECT = 0x8000, 1066 }; 1067 1068 #define NI_GPCT_GATE_PIN_GATE_SELECT(x) (0x102 + (x)) 1069 #define NI_GPCT_RTSI_GATE_SELECT(x) NI_USUAL_RTSI_SELECT(x) 1070 #define NI_GPCT_PFI_GATE_SELECT(x) NI_USUAL_PFI_SELECT(x) 1071 #define NI_GPCT_UP_DOWN_PIN_GATE_SELECT(x) (0x202 + (x)) 1072 1073 /* 1074 * Possibilities for setting a source with 1075 * INSN_CONFIG_SET_OTHER_SRC when using NI general-purpose counters. 1076 */ 1077 enum ni_gpct_other_index { 1078 NI_GPCT_SOURCE_ENCODER_A, 1079 NI_GPCT_SOURCE_ENCODER_B, 1080 NI_GPCT_SOURCE_ENCODER_Z 1081 }; 1082 1083 enum ni_gpct_other_select { 1084 /* m-series gates */ 1085 /* Still unknown, probably only need NI_GPCT_PFI_OTHER_SELECT */ 1086 NI_GPCT_DISABLED_OTHER_SELECT = 0x8000, 1087 }; 1088 1089 #define NI_GPCT_PFI_OTHER_SELECT(x) NI_USUAL_PFI_SELECT(x) 1090 1091 /* 1092 * start sources for ni general-purpose counters for use with 1093 * INSN_CONFIG_ARM 1094 */ 1095 enum ni_gpct_arm_source { 1096 NI_GPCT_ARM_IMMEDIATE = 0x0, 1097 /* 1098 * Start both the counter and the adjacent paired counter simultaneously 1099 */ 1100 NI_GPCT_ARM_PAIRED_IMMEDIATE = 0x1, 1101 /* 1102 * If the NI_GPCT_HW_ARM bit is set, we will pass the least significant 1103 * bits (3 bits for 660x or 5 bits for m-series) through to the 1104 * hardware. To select a hardware trigger, pass the appropriate select 1105 * bit, e.g., 1106 * NI_GPCT_HW_ARM | NI_GPCT_AI_START1_GATE_SELECT or 1107 * NI_GPCT_HW_ARM | NI_GPCT_PFI_GATE_SELECT(pfi_number) 1108 */ 1109 NI_GPCT_HW_ARM = 0x1000, 1110 NI_GPCT_ARM_UNKNOWN = NI_GPCT_HW_ARM, /* for backward compatibility */ 1111 }; 1112 1113 /* digital filtering options for ni 660x for use with INSN_CONFIG_FILTER. */ 1114 enum ni_gpct_filter_select { 1115 NI_GPCT_FILTER_OFF = 0x0, 1116 NI_GPCT_FILTER_TIMEBASE_3_SYNC = 0x1, 1117 NI_GPCT_FILTER_100x_TIMEBASE_1 = 0x2, 1118 NI_GPCT_FILTER_20x_TIMEBASE_1 = 0x3, 1119 NI_GPCT_FILTER_10x_TIMEBASE_1 = 0x4, 1120 NI_GPCT_FILTER_2x_TIMEBASE_1 = 0x5, 1121 NI_GPCT_FILTER_2x_TIMEBASE_3 = 0x6 1122 }; 1123 1124 /* 1125 * PFI digital filtering options for ni m-series for use with 1126 * INSN_CONFIG_FILTER. 1127 */ 1128 enum ni_pfi_filter_select { 1129 NI_PFI_FILTER_OFF = 0x0, 1130 NI_PFI_FILTER_125ns = 0x1, 1131 NI_PFI_FILTER_6425ns = 0x2, 1132 NI_PFI_FILTER_2550us = 0x3 1133 }; 1134 1135 /* master clock sources for ni mio boards and INSN_CONFIG_SET_CLOCK_SRC */ 1136 enum ni_mio_clock_source { 1137 NI_MIO_INTERNAL_CLOCK = 0, 1138 /* 1139 * Doesn't work for m-series, use NI_MIO_PLL_RTSI_CLOCK() 1140 * the NI_MIO_PLL_* sources are m-series only 1141 */ 1142 NI_MIO_RTSI_CLOCK = 1, 1143 NI_MIO_PLL_PXI_STAR_TRIGGER_CLOCK = 2, 1144 NI_MIO_PLL_PXI10_CLOCK = 3, 1145 NI_MIO_PLL_RTSI0_CLOCK = 4 1146 }; 1147 1148 #define NI_MIO_PLL_RTSI_CLOCK(x) (NI_MIO_PLL_RTSI0_CLOCK + (x)) 1149 1150 /* 1151 * Signals which can be routed to an NI RTSI pin with INSN_CONFIG_SET_ROUTING. 1152 * The numbers assigned are not arbitrary, they correspond to the bits required 1153 * to program the board. 1154 */ 1155 enum ni_rtsi_routing { 1156 NI_RTSI_OUTPUT_ADR_START1 = 0, 1157 NI_RTSI_OUTPUT_ADR_START2 = 1, 1158 NI_RTSI_OUTPUT_SCLKG = 2, 1159 NI_RTSI_OUTPUT_DACUPDN = 3, 1160 NI_RTSI_OUTPUT_DA_START1 = 4, 1161 NI_RTSI_OUTPUT_G_SRC0 = 5, 1162 NI_RTSI_OUTPUT_G_GATE0 = 6, 1163 NI_RTSI_OUTPUT_RGOUT0 = 7, 1164 NI_RTSI_OUTPUT_RTSI_BRD_0 = 8, 1165 /* Pre-m-series always have RTSI clock on line 7 */ 1166 NI_RTSI_OUTPUT_RTSI_OSC = 12 1167 }; 1168 1169 #define NI_RTSI_OUTPUT_RTSI_BRD(x) (NI_RTSI_OUTPUT_RTSI_BRD_0 + (x)) 1170 1171 /* 1172 * Signals which can be routed to an NI PFI pin on an m-series board with 1173 * INSN_CONFIG_SET_ROUTING. These numbers are also returned by 1174 * INSN_CONFIG_GET_ROUTING on pre-m-series boards, even though their routing 1175 * cannot be changed. The numbers assigned are not arbitrary, they correspond 1176 * to the bits required to program the board. 1177 */ 1178 enum ni_pfi_routing { 1179 NI_PFI_OUTPUT_PFI_DEFAULT = 0, 1180 NI_PFI_OUTPUT_AI_START1 = 1, 1181 NI_PFI_OUTPUT_AI_START2 = 2, 1182 NI_PFI_OUTPUT_AI_CONVERT = 3, 1183 NI_PFI_OUTPUT_G_SRC1 = 4, 1184 NI_PFI_OUTPUT_G_GATE1 = 5, 1185 NI_PFI_OUTPUT_AO_UPDATE_N = 6, 1186 NI_PFI_OUTPUT_AO_START1 = 7, 1187 NI_PFI_OUTPUT_AI_START_PULSE = 8, 1188 NI_PFI_OUTPUT_G_SRC0 = 9, 1189 NI_PFI_OUTPUT_G_GATE0 = 10, 1190 NI_PFI_OUTPUT_EXT_STROBE = 11, 1191 NI_PFI_OUTPUT_AI_EXT_MUX_CLK = 12, 1192 NI_PFI_OUTPUT_GOUT0 = 13, 1193 NI_PFI_OUTPUT_GOUT1 = 14, 1194 NI_PFI_OUTPUT_FREQ_OUT = 15, 1195 NI_PFI_OUTPUT_PFI_DO = 16, 1196 NI_PFI_OUTPUT_I_ATRIG = 17, 1197 NI_PFI_OUTPUT_RTSI0 = 18, 1198 NI_PFI_OUTPUT_PXI_STAR_TRIGGER_IN = 26, 1199 NI_PFI_OUTPUT_SCXI_TRIG1 = 27, 1200 NI_PFI_OUTPUT_DIO_CHANGE_DETECT_RTSI = 28, 1201 NI_PFI_OUTPUT_CDI_SAMPLE = 29, 1202 NI_PFI_OUTPUT_CDO_UPDATE = 30 1203 }; 1204 1205 #define NI_PFI_OUTPUT_RTSI(x) (NI_PFI_OUTPUT_RTSI0 + (x)) 1206 1207 /* 1208 * Signals which can be routed to output on a NI PFI pin on a 660x board 1209 * with INSN_CONFIG_SET_ROUTING. The numbers assigned are 1210 * not arbitrary, they correspond to the bits required 1211 * to program the board. Lines 0 to 7 can only be set to 1212 * NI_660X_PFI_OUTPUT_DIO. Lines 32 to 39 can only be set to 1213 * NI_660X_PFI_OUTPUT_COUNTER. 1214 */ 1215 enum ni_660x_pfi_routing { 1216 NI_660X_PFI_OUTPUT_COUNTER = 1, /* counter */ 1217 NI_660X_PFI_OUTPUT_DIO = 2, /* static digital output */ 1218 }; 1219 1220 /* 1221 * NI External Trigger lines. These values are not arbitrary, but are related 1222 * to the bits required to program the board (offset by 1 for historical 1223 * reasons). 1224 */ 1225 #define NI_EXT_PFI(x) (NI_USUAL_PFI_SELECT(x) - 1) 1226 #define NI_EXT_RTSI(x) (NI_USUAL_RTSI_SELECT(x) - 1) 1227 1228 /* 1229 * Clock sources for CDIO subdevice on NI m-series boards. Used as the 1230 * scan_begin_arg for a comedi_command. These sources may also be bitwise-or'd 1231 * with CR_INVERT to change polarity. 1232 */ 1233 enum ni_m_series_cdio_scan_begin_src { 1234 NI_CDIO_SCAN_BEGIN_SRC_GROUND = 0, 1235 NI_CDIO_SCAN_BEGIN_SRC_AI_START = 18, 1236 NI_CDIO_SCAN_BEGIN_SRC_AI_CONVERT = 19, 1237 NI_CDIO_SCAN_BEGIN_SRC_PXI_STAR_TRIGGER = 20, 1238 NI_CDIO_SCAN_BEGIN_SRC_G0_OUT = 28, 1239 NI_CDIO_SCAN_BEGIN_SRC_G1_OUT = 29, 1240 NI_CDIO_SCAN_BEGIN_SRC_ANALOG_TRIGGER = 30, 1241 NI_CDIO_SCAN_BEGIN_SRC_AO_UPDATE = 31, 1242 NI_CDIO_SCAN_BEGIN_SRC_FREQ_OUT = 32, 1243 NI_CDIO_SCAN_BEGIN_SRC_DIO_CHANGE_DETECT_IRQ = 33 1244 }; 1245 1246 #define NI_CDIO_SCAN_BEGIN_SRC_PFI(x) NI_USUAL_PFI_SELECT(x) 1247 #define NI_CDIO_SCAN_BEGIN_SRC_RTSI(x) NI_USUAL_RTSI_SELECT(x) 1248 1249 /* 1250 * scan_begin_src for scan_begin_arg==TRIG_EXT with analog output command on NI 1251 * boards. These scan begin sources can also be bitwise-or'd with CR_INVERT to 1252 * change polarity. 1253 */ 1254 #define NI_AO_SCAN_BEGIN_SRC_PFI(x) NI_USUAL_PFI_SELECT(x) 1255 #define NI_AO_SCAN_BEGIN_SRC_RTSI(x) NI_USUAL_RTSI_SELECT(x) 1256 1257 /* 1258 * Bits for setting a clock source with 1259 * INSN_CONFIG_SET_CLOCK_SRC when using NI frequency output subdevice. 1260 */ 1261 enum ni_freq_out_clock_source_bits { 1262 NI_FREQ_OUT_TIMEBASE_1_DIV_2_CLOCK_SRC, /* 10 MHz */ 1263 NI_FREQ_OUT_TIMEBASE_2_CLOCK_SRC /* 100 KHz */ 1264 }; 1265 1266 /* 1267 * Values for setting a clock source with INSN_CONFIG_SET_CLOCK_SRC for 1268 * 8254 counter subdevices on Amplicon DIO boards (amplc_dio200 driver). 1269 */ 1270 enum amplc_dio_clock_source { 1271 /* 1272 * Per channel external clock 1273 * input/output pin (pin is only an 1274 * input when clock source set to this value, 1275 * otherwise it is an output) 1276 */ 1277 AMPLC_DIO_CLK_CLKN, 1278 AMPLC_DIO_CLK_10MHZ, /* 10 MHz internal clock */ 1279 AMPLC_DIO_CLK_1MHZ, /* 1 MHz internal clock */ 1280 AMPLC_DIO_CLK_100KHZ, /* 100 kHz internal clock */ 1281 AMPLC_DIO_CLK_10KHZ, /* 10 kHz internal clock */ 1282 AMPLC_DIO_CLK_1KHZ, /* 1 kHz internal clock */ 1283 /* 1284 * Output of preceding counter channel 1285 * (for channel 0, preceding counter 1286 * channel is channel 2 on preceding 1287 * counter subdevice, for first counter 1288 * subdevice, preceding counter 1289 * subdevice is the last counter 1290 * subdevice) 1291 */ 1292 AMPLC_DIO_CLK_OUTNM1, 1293 AMPLC_DIO_CLK_EXT, /* per chip external input pin */ 1294 /* the following are "enhanced" clock sources for PCIe models */ 1295 AMPLC_DIO_CLK_VCC, /* clock input HIGH */ 1296 AMPLC_DIO_CLK_GND, /* clock input LOW */ 1297 AMPLC_DIO_CLK_PAT_PRESENT, /* "pattern present" signal */ 1298 AMPLC_DIO_CLK_20MHZ /* 20 MHz internal clock */ 1299 }; 1300 1301 /* 1302 * Values for setting a clock source with INSN_CONFIG_SET_CLOCK_SRC for 1303 * timer subdevice on some Amplicon DIO PCIe boards (amplc_dio200 driver). 1304 */ 1305 enum amplc_dio_ts_clock_src { 1306 AMPLC_DIO_TS_CLK_1GHZ, /* 1 ns period with 20 ns granularity */ 1307 AMPLC_DIO_TS_CLK_1MHZ, /* 1 us period */ 1308 AMPLC_DIO_TS_CLK_1KHZ /* 1 ms period */ 1309 }; 1310 1311 /* 1312 * Values for setting a gate source with INSN_CONFIG_SET_GATE_SRC for 1313 * 8254 counter subdevices on Amplicon DIO boards (amplc_dio200 driver). 1314 */ 1315 enum amplc_dio_gate_source { 1316 AMPLC_DIO_GAT_VCC, /* internal high logic level */ 1317 AMPLC_DIO_GAT_GND, /* internal low logic level */ 1318 AMPLC_DIO_GAT_GATN, /* per channel external gate input */ 1319 /* 1320 * negated output of counter channel minus 2 1321 * (for channels 0 or 1, channel minus 2 is channel 1 or 2 on 1322 * the preceding counter subdevice, for the first counter subdevice 1323 * the preceding counter subdevice is the last counter subdevice) 1324 */ 1325 AMPLC_DIO_GAT_NOUTNM2, 1326 AMPLC_DIO_GAT_RESERVED4, 1327 AMPLC_DIO_GAT_RESERVED5, 1328 AMPLC_DIO_GAT_RESERVED6, 1329 AMPLC_DIO_GAT_RESERVED7, 1330 /* the following are "enhanced" gate sources for PCIe models */ 1331 AMPLC_DIO_GAT_NGATN = 6, /* negated per channel gate input */ 1332 /* non-negated output of counter channel minus 2 */ 1333 AMPLC_DIO_GAT_OUTNM2, 1334 AMPLC_DIO_GAT_PAT_PRESENT, /* "pattern present" signal */ 1335 AMPLC_DIO_GAT_PAT_OCCURRED, /* "pattern occurred" latched */ 1336 AMPLC_DIO_GAT_PAT_GONE, /* "pattern gone away" latched */ 1337 AMPLC_DIO_GAT_NPAT_PRESENT, /* negated "pattern present" */ 1338 AMPLC_DIO_GAT_NPAT_OCCURRED, /* negated "pattern occurred" */ 1339 AMPLC_DIO_GAT_NPAT_GONE /* negated "pattern gone away" */ 1340 }; 1341 1342 /* 1343 * Values for setting a clock source with INSN_CONFIG_SET_CLOCK_SRC for 1344 * the counter subdevice on the Kolter Electronic PCI-Counter board 1345 * (ke_counter driver). 1346 */ 1347 enum ke_counter_clock_source { 1348 KE_CLK_20MHZ, /* internal 20MHz (default) */ 1349 KE_CLK_4MHZ, /* internal 4MHz (option) */ 1350 KE_CLK_EXT /* external clock on pin 21 of D-Sub */ 1351 }; 1352 1353 #endif /* _COMEDI_H */ 1354