comedidev.h 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * comedidev.h
  4. * header file for kernel-only structures, variables, and constants
  5. *
  6. * COMEDI - Linux Control and Measurement Device Interface
  7. * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
  8. */
  9. #ifndef _COMEDIDEV_H
  10. #define _COMEDIDEV_H
  11. #include <linux/dma-mapping.h>
  12. #include <linux/mutex.h>
  13. #include <linux/spinlock_types.h>
  14. #include <linux/rwsem.h>
  15. #include <linux/kref.h>
  16. #include "comedi.h"
  17. #define COMEDI_VERSION(a, b, c) (((a) << 16) + ((b) << 8) + (c))
  18. #define COMEDI_VERSION_CODE COMEDI_VERSION(COMEDI_MAJORVERSION, \
  19. COMEDI_MINORVERSION, COMEDI_MICROVERSION)
  20. #define COMEDI_RELEASE VERSION
  21. #define COMEDI_NUM_BOARD_MINORS 0x30
  22. /**
  23. * struct comedi_subdevice - Working data for a COMEDI subdevice
  24. * @device: COMEDI device to which this subdevice belongs. (Initialized by
  25. * comedi_alloc_subdevices().)
  26. * @index: Index of this subdevice within device's array of subdevices.
  27. * (Initialized by comedi_alloc_subdevices().)
  28. * @type: Type of subdevice from &enum comedi_subdevice_type. (Initialized by
  29. * the low-level driver.)
  30. * @n_chan: Number of channels the subdevice supports. (Initialized by the
  31. * low-level driver.)
  32. * @subdev_flags: Various "SDF" flags indicating aspects of the subdevice to
  33. * the COMEDI core and user application. (Initialized by the low-level
  34. * driver.)
  35. * @len_chanlist: Maximum length of a channel list if the subdevice supports
  36. * asynchronous acquisition commands. (Optionally initialized by the
  37. * low-level driver, or changed from 0 to 1 during post-configuration.)
  38. * @private: Private data pointer which is either set by the low-level driver
  39. * itself, or by a call to comedi_alloc_spriv() which allocates storage.
  40. * In the latter case, the storage is automatically freed after the
  41. * low-level driver's "detach" handler is called for the device.
  42. * (Initialized by the low-level driver.)
  43. * @async: Pointer to &struct comedi_async id the subdevice supports
  44. * asynchronous acquisition commands. (Allocated and initialized during
  45. * post-configuration if needed.)
  46. * @lock: Pointer to a file object that performed a %COMEDI_LOCK ioctl on the
  47. * subdevice. (Initially NULL.)
  48. * @busy: Pointer to a file object that is performing an asynchronous
  49. * acquisition command on the subdevice. (Initially NULL.)
  50. * @runflags: Internal flags for use by COMEDI core, mostly indicating whether
  51. * an asynchronous acquisition command is running.
  52. * @spin_lock: Generic spin-lock for use by the COMEDI core and the low-level
  53. * driver. (Initialized by comedi_alloc_subdevices().)
  54. * @io_bits: Bit-mask indicating the channel directions for a DIO subdevice
  55. * with no more than 32 channels. A '1' at a bit position indicates the
  56. * corresponding channel is configured as an output. (Initialized by the
  57. * low-level driver for a DIO subdevice. Forced to all-outputs during
  58. * post-configuration for a digital output subdevice.)
  59. * @maxdata: If non-zero, this is the maximum raw data value of each channel.
  60. * If zero, the maximum data value is channel-specific. (Initialized by
  61. * the low-level driver.)
  62. * @maxdata_list: If the maximum data value is channel-specific, this points
  63. * to an array of maximum data values indexed by channel index.
  64. * (Initialized by the low-level driver.)
  65. * @range_table: If non-NULL, this points to a COMEDI range table for the
  66. * subdevice. If NULL, the range table is channel-specific. (Initialized
  67. * by the low-level driver, will be set to an "invalid" range table during
  68. * post-configuration if @range_table and @range_table_list are both
  69. * NULL.)
  70. * @range_table_list: If the COMEDI range table is channel-specific, this
  71. * points to an array of pointers to COMEDI range tables indexed by
  72. * channel number. (Initialized by the low-level driver.)
  73. * @chanlist: Not used.
  74. * @insn_read: Optional pointer to a handler for the %INSN_READ instruction.
  75. * (Initialized by the low-level driver, or set to a default handler
  76. * during post-configuration.)
  77. * @insn_write: Optional pointer to a handler for the %INSN_WRITE instruction.
  78. * (Initialized by the low-level driver, or set to a default handler
  79. * during post-configuration.)
  80. * @insn_bits: Optional pointer to a handler for the %INSN_BITS instruction
  81. * for a digital input, digital output or digital input/output subdevice.
  82. * (Initialized by the low-level driver, or set to a default handler
  83. * during post-configuration.)
  84. * @insn_config: Optional pointer to a handler for the %INSN_CONFIG
  85. * instruction. (Initialized by the low-level driver, or set to a default
  86. * handler during post-configuration.)
  87. * @do_cmd: If the subdevice supports asynchronous acquisition commands, this
  88. * points to a handler to set it up in hardware. (Initialized by the
  89. * low-level driver.)
  90. * @do_cmdtest: If the subdevice supports asynchronous acquisition commands,
  91. * this points to a handler used to check and possibly tweak a prospective
  92. * acquisition command without setting it up in hardware. (Initialized by
  93. * the low-level driver.)
  94. * @poll: If the subdevice supports asynchronous acquisition commands, this
  95. * is an optional pointer to a handler for the %COMEDI_POLL ioctl which
  96. * instructs the low-level driver to synchronize buffers. (Initialized by
  97. * the low-level driver if needed.)
  98. * @cancel: If the subdevice supports asynchronous acquisition commands, this
  99. * points to a handler used to terminate a running command. (Initialized
  100. * by the low-level driver.)
  101. * @buf_change: If the subdevice supports asynchronous acquisition commands,
  102. * this is an optional pointer to a handler that is called when the data
  103. * buffer for handling asynchronous commands is allocated or reallocated.
  104. * (Initialized by the low-level driver if needed.)
  105. * @munge: If the subdevice supports asynchronous acquisition commands and
  106. * uses DMA to transfer data from the hardware to the acquisition buffer,
  107. * this points to a function used to "munge" the data values from the
  108. * hardware into the format expected by COMEDI. (Initialized by the
  109. * low-level driver if needed.)
  110. * @async_dma_dir: If the subdevice supports asynchronous acquisition commands
  111. * and uses DMA to transfer data from the hardware to the acquisition
  112. * buffer, this sets the DMA direction for the buffer. (initialized to
  113. * %DMA_NONE by comedi_alloc_subdevices() and changed by the low-level
  114. * driver if necessary.)
  115. * @state: Handy bit-mask indicating the output states for a DIO or digital
  116. * output subdevice with no more than 32 channels. (Initialized by the
  117. * low-level driver.)
  118. * @class_dev: If the subdevice supports asynchronous acquisition commands,
  119. * this points to a sysfs comediX_subdY device where X is the minor device
  120. * number of the COMEDI device and Y is the subdevice number. The minor
  121. * device number for the sysfs device is allocated dynamically in the
  122. * range 48 to 255. This is used to allow the COMEDI device to be opened
  123. * with a different default read or write subdevice. (Allocated during
  124. * post-configuration if needed.)
  125. * @minor: If @class_dev is set, this is its dynamically allocated minor
  126. * device number. (Set during post-configuration if necessary.)
  127. * @readback: Optional pointer to memory allocated by
  128. * comedi_alloc_subdev_readback() used to hold the values written to
  129. * analog output channels so they can be read back. The storage is
  130. * automatically freed after the low-level driver's "detach" handler is
  131. * called for the device. (Initialized by the low-level driver.)
  132. *
  133. * This is the main control structure for a COMEDI subdevice. If the subdevice
  134. * supports asynchronous acquisition commands, additional information is stored
  135. * in the &struct comedi_async pointed to by @async.
  136. *
  137. * Most of the subdevice is initialized by the low-level driver's "attach" or
  138. * "auto_attach" handlers but parts of it are initialized by
  139. * comedi_alloc_subdevices(), and other parts are initialized during
  140. * post-configuration on return from that handler.
  141. *
  142. * A low-level driver that sets @insn_bits for a digital input, digital output,
  143. * or DIO subdevice may leave @insn_read and @insn_write uninitialized, in
  144. * which case they will be set to a default handler during post-configuration
  145. * that uses @insn_bits to emulate the %INSN_READ and %INSN_WRITE instructions.
  146. */
  147. struct comedi_subdevice {
  148. struct comedi_device *device;
  149. int index;
  150. int type;
  151. int n_chan;
  152. int subdev_flags;
  153. int len_chanlist; /* maximum length of channel/gain list */
  154. void *private;
  155. struct comedi_async *async;
  156. void *lock;
  157. void *busy;
  158. unsigned int runflags;
  159. spinlock_t spin_lock; /* generic spin-lock for COMEDI and drivers */
  160. unsigned int io_bits;
  161. unsigned int maxdata; /* if maxdata==0, use list */
  162. const unsigned int *maxdata_list; /* list is channel specific */
  163. const struct comedi_lrange *range_table;
  164. const struct comedi_lrange *const *range_table_list;
  165. unsigned int *chanlist; /* driver-owned chanlist (not used) */
  166. int (*insn_read)(struct comedi_device *dev, struct comedi_subdevice *s,
  167. struct comedi_insn *insn, unsigned int *data);
  168. int (*insn_write)(struct comedi_device *dev, struct comedi_subdevice *s,
  169. struct comedi_insn *insn, unsigned int *data);
  170. int (*insn_bits)(struct comedi_device *dev, struct comedi_subdevice *s,
  171. struct comedi_insn *insn, unsigned int *data);
  172. int (*insn_config)(struct comedi_device *dev,
  173. struct comedi_subdevice *s,
  174. struct comedi_insn *insn,
  175. unsigned int *data);
  176. int (*do_cmd)(struct comedi_device *dev, struct comedi_subdevice *s);
  177. int (*do_cmdtest)(struct comedi_device *dev,
  178. struct comedi_subdevice *s,
  179. struct comedi_cmd *cmd);
  180. int (*poll)(struct comedi_device *dev, struct comedi_subdevice *s);
  181. int (*cancel)(struct comedi_device *dev, struct comedi_subdevice *s);
  182. /* called when the buffer changes */
  183. int (*buf_change)(struct comedi_device *dev,
  184. struct comedi_subdevice *s);
  185. void (*munge)(struct comedi_device *dev, struct comedi_subdevice *s,
  186. void *data, unsigned int num_bytes,
  187. unsigned int start_chan_index);
  188. enum dma_data_direction async_dma_dir;
  189. unsigned int state;
  190. struct device *class_dev;
  191. int minor;
  192. unsigned int *readback;
  193. };
  194. /**
  195. * struct comedi_buf_page - Describe a page of a COMEDI buffer
  196. * @virt_addr: Kernel address of page.
  197. * @dma_addr: DMA address of page if in DMA coherent memory.
  198. */
  199. struct comedi_buf_page {
  200. void *virt_addr;
  201. dma_addr_t dma_addr;
  202. };
  203. /**
  204. * struct comedi_buf_map - Describe pages in a COMEDI buffer
  205. * @dma_hw_dev: Low-level hardware &struct device pointer copied from the
  206. * COMEDI device's hw_dev member.
  207. * @page_list: Pointer to array of &struct comedi_buf_page, one for each
  208. * page in the buffer.
  209. * @n_pages: Number of pages in the buffer.
  210. * @dma_dir: DMA direction used to allocate pages of DMA coherent memory,
  211. * or %DMA_NONE if pages allocated from regular memory.
  212. * @refcount: &struct kref reference counter used to free the buffer.
  213. *
  214. * A COMEDI data buffer is allocated as individual pages, either in
  215. * conventional memory or DMA coherent memory, depending on the attached,
  216. * low-level hardware device. (The buffer pages also get mapped into the
  217. * kernel's contiguous virtual address space pointed to by the 'prealloc_buf'
  218. * member of &struct comedi_async.)
  219. *
  220. * The buffer is normally freed when the COMEDI device is detached from the
  221. * low-level driver (which may happen due to device removal), but if it happens
  222. * to be mmapped at the time, the pages cannot be freed until the buffer has
  223. * been munmapped. That is what the reference counter is for. (The virtual
  224. * address space pointed by 'prealloc_buf' is freed when the COMEDI device is
  225. * detached.)
  226. */
  227. struct comedi_buf_map {
  228. struct device *dma_hw_dev;
  229. struct comedi_buf_page *page_list;
  230. unsigned int n_pages;
  231. enum dma_data_direction dma_dir;
  232. struct kref refcount;
  233. };
  234. /**
  235. * struct comedi_async - Control data for asynchronous COMEDI commands
  236. * @prealloc_buf: Kernel virtual address of allocated acquisition buffer.
  237. * @prealloc_bufsz: Buffer size (in bytes).
  238. * @buf_map: Map of buffer pages.
  239. * @max_bufsize: Maximum allowed buffer size (in bytes).
  240. * @buf_write_count: "Write completed" count (in bytes, modulo 2**32).
  241. * @buf_write_alloc_count: "Allocated for writing" count (in bytes,
  242. * modulo 2**32).
  243. * @buf_read_count: "Read completed" count (in bytes, modulo 2**32).
  244. * @buf_read_alloc_count: "Allocated for reading" count (in bytes,
  245. * modulo 2**32).
  246. * @buf_write_ptr: Buffer position for writer.
  247. * @buf_read_ptr: Buffer position for reader.
  248. * @cur_chan: Current position in chanlist for scan (for those drivers that
  249. * use it).
  250. * @scans_done: The number of scans completed.
  251. * @scan_progress: Amount received or sent for current scan (in bytes).
  252. * @munge_chan: Current position in chanlist for "munging".
  253. * @munge_count: "Munge" count (in bytes, modulo 2**32).
  254. * @munge_ptr: Buffer position for "munging".
  255. * @events: Bit-vector of events that have occurred.
  256. * @cmd: Details of comedi command in progress.
  257. * @wait_head: Task wait queue for file reader or writer.
  258. * @cb_mask: Bit-vector of events that should wake waiting tasks.
  259. * @inttrig: Software trigger function for command, or NULL.
  260. *
  261. * Note about the ..._count and ..._ptr members:
  262. *
  263. * Think of the _Count values being integers of unlimited size, indexing
  264. * into a buffer of infinite length (though only an advancing portion
  265. * of the buffer of fixed length prealloc_bufsz is accessible at any
  266. * time). Then:
  267. *
  268. * Buf_Read_Count <= Buf_Read_Alloc_Count <= Munge_Count <=
  269. * Buf_Write_Count <= Buf_Write_Alloc_Count <=
  270. * (Buf_Read_Count + prealloc_bufsz)
  271. *
  272. * (Those aren't the actual members, apart from prealloc_bufsz.) When the
  273. * buffer is reset, those _Count values start at 0 and only increase in value,
  274. * maintaining the above inequalities until the next time the buffer is
  275. * reset. The buffer is divided into the following regions by the inequalities:
  276. *
  277. * [0, Buf_Read_Count):
  278. * old region no longer accessible
  279. *
  280. * [Buf_Read_Count, Buf_Read_Alloc_Count):
  281. * filled and munged region allocated for reading but not yet read
  282. *
  283. * [Buf_Read_Alloc_Count, Munge_Count):
  284. * filled and munged region not yet allocated for reading
  285. *
  286. * [Munge_Count, Buf_Write_Count):
  287. * filled region not yet munged
  288. *
  289. * [Buf_Write_Count, Buf_Write_Alloc_Count):
  290. * unfilled region allocated for writing but not yet written
  291. *
  292. * [Buf_Write_Alloc_Count, Buf_Read_Count + prealloc_bufsz):
  293. * unfilled region not yet allocated for writing
  294. *
  295. * [Buf_Read_Count + prealloc_bufsz, infinity):
  296. * unfilled region not yet accessible
  297. *
  298. * Data needs to be written into the buffer before it can be read out,
  299. * and may need to be converted (or "munged") between the two
  300. * operations. Extra unfilled buffer space may need to allocated for
  301. * writing (advancing Buf_Write_Alloc_Count) before new data is written.
  302. * After writing new data, the newly filled space needs to be released
  303. * (advancing Buf_Write_Count). This also results in the new data being
  304. * "munged" (advancing Munge_Count). Before data is read out of the
  305. * buffer, extra space may need to be allocated for reading (advancing
  306. * Buf_Read_Alloc_Count). After the data has been read out, the space
  307. * needs to be released (advancing Buf_Read_Count).
  308. *
  309. * The actual members, buf_read_count, buf_read_alloc_count,
  310. * munge_count, buf_write_count, and buf_write_alloc_count take the
  311. * value of the corresponding capitalized _Count values modulo 2^32
  312. * (UINT_MAX+1). Subtracting a "higher" _count value from a "lower"
  313. * _count value gives the same answer as subtracting a "higher" _Count
  314. * value from a lower _Count value because prealloc_bufsz < UINT_MAX+1.
  315. * The modulo operation is done implicitly.
  316. *
  317. * The buf_read_ptr, munge_ptr, and buf_write_ptr members take the value
  318. * of the corresponding capitalized _Count values modulo prealloc_bufsz.
  319. * These correspond to byte indices in the physical buffer. The modulo
  320. * operation is done by subtracting prealloc_bufsz when the value
  321. * exceeds prealloc_bufsz (assuming prealloc_bufsz plus the increment is
  322. * less than or equal to UINT_MAX).
  323. */
  324. struct comedi_async {
  325. void *prealloc_buf;
  326. unsigned int prealloc_bufsz;
  327. struct comedi_buf_map *buf_map;
  328. unsigned int max_bufsize;
  329. unsigned int buf_write_count;
  330. unsigned int buf_write_alloc_count;
  331. unsigned int buf_read_count;
  332. unsigned int buf_read_alloc_count;
  333. unsigned int buf_write_ptr;
  334. unsigned int buf_read_ptr;
  335. unsigned int cur_chan;
  336. unsigned int scans_done;
  337. unsigned int scan_progress;
  338. unsigned int munge_chan;
  339. unsigned int munge_count;
  340. unsigned int munge_ptr;
  341. unsigned int events;
  342. struct comedi_cmd cmd;
  343. wait_queue_head_t wait_head;
  344. unsigned int cb_mask;
  345. int (*inttrig)(struct comedi_device *dev, struct comedi_subdevice *s,
  346. unsigned int x);
  347. };
  348. /**
  349. * enum comedi_cb - &struct comedi_async callback "events"
  350. * @COMEDI_CB_EOS: end-of-scan
  351. * @COMEDI_CB_EOA: end-of-acquisition/output
  352. * @COMEDI_CB_BLOCK: data has arrived, wakes up read() / write()
  353. * @COMEDI_CB_EOBUF: DEPRECATED: end of buffer
  354. * @COMEDI_CB_ERROR: card error during acquisition
  355. * @COMEDI_CB_OVERFLOW: buffer overflow/underflow
  356. * @COMEDI_CB_ERROR_MASK: events that indicate an error has occurred
  357. * @COMEDI_CB_CANCEL_MASK: events that will cancel an async command
  358. */
  359. enum comedi_cb {
  360. COMEDI_CB_EOS = BIT(0),
  361. COMEDI_CB_EOA = BIT(1),
  362. COMEDI_CB_BLOCK = BIT(2),
  363. COMEDI_CB_EOBUF = BIT(3),
  364. COMEDI_CB_ERROR = BIT(4),
  365. COMEDI_CB_OVERFLOW = BIT(5),
  366. /* masks */
  367. COMEDI_CB_ERROR_MASK = (COMEDI_CB_ERROR | COMEDI_CB_OVERFLOW),
  368. COMEDI_CB_CANCEL_MASK = (COMEDI_CB_EOA | COMEDI_CB_ERROR_MASK)
  369. };
  370. /**
  371. * struct comedi_driver - COMEDI driver registration
  372. * @driver_name: Name of driver.
  373. * @module: Owning module.
  374. * @attach: The optional "attach" handler for manually configured COMEDI
  375. * devices.
  376. * @detach: The "detach" handler for deconfiguring COMEDI devices.
  377. * @auto_attach: The optional "auto_attach" handler for automatically
  378. * configured COMEDI devices.
  379. * @num_names: Optional number of "board names" supported.
  380. * @board_name: Optional pointer to a pointer to a board name. The pointer
  381. * to a board name is embedded in an element of a driver-defined array
  382. * of static, read-only board type information.
  383. * @offset: Optional size of each element of the driver-defined array of
  384. * static, read-only board type information, i.e. the offset between each
  385. * pointer to a board name.
  386. *
  387. * This is used with comedi_driver_register() and comedi_driver_unregister() to
  388. * register and unregister a low-level COMEDI driver with the COMEDI core.
  389. *
  390. * If @num_names is non-zero, @board_name should be non-NULL, and @offset
  391. * should be at least sizeof(*board_name). These are used by the handler for
  392. * the %COMEDI_DEVCONFIG ioctl to match a hardware device and its driver by
  393. * board name. If @num_names is zero, the %COMEDI_DEVCONFIG ioctl matches a
  394. * hardware device and its driver by driver name. This is only useful if the
  395. * @attach handler is set. If @num_names is non-zero, the driver's @attach
  396. * handler will be called with the COMEDI device structure's board_ptr member
  397. * pointing to the matched pointer to a board name within the driver's private
  398. * array of static, read-only board type information.
  399. *
  400. * The @detach handler has two roles. If a COMEDI device was successfully
  401. * configured by the @attach or @auto_attach handler, it is called when the
  402. * device is being deconfigured (by the %COMEDI_DEVCONFIG ioctl, or due to
  403. * unloading of the driver, or due to device removal). It is also called when
  404. * the @attach or @auto_attach handler returns an error. Therefore, the
  405. * @attach or @auto_attach handlers can defer clean-up on error until the
  406. * @detach handler is called. If the @attach or @auto_attach handlers free
  407. * any resources themselves, they must prevent the @detach handler from
  408. * freeing the same resources. The @detach handler must not assume that all
  409. * resources requested by the @attach or @auto_attach handler were
  410. * successfully allocated.
  411. */
  412. struct comedi_driver {
  413. /* private: */
  414. struct comedi_driver *next; /* Next in list of COMEDI drivers. */
  415. /* public: */
  416. const char *driver_name;
  417. struct module *module;
  418. int (*attach)(struct comedi_device *dev, struct comedi_devconfig *it);
  419. void (*detach)(struct comedi_device *dev);
  420. int (*auto_attach)(struct comedi_device *dev, unsigned long context);
  421. unsigned int num_names;
  422. const char *const *board_name;
  423. int offset;
  424. };
  425. /**
  426. * struct comedi_device - Working data for a COMEDI device
  427. * @use_count: Number of open file objects.
  428. * @driver: Low-level COMEDI driver attached to this COMEDI device.
  429. * @pacer: Optional pointer to a dynamically allocated acquisition pacer
  430. * control. It is freed automatically after the COMEDI device is
  431. * detached from the low-level driver.
  432. * @private: Optional pointer to private data allocated by the low-level
  433. * driver. It is freed automatically after the COMEDI device is
  434. * detached from the low-level driver.
  435. * @class_dev: Sysfs comediX device.
  436. * @minor: Minor device number of COMEDI char device (0-47).
  437. * @detach_count: Counter incremented every time the COMEDI device is detached.
  438. * Used for checking a previous attachment is still valid.
  439. * @hw_dev: Optional pointer to the low-level hardware &struct device. It is
  440. * required for automatically configured COMEDI devices and optional for
  441. * COMEDI devices configured by the %COMEDI_DEVCONFIG ioctl, although
  442. * the bus-specific COMEDI functions only work if it is set correctly.
  443. * It is also passed to dma_alloc_coherent() for COMEDI subdevices that
  444. * have their 'async_dma_dir' member set to something other than
  445. * %DMA_NONE.
  446. * @board_name: Pointer to a COMEDI board name or a COMEDI driver name. When
  447. * the low-level driver's "attach" handler is called by the handler for
  448. * the %COMEDI_DEVCONFIG ioctl, it either points to a matched board name
  449. * string if the 'num_names' member of the &struct comedi_driver is
  450. * non-zero, otherwise it points to the low-level driver name string.
  451. * When the low-lever driver's "auto_attach" handler is called for an
  452. * automatically configured COMEDI device, it points to the low-level
  453. * driver name string. The low-level driver is free to change it in its
  454. * "attach" or "auto_attach" handler if it wishes.
  455. * @board_ptr: Optional pointer to private, read-only board type information in
  456. * the low-level driver. If the 'num_names' member of the &struct
  457. * comedi_driver is non-zero, the handler for the %COMEDI_DEVCONFIG ioctl
  458. * will point it to a pointer to a matched board name string within the
  459. * driver's private array of static, read-only board type information when
  460. * calling the driver's "attach" handler. The low-level driver is free to
  461. * change it.
  462. * @attached: Flag indicating that the COMEDI device is attached to a low-level
  463. * driver.
  464. * @ioenabled: Flag used to indicate that a PCI device has been enabled and
  465. * its regions requested.
  466. * @spinlock: Generic spin-lock for use by the low-level driver.
  467. * @mutex: Generic mutex for use by the COMEDI core module.
  468. * @attach_lock: &struct rw_semaphore used to guard against the COMEDI device
  469. * being detached while an operation is in progress. The down_write()
  470. * operation is only allowed while @mutex is held and is used when
  471. * changing @attached and @detach_count and calling the low-level driver's
  472. * "detach" handler. The down_read() operation is generally used without
  473. * holding @mutex.
  474. * @refcount: &struct kref reference counter for freeing COMEDI device.
  475. * @n_subdevices: Number of COMEDI subdevices allocated by the low-level
  476. * driver for this device.
  477. * @subdevices: Dynamically allocated array of COMEDI subdevices.
  478. * @mmio: Optional pointer to a remapped MMIO region set by the low-level
  479. * driver.
  480. * @iobase: Optional base of an I/O port region requested by the low-level
  481. * driver.
  482. * @iolen: Length of I/O port region requested at @iobase.
  483. * @irq: Optional IRQ number requested by the low-level driver.
  484. * @read_subdev: Optional pointer to a default COMEDI subdevice operated on by
  485. * the read() file operation. Set by the low-level driver.
  486. * @write_subdev: Optional pointer to a default COMEDI subdevice operated on by
  487. * the write() file operation. Set by the low-level driver.
  488. * @async_queue: Storage for fasync_helper().
  489. * @open: Optional pointer to a function set by the low-level driver to be
  490. * called when @use_count changes from 0 to 1.
  491. * @close: Optional pointer to a function set by the low-level driver to be
  492. * called when @use_count changed from 1 to 0.
  493. * @insn_device_config: Optional pointer to a handler for all sub-instructions
  494. * except %INSN_DEVICE_CONFIG_GET_ROUTES of the %INSN_DEVICE_CONFIG
  495. * instruction. If this is not initialized by the low-level driver, a
  496. * default handler will be set during post-configuration.
  497. * @get_valid_routes: Optional pointer to a handler for the
  498. * %INSN_DEVICE_CONFIG_GET_ROUTES sub-instruction of the
  499. * %INSN_DEVICE_CONFIG instruction set. If this is not initialized by the
  500. * low-level driver, a default handler that copies zero routes back to the
  501. * user will be used.
  502. *
  503. * This is the main control data structure for a COMEDI device (as far as the
  504. * COMEDI core is concerned). There are two groups of COMEDI devices -
  505. * "legacy" devices that are configured by the handler for the
  506. * %COMEDI_DEVCONFIG ioctl, and automatically configured devices resulting
  507. * from a call to comedi_auto_config() as a result of a bus driver probe in
  508. * a low-level COMEDI driver. The "legacy" COMEDI devices are allocated
  509. * during module initialization if the "comedi_num_legacy_minors" module
  510. * parameter is non-zero and use minor device numbers from 0 to
  511. * comedi_num_legacy_minors minus one. The automatically configured COMEDI
  512. * devices are allocated on demand and use minor device numbers from
  513. * comedi_num_legacy_minors to 47.
  514. */
  515. struct comedi_device {
  516. int use_count;
  517. struct comedi_driver *driver;
  518. struct comedi_8254 *pacer;
  519. void *private;
  520. struct device *class_dev;
  521. int minor;
  522. unsigned int detach_count;
  523. struct device *hw_dev;
  524. const char *board_name;
  525. const void *board_ptr;
  526. unsigned int attached:1;
  527. unsigned int ioenabled:1;
  528. spinlock_t spinlock; /* generic spin-lock for low-level driver */
  529. struct mutex mutex; /* generic mutex for COMEDI core */
  530. struct rw_semaphore attach_lock;
  531. struct kref refcount;
  532. int n_subdevices;
  533. struct comedi_subdevice *subdevices;
  534. /* dumb */
  535. void __iomem *mmio;
  536. unsigned long iobase;
  537. unsigned long iolen;
  538. unsigned int irq;
  539. struct comedi_subdevice *read_subdev;
  540. struct comedi_subdevice *write_subdev;
  541. struct fasync_struct *async_queue;
  542. int (*open)(struct comedi_device *dev);
  543. void (*close)(struct comedi_device *dev);
  544. int (*insn_device_config)(struct comedi_device *dev,
  545. struct comedi_insn *insn, unsigned int *data);
  546. unsigned int (*get_valid_routes)(struct comedi_device *dev,
  547. unsigned int n_pairs,
  548. unsigned int *pair_data);
  549. };
  550. /*
  551. * function prototypes
  552. */
  553. void comedi_event(struct comedi_device *dev, struct comedi_subdevice *s);
  554. struct comedi_device *comedi_dev_get_from_minor(unsigned int minor);
  555. int comedi_dev_put(struct comedi_device *dev);
  556. bool comedi_is_subdevice_running(struct comedi_subdevice *s);
  557. void *comedi_alloc_spriv(struct comedi_subdevice *s, size_t size);
  558. void comedi_set_spriv_auto_free(struct comedi_subdevice *s);
  559. int comedi_check_chanlist(struct comedi_subdevice *s,
  560. int n,
  561. unsigned int *chanlist);
  562. /* range stuff */
  563. #define RANGE(a, b) {(a) * 1e6, (b) * 1e6, 0}
  564. #define RANGE_ext(a, b) {(a) * 1e6, (b) * 1e6, RF_EXTERNAL}
  565. #define RANGE_mA(a, b) {(a) * 1e6, (b) * 1e6, UNIT_mA}
  566. #define RANGE_unitless(a, b) {(a) * 1e6, (b) * 1e6, 0}
  567. #define BIP_RANGE(a) {-(a) * 1e6, (a) * 1e6, 0}
  568. #define UNI_RANGE(a) {0, (a) * 1e6, 0}
  569. extern const struct comedi_lrange range_bipolar10;
  570. extern const struct comedi_lrange range_bipolar5;
  571. extern const struct comedi_lrange range_bipolar2_5;
  572. extern const struct comedi_lrange range_unipolar10;
  573. extern const struct comedi_lrange range_unipolar5;
  574. extern const struct comedi_lrange range_unipolar2_5;
  575. extern const struct comedi_lrange range_0_20mA;
  576. extern const struct comedi_lrange range_4_20mA;
  577. extern const struct comedi_lrange range_0_32mA;
  578. extern const struct comedi_lrange range_unknown;
  579. #define range_digital range_unipolar5
  580. /**
  581. * struct comedi_lrange - Describes a COMEDI range table
  582. * @length: Number of entries in the range table.
  583. * @range: Array of &struct comedi_krange, one for each range.
  584. *
  585. * Each element of @range[] describes the minimum and maximum physical range
  586. * and the type of units. Typically, the type of unit is %UNIT_volt
  587. * (i.e. volts) and the minimum and maximum are in millionths of a volt.
  588. * There may also be a flag that indicates the minimum and maximum are merely
  589. * scale factors for an unknown, external reference.
  590. */
  591. struct comedi_lrange {
  592. int length;
  593. struct comedi_krange range[];
  594. };
  595. /**
  596. * comedi_range_is_bipolar() - Test if subdevice range is bipolar
  597. * @s: COMEDI subdevice.
  598. * @range: Index of range within a range table.
  599. *
  600. * Tests whether a range is bipolar by checking whether its minimum value
  601. * is negative.
  602. *
  603. * Assumes @range is valid. Does not work for subdevices using a
  604. * channel-specific range table list.
  605. *
  606. * Return:
  607. * %true if the range is bipolar.
  608. * %false if the range is unipolar.
  609. */
  610. static inline bool comedi_range_is_bipolar(struct comedi_subdevice *s,
  611. unsigned int range)
  612. {
  613. return s->range_table->range[range].min < 0;
  614. }
  615. /**
  616. * comedi_range_is_unipolar() - Test if subdevice range is unipolar
  617. * @s: COMEDI subdevice.
  618. * @range: Index of range within a range table.
  619. *
  620. * Tests whether a range is unipolar by checking whether its minimum value
  621. * is at least 0.
  622. *
  623. * Assumes @range is valid. Does not work for subdevices using a
  624. * channel-specific range table list.
  625. *
  626. * Return:
  627. * %true if the range is unipolar.
  628. * %false if the range is bipolar.
  629. */
  630. static inline bool comedi_range_is_unipolar(struct comedi_subdevice *s,
  631. unsigned int range)
  632. {
  633. return s->range_table->range[range].min >= 0;
  634. }
  635. /**
  636. * comedi_range_is_external() - Test if subdevice range is external
  637. * @s: COMEDI subdevice.
  638. * @range: Index of range within a range table.
  639. *
  640. * Tests whether a range is externally reference by checking whether its
  641. * %RF_EXTERNAL flag is set.
  642. *
  643. * Assumes @range is valid. Does not work for subdevices using a
  644. * channel-specific range table list.
  645. *
  646. * Return:
  647. * %true if the range is external.
  648. * %false if the range is internal.
  649. */
  650. static inline bool comedi_range_is_external(struct comedi_subdevice *s,
  651. unsigned int range)
  652. {
  653. return !!(s->range_table->range[range].flags & RF_EXTERNAL);
  654. }
  655. /**
  656. * comedi_chan_range_is_bipolar() - Test if channel-specific range is bipolar
  657. * @s: COMEDI subdevice.
  658. * @chan: The channel number.
  659. * @range: Index of range within a range table.
  660. *
  661. * Tests whether a range is bipolar by checking whether its minimum value
  662. * is negative.
  663. *
  664. * Assumes @chan and @range are valid. Only works for subdevices with a
  665. * channel-specific range table list.
  666. *
  667. * Return:
  668. * %true if the range is bipolar.
  669. * %false if the range is unipolar.
  670. */
  671. static inline bool comedi_chan_range_is_bipolar(struct comedi_subdevice *s,
  672. unsigned int chan,
  673. unsigned int range)
  674. {
  675. return s->range_table_list[chan]->range[range].min < 0;
  676. }
  677. /**
  678. * comedi_chan_range_is_unipolar() - Test if channel-specific range is unipolar
  679. * @s: COMEDI subdevice.
  680. * @chan: The channel number.
  681. * @range: Index of range within a range table.
  682. *
  683. * Tests whether a range is unipolar by checking whether its minimum value
  684. * is at least 0.
  685. *
  686. * Assumes @chan and @range are valid. Only works for subdevices with a
  687. * channel-specific range table list.
  688. *
  689. * Return:
  690. * %true if the range is unipolar.
  691. * %false if the range is bipolar.
  692. */
  693. static inline bool comedi_chan_range_is_unipolar(struct comedi_subdevice *s,
  694. unsigned int chan,
  695. unsigned int range)
  696. {
  697. return s->range_table_list[chan]->range[range].min >= 0;
  698. }
  699. /**
  700. * comedi_chan_range_is_external() - Test if channel-specific range is external
  701. * @s: COMEDI subdevice.
  702. * @chan: The channel number.
  703. * @range: Index of range within a range table.
  704. *
  705. * Tests whether a range is externally reference by checking whether its
  706. * %RF_EXTERNAL flag is set.
  707. *
  708. * Assumes @chan and @range are valid. Only works for subdevices with a
  709. * channel-specific range table list.
  710. *
  711. * Return:
  712. * %true if the range is bipolar.
  713. * %false if the range is unipolar.
  714. */
  715. static inline bool comedi_chan_range_is_external(struct comedi_subdevice *s,
  716. unsigned int chan,
  717. unsigned int range)
  718. {
  719. return !!(s->range_table_list[chan]->range[range].flags & RF_EXTERNAL);
  720. }
  721. /**
  722. * comedi_offset_munge() - Convert between offset binary and 2's complement
  723. * @s: COMEDI subdevice.
  724. * @val: Value to be converted.
  725. *
  726. * Toggles the highest bit of a sample value to toggle between offset binary
  727. * and 2's complement. Assumes that @s->maxdata is a power of 2 minus 1.
  728. *
  729. * Return: The converted value.
  730. */
  731. static inline unsigned int comedi_offset_munge(struct comedi_subdevice *s,
  732. unsigned int val)
  733. {
  734. return val ^ s->maxdata ^ (s->maxdata >> 1);
  735. }
  736. /**
  737. * comedi_bytes_per_sample() - Determine subdevice sample size
  738. * @s: COMEDI subdevice.
  739. *
  740. * The sample size will be 4 (sizeof int) or 2 (sizeof short) depending on
  741. * whether the %SDF_LSAMPL subdevice flag is set or not.
  742. *
  743. * Return: The subdevice sample size.
  744. */
  745. static inline unsigned int comedi_bytes_per_sample(struct comedi_subdevice *s)
  746. {
  747. return s->subdev_flags & SDF_LSAMPL ? sizeof(int) : sizeof(short);
  748. }
  749. /**
  750. * comedi_sample_shift() - Determine log2 of subdevice sample size
  751. * @s: COMEDI subdevice.
  752. *
  753. * The sample size will be 4 (sizeof int) or 2 (sizeof short) depending on
  754. * whether the %SDF_LSAMPL subdevice flag is set or not. The log2 of the
  755. * sample size will be 2 or 1 and can be used as the right operand of a
  756. * bit-shift operator to multiply or divide something by the sample size.
  757. *
  758. * Return: log2 of the subdevice sample size.
  759. */
  760. static inline unsigned int comedi_sample_shift(struct comedi_subdevice *s)
  761. {
  762. return s->subdev_flags & SDF_LSAMPL ? 2 : 1;
  763. }
  764. /**
  765. * comedi_bytes_to_samples() - Convert a number of bytes to a number of samples
  766. * @s: COMEDI subdevice.
  767. * @nbytes: Number of bytes
  768. *
  769. * Return: The number of bytes divided by the subdevice sample size.
  770. */
  771. static inline unsigned int comedi_bytes_to_samples(struct comedi_subdevice *s,
  772. unsigned int nbytes)
  773. {
  774. return nbytes >> comedi_sample_shift(s);
  775. }
  776. /**
  777. * comedi_samples_to_bytes() - Convert a number of samples to a number of bytes
  778. * @s: COMEDI subdevice.
  779. * @nsamples: Number of samples.
  780. *
  781. * Return: The number of samples multiplied by the subdevice sample size.
  782. * (Does not check for arithmetic overflow.)
  783. */
  784. static inline unsigned int comedi_samples_to_bytes(struct comedi_subdevice *s,
  785. unsigned int nsamples)
  786. {
  787. return nsamples << comedi_sample_shift(s);
  788. }
  789. /**
  790. * comedi_check_trigger_src() - Trivially validate a comedi_cmd trigger source
  791. * @src: Pointer to the trigger source to validate.
  792. * @flags: Bitmask of valid %TRIG_* for the trigger.
  793. *
  794. * This is used in "step 1" of the do_cmdtest functions of comedi drivers
  795. * to validate the comedi_cmd triggers. The mask of the @src against the
  796. * @flags allows the userspace comedilib to pass all the comedi_cmd
  797. * triggers as %TRIG_ANY and get back a bitmask of the valid trigger sources.
  798. *
  799. * Return:
  800. * 0 if trigger sources in *@src are all supported.
  801. * -EINVAL if any trigger source in *@src is unsupported.
  802. */
  803. static inline int comedi_check_trigger_src(unsigned int *src,
  804. unsigned int flags)
  805. {
  806. unsigned int orig_src = *src;
  807. *src = orig_src & flags;
  808. if (*src == TRIG_INVALID || *src != orig_src)
  809. return -EINVAL;
  810. return 0;
  811. }
  812. /**
  813. * comedi_check_trigger_is_unique() - Make sure a trigger source is unique
  814. * @src: The trigger source to check.
  815. *
  816. * Return:
  817. * 0 if no more than one trigger source is set.
  818. * -EINVAL if more than one trigger source is set.
  819. */
  820. static inline int comedi_check_trigger_is_unique(unsigned int src)
  821. {
  822. /* this test is true if more than one _src bit is set */
  823. if ((src & (src - 1)) != 0)
  824. return -EINVAL;
  825. return 0;
  826. }
  827. /**
  828. * comedi_check_trigger_arg_is() - Trivially validate a trigger argument
  829. * @arg: Pointer to the trigger arg to validate.
  830. * @val: The value the argument should be.
  831. *
  832. * Forces *@arg to be @val.
  833. *
  834. * Return:
  835. * 0 if *@arg was already @val.
  836. * -EINVAL if *@arg differed from @val.
  837. */
  838. static inline int comedi_check_trigger_arg_is(unsigned int *arg,
  839. unsigned int val)
  840. {
  841. if (*arg != val) {
  842. *arg = val;
  843. return -EINVAL;
  844. }
  845. return 0;
  846. }
  847. /**
  848. * comedi_check_trigger_arg_min() - Trivially validate a trigger argument min
  849. * @arg: Pointer to the trigger arg to validate.
  850. * @val: The minimum value the argument should be.
  851. *
  852. * Forces *@arg to be at least @val, setting it to @val if necessary.
  853. *
  854. * Return:
  855. * 0 if *@arg was already at least @val.
  856. * -EINVAL if *@arg was less than @val.
  857. */
  858. static inline int comedi_check_trigger_arg_min(unsigned int *arg,
  859. unsigned int val)
  860. {
  861. if (*arg < val) {
  862. *arg = val;
  863. return -EINVAL;
  864. }
  865. return 0;
  866. }
  867. /**
  868. * comedi_check_trigger_arg_max() - Trivially validate a trigger argument max
  869. * @arg: Pointer to the trigger arg to validate.
  870. * @val: The maximum value the argument should be.
  871. *
  872. * Forces *@arg to be no more than @val, setting it to @val if necessary.
  873. *
  874. * Return:
  875. * 0 if*@arg was already no more than @val.
  876. * -EINVAL if *@arg was greater than @val.
  877. */
  878. static inline int comedi_check_trigger_arg_max(unsigned int *arg,
  879. unsigned int val)
  880. {
  881. if (*arg > val) {
  882. *arg = val;
  883. return -EINVAL;
  884. }
  885. return 0;
  886. }
  887. /*
  888. * Must set dev->hw_dev if you wish to dma directly into comedi's buffer.
  889. * Also useful for retrieving a previously configured hardware device of
  890. * known bus type. Set automatically for auto-configured devices.
  891. * Automatically set to NULL when detaching hardware device.
  892. */
  893. int comedi_set_hw_dev(struct comedi_device *dev, struct device *hw_dev);
  894. /**
  895. * comedi_buf_n_bytes_ready - Determine amount of unread data in buffer
  896. * @s: COMEDI subdevice.
  897. *
  898. * Determines the number of bytes of unread data in the asynchronous
  899. * acquisition data buffer for a subdevice. The data in question might not
  900. * have been fully "munged" yet.
  901. *
  902. * Returns: The amount of unread data in bytes.
  903. */
  904. static inline unsigned int comedi_buf_n_bytes_ready(struct comedi_subdevice *s)
  905. {
  906. return s->async->buf_write_count - s->async->buf_read_count;
  907. }
  908. unsigned int comedi_buf_write_alloc(struct comedi_subdevice *s, unsigned int n);
  909. unsigned int comedi_buf_write_free(struct comedi_subdevice *s, unsigned int n);
  910. unsigned int comedi_buf_read_n_available(struct comedi_subdevice *s);
  911. unsigned int comedi_buf_read_alloc(struct comedi_subdevice *s, unsigned int n);
  912. unsigned int comedi_buf_read_free(struct comedi_subdevice *s, unsigned int n);
  913. unsigned int comedi_buf_write_samples(struct comedi_subdevice *s,
  914. const void *data, unsigned int nsamples);
  915. unsigned int comedi_buf_read_samples(struct comedi_subdevice *s,
  916. void *data, unsigned int nsamples);
  917. /* drivers.c - general comedi driver functions */
  918. #define COMEDI_TIMEOUT_MS 1000
  919. int comedi_timeout(struct comedi_device *dev, struct comedi_subdevice *s,
  920. struct comedi_insn *insn,
  921. int (*cb)(struct comedi_device *dev,
  922. struct comedi_subdevice *s,
  923. struct comedi_insn *insn, unsigned long context),
  924. unsigned long context);
  925. unsigned int comedi_handle_events(struct comedi_device *dev,
  926. struct comedi_subdevice *s);
  927. int comedi_dio_insn_config(struct comedi_device *dev,
  928. struct comedi_subdevice *s,
  929. struct comedi_insn *insn, unsigned int *data,
  930. unsigned int mask);
  931. unsigned int comedi_dio_update_state(struct comedi_subdevice *s,
  932. unsigned int *data);
  933. unsigned int comedi_bytes_per_scan_cmd(struct comedi_subdevice *s,
  934. struct comedi_cmd *cmd);
  935. unsigned int comedi_bytes_per_scan(struct comedi_subdevice *s);
  936. unsigned int comedi_nscans_left(struct comedi_subdevice *s,
  937. unsigned int nscans);
  938. unsigned int comedi_nsamples_left(struct comedi_subdevice *s,
  939. unsigned int nsamples);
  940. void comedi_inc_scan_progress(struct comedi_subdevice *s,
  941. unsigned int num_bytes);
  942. void *comedi_alloc_devpriv(struct comedi_device *dev, size_t size);
  943. int comedi_alloc_subdevices(struct comedi_device *dev, int num_subdevices);
  944. int comedi_alloc_subdev_readback(struct comedi_subdevice *s);
  945. int comedi_readback_insn_read(struct comedi_device *dev,
  946. struct comedi_subdevice *s,
  947. struct comedi_insn *insn, unsigned int *data);
  948. int comedi_load_firmware(struct comedi_device *dev, struct device *hw_dev,
  949. const char *name,
  950. int (*cb)(struct comedi_device *dev,
  951. const u8 *data, size_t size,
  952. unsigned long context),
  953. unsigned long context);
  954. int __comedi_request_region(struct comedi_device *dev,
  955. unsigned long start, unsigned long len);
  956. int comedi_request_region(struct comedi_device *dev,
  957. unsigned long start, unsigned long len);
  958. void comedi_legacy_detach(struct comedi_device *dev);
  959. int comedi_auto_config(struct device *hardware_device,
  960. struct comedi_driver *driver, unsigned long context);
  961. void comedi_auto_unconfig(struct device *hardware_device);
  962. int comedi_driver_register(struct comedi_driver *driver);
  963. void comedi_driver_unregister(struct comedi_driver *driver);
  964. /**
  965. * module_comedi_driver() - Helper macro for registering a comedi driver
  966. * @__comedi_driver: comedi_driver struct
  967. *
  968. * Helper macro for comedi drivers which do not do anything special in module
  969. * init/exit. This eliminates a lot of boilerplate. Each module may only use
  970. * this macro once, and calling it replaces module_init() and module_exit().
  971. */
  972. #define module_comedi_driver(__comedi_driver) \
  973. module_driver(__comedi_driver, comedi_driver_register, \
  974. comedi_driver_unregister)
  975. #endif /* _COMEDIDEV_H */