]>
Commit | Line | Data |
---|---|---|
ed9eccbe DS |
1 | /* |
2 | include/linux/comedidev.h | |
3 | header file for kernel-only structures, variables, and constants | |
4 | ||
5 | COMEDI - Linux Control and Measurement Device Interface | |
6 | Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org> | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
21 | ||
22 | */ | |
23 | ||
24 | #ifndef _COMEDIDEV_H | |
25 | #define _COMEDIDEV_H | |
26 | ||
27 | #include <linux/kernel.h> | |
28 | #include <linux/module.h> | |
ed9eccbe DS |
29 | #include <linux/kdev_t.h> |
30 | #include <linux/slab.h> | |
f9c51375 | 31 | #include <linux/delay.h> |
ed9eccbe DS |
32 | #include <linux/errno.h> |
33 | #include <linux/spinlock.h> | |
34 | #include <linux/mutex.h> | |
35 | #include <linux/wait.h> | |
36 | #include <linux/mm.h> | |
37 | #include <linux/init.h> | |
38 | #include <linux/vmalloc.h> | |
ed9eccbe | 39 | #include <linux/dma-mapping.h> |
e0dcef71 GKH |
40 | #include <linux/uaccess.h> |
41 | #include <linux/io.h> | |
c7a5d707 | 42 | #include <linux/timer.h> |
55c03cff | 43 | #include <linux/pci.h> |
0a577b82 | 44 | #include <linux/usb.h> |
ed9eccbe DS |
45 | |
46 | #include "comedi.h" | |
47 | ||
e0dcef71 GKH |
48 | #define DPRINTK(format, args...) do { \ |
49 | if (comedi_debug) \ | |
4f870fe6 | 50 | pr_debug("comedi: " format, ## args); \ |
e0dcef71 | 51 | } while (0) |
ed9eccbe | 52 | |
e0dcef71 | 53 | #define COMEDI_VERSION(a, b, c) (((a) << 16) + ((b) << 8) + (c)) |
62eeae93 SW |
54 | #define COMEDI_VERSION_CODE COMEDI_VERSION(COMEDI_MAJORVERSION, \ |
55 | COMEDI_MINORVERSION, COMEDI_MICROVERSION) | |
ed9eccbe DS |
56 | #define COMEDI_RELEASE VERSION |
57 | ||
cb3e9d86 HS |
58 | /* |
59 | * PCI Vendor IDs not in <linux/pci_ids.h> | |
60 | */ | |
0d374622 | 61 | #define PCI_VENDOR_ID_KOLTER 0x1001 |
ed9eccbe | 62 | #define PCI_VENDOR_ID_ICP 0x104c |
26853312 | 63 | #define PCI_VENDOR_ID_AMCC 0x10e8 |
f656ef5b | 64 | #define PCI_VENDOR_ID_DT 0x1116 |
34f8d208 | 65 | #define PCI_VENDOR_ID_IOTECH 0x1616 |
ed9eccbe | 66 | #define PCI_VENDOR_ID_CONTEC 0x1221 |
cb3e9d86 | 67 | #define PCI_VENDOR_ID_CB 0x1307 /* Measurement Computing */ |
12f07ba5 | 68 | #define PCI_VENDOR_ID_ADVANTECH 0x13fe |
b77d93a0 | 69 | #define PCI_VENDOR_ID_MEILHAUS 0x1402 |
50d3c3f5 | 70 | #define PCI_VENDOR_ID_RTD 0x1435 |
cb3e9d86 | 71 | #define PCI_VENDOR_ID_ADLINK 0x144a |
2847ff5d | 72 | #define PCI_VENDOR_ID_AMPLICON 0x14dc |
ed9eccbe DS |
73 | |
74 | #define COMEDI_NUM_MINORS 0x100 | |
ed9eccbe DS |
75 | #define COMEDI_NUM_BOARD_MINORS 0x30 |
76 | #define COMEDI_FIRST_SUBDEVICE_MINOR COMEDI_NUM_BOARD_MINORS | |
77 | ||
34c43922 | 78 | struct comedi_subdevice { |
71b5f4f1 | 79 | struct comedi_device *device; |
ed9eccbe DS |
80 | int type; |
81 | int n_chan; | |
baf22b64 | 82 | int subdev_flags; |
ed9eccbe DS |
83 | int len_chanlist; /* maximum length of channel/gain list */ |
84 | ||
85 | void *private; | |
86 | ||
d163679c | 87 | struct comedi_async *async; |
ed9eccbe DS |
88 | |
89 | void *lock; | |
90 | void *busy; | |
91 | unsigned runflags; | |
92 | spinlock_t spin_lock; | |
93 | ||
d4a7dc85 | 94 | unsigned int io_bits; |
ed9eccbe | 95 | |
790c5541 BP |
96 | unsigned int maxdata; /* if maxdata==0, use list */ |
97 | const unsigned int *maxdata_list; /* list is channel specific */ | |
ed9eccbe DS |
98 | |
99 | unsigned int flags; | |
100 | const unsigned int *flaglist; | |
101 | ||
102 | unsigned int settling_time_0; | |
103 | ||
9ced1de6 BP |
104 | const struct comedi_lrange *range_table; |
105 | const struct comedi_lrange *const *range_table_list; | |
ed9eccbe DS |
106 | |
107 | unsigned int *chanlist; /* driver-owned chanlist (not used) */ | |
108 | ||
0a85b6f0 MT |
109 | int (*insn_read) (struct comedi_device *, struct comedi_subdevice *, |
110 | struct comedi_insn *, unsigned int *); | |
111 | int (*insn_write) (struct comedi_device *, struct comedi_subdevice *, | |
112 | struct comedi_insn *, unsigned int *); | |
113 | int (*insn_bits) (struct comedi_device *, struct comedi_subdevice *, | |
114 | struct comedi_insn *, unsigned int *); | |
115 | int (*insn_config) (struct comedi_device *, struct comedi_subdevice *, | |
116 | struct comedi_insn *, unsigned int *); | |
ed9eccbe | 117 | |
34c43922 | 118 | int (*do_cmd) (struct comedi_device *, struct comedi_subdevice *); |
0a85b6f0 MT |
119 | int (*do_cmdtest) (struct comedi_device *, struct comedi_subdevice *, |
120 | struct comedi_cmd *); | |
34c43922 BP |
121 | int (*poll) (struct comedi_device *, struct comedi_subdevice *); |
122 | int (*cancel) (struct comedi_device *, struct comedi_subdevice *); | |
62eeae93 SW |
123 | /* int (*do_lock)(struct comedi_device *, struct comedi_subdevice *); */ |
124 | /* int (*do_unlock)(struct comedi_device *, \ | |
125 | struct comedi_subdevice *); */ | |
ed9eccbe DS |
126 | |
127 | /* called when the buffer changes */ | |
62eeae93 SW |
128 | int (*buf_change) (struct comedi_device *dev, |
129 | struct comedi_subdevice *s, unsigned long new_size); | |
ed9eccbe | 130 | |
62eeae93 | 131 | void (*munge) (struct comedi_device *dev, struct comedi_subdevice *s, |
0a85b6f0 MT |
132 | void *data, unsigned int num_bytes, |
133 | unsigned int start_chan_index); | |
ed9eccbe DS |
134 | enum dma_data_direction async_dma_dir; |
135 | ||
136 | unsigned int state; | |
137 | ||
0bfbbe8f | 138 | struct device *class_dev; |
ed9eccbe DS |
139 | int minor; |
140 | }; | |
141 | ||
142 | struct comedi_buf_page { | |
143 | void *virt_addr; | |
144 | dma_addr_t dma_addr; | |
145 | }; | |
146 | ||
d163679c | 147 | struct comedi_async { |
34c43922 | 148 | struct comedi_subdevice *subdevice; |
ed9eccbe DS |
149 | |
150 | void *prealloc_buf; /* pre-allocated buffer */ | |
151 | unsigned int prealloc_bufsz; /* buffer size, in bytes */ | |
62eeae93 SW |
152 | /* virtual and dma address of each page */ |
153 | struct comedi_buf_page *buf_page_list; | |
ed9eccbe DS |
154 | unsigned n_buf_pages; /* num elements in buf_page_list */ |
155 | ||
156 | unsigned int max_bufsize; /* maximum buffer size, bytes */ | |
62eeae93 SW |
157 | /* current number of mmaps of prealloc_buf */ |
158 | unsigned int mmap_count; | |
159 | ||
160 | /* byte count for writer (write completed) */ | |
161 | unsigned int buf_write_count; | |
162 | /* byte count for writer (allocated for writing) */ | |
163 | unsigned int buf_write_alloc_count; | |
164 | /* byte count for reader (read completed) */ | |
165 | unsigned int buf_read_count; | |
166 | /* byte count for reader (allocated for reading) */ | |
167 | unsigned int buf_read_alloc_count; | |
ed9eccbe DS |
168 | |
169 | unsigned int buf_write_ptr; /* buffer marker for writer */ | |
170 | unsigned int buf_read_ptr; /* buffer marker for reader */ | |
171 | ||
172 | unsigned int cur_chan; /* useless channel marker for interrupt */ | |
173 | /* number of bytes that have been received for current scan */ | |
174 | unsigned int scan_progress; | |
175 | /* keeps track of where we are in chanlist as for munging */ | |
176 | unsigned int munge_chan; | |
177 | /* number of bytes that have been munged */ | |
178 | unsigned int munge_count; | |
179 | /* buffer marker for munging */ | |
180 | unsigned int munge_ptr; | |
181 | ||
182 | unsigned int events; /* events that have occurred */ | |
183 | ||
ea6d0d4c | 184 | struct comedi_cmd cmd; |
ed9eccbe DS |
185 | |
186 | wait_queue_head_t wait_head; | |
187 | ||
e0dcef71 | 188 | /* callback stuff */ |
ed9eccbe DS |
189 | unsigned int cb_mask; |
190 | int (*cb_func) (unsigned int flags, void *); | |
191 | void *cb_arg; | |
192 | ||
62eeae93 | 193 | int (*inttrig) (struct comedi_device *dev, struct comedi_subdevice *s, |
e0dcef71 | 194 | unsigned int x); |
ed9eccbe DS |
195 | }; |
196 | ||
139dfbdf BP |
197 | struct comedi_driver { |
198 | struct comedi_driver *next; | |
ed9eccbe DS |
199 | |
200 | const char *driver_name; | |
201 | struct module *module; | |
0707bb04 | 202 | int (*attach) (struct comedi_device *, struct comedi_devconfig *); |
484ecc95 | 203 | void (*detach) (struct comedi_device *); |
8ed705af | 204 | int (*auto_attach) (struct comedi_device *, unsigned long); |
ed9eccbe DS |
205 | |
206 | /* number of elements in board_name and board_id arrays */ | |
207 | unsigned int num_names; | |
208 | const char *const *board_name; | |
209 | /* offset in bytes from one board name pointer to the next */ | |
210 | int offset; | |
211 | }; | |
212 | ||
71b5f4f1 | 213 | struct comedi_device { |
ed9eccbe | 214 | int use_count; |
139dfbdf | 215 | struct comedi_driver *driver; |
ed9eccbe DS |
216 | void *private; |
217 | ||
0bfbbe8f | 218 | struct device *class_dev; |
ed9eccbe | 219 | int minor; |
e0dcef71 GKH |
220 | /* hw_dev is passed to dma_alloc_coherent when allocating async buffers |
221 | * for subdevices that have async_dma_dir set to something other than | |
222 | * DMA_NONE */ | |
ed9eccbe DS |
223 | struct device *hw_dev; |
224 | ||
225 | const char *board_name; | |
226 | const void *board_ptr; | |
227 | int attached; | |
ed9eccbe DS |
228 | spinlock_t spinlock; |
229 | struct mutex mutex; | |
230 | int in_request_module; | |
231 | ||
232 | int n_subdevices; | |
34c43922 | 233 | struct comedi_subdevice *subdevices; |
ed9eccbe DS |
234 | |
235 | /* dumb */ | |
236 | unsigned long iobase; | |
237 | unsigned int irq; | |
238 | ||
34c43922 BP |
239 | struct comedi_subdevice *read_subdev; |
240 | struct comedi_subdevice *write_subdev; | |
ed9eccbe DS |
241 | |
242 | struct fasync_struct *async_queue; | |
243 | ||
3c17ba07 | 244 | int (*open) (struct comedi_device *dev); |
62eeae93 | 245 | void (*close) (struct comedi_device *dev); |
ed9eccbe DS |
246 | }; |
247 | ||
4dba6c02 | 248 | static inline const void *comedi_board(const struct comedi_device *dev) |
37859f88 HS |
249 | { |
250 | return dev->board_ptr; | |
251 | } | |
252 | ||
ed9eccbe DS |
253 | #ifdef CONFIG_COMEDI_DEBUG |
254 | extern int comedi_debug; | |
255 | #else | |
e0dcef71 | 256 | static const int comedi_debug; |
ed9eccbe DS |
257 | #endif |
258 | ||
259 | /* | |
260 | * function prototypes | |
261 | */ | |
262 | ||
34c43922 | 263 | void comedi_event(struct comedi_device *dev, struct comedi_subdevice *s); |
71b5f4f1 | 264 | void comedi_error(const struct comedi_device *dev, const char *s); |
ed9eccbe DS |
265 | |
266 | /* we can expand the number of bits used to encode devices/subdevices into | |
267 | the minor number soon, after more distros support > 8 bit minor numbers | |
268 | (like after Debian Etch gets released) */ | |
269 | enum comedi_minor_bits { | |
270 | COMEDI_DEVICE_MINOR_MASK = 0xf, | |
271 | COMEDI_SUBDEVICE_MINOR_MASK = 0xf0 | |
272 | }; | |
273 | static const unsigned COMEDI_SUBDEVICE_MINOR_SHIFT = 4; | |
274 | static const unsigned COMEDI_SUBDEVICE_MINOR_OFFSET = 1; | |
275 | ||
85104e9b HS |
276 | struct comedi_device *comedi_dev_from_minor(unsigned minor); |
277 | ||
8b9ba6e5 | 278 | int comedi_alloc_subdevices(struct comedi_device *, int); |
2f0b9d08 | 279 | |
71b5f4f1 | 280 | void comedi_device_detach(struct comedi_device *dev); |
0a85b6f0 MT |
281 | int comedi_device_attach(struct comedi_device *dev, |
282 | struct comedi_devconfig *it); | |
139dfbdf BP |
283 | int comedi_driver_register(struct comedi_driver *); |
284 | int comedi_driver_unregister(struct comedi_driver *); | |
ed9eccbe | 285 | |
20416257 HS |
286 | /** |
287 | * module_comedi_driver() - Helper macro for registering a comedi driver | |
288 | * @__comedi_driver: comedi_driver struct | |
289 | * | |
290 | * Helper macro for comedi drivers which do not do anything special in module | |
291 | * init/exit. This eliminates a lot of boilerplate. Each module may only use | |
292 | * this macro once, and calling it replaces module_init() and module_exit(). | |
293 | */ | |
294 | #define module_comedi_driver(__comedi_driver) \ | |
295 | module_driver(__comedi_driver, comedi_driver_register, \ | |
296 | comedi_driver_unregister) | |
297 | ||
55c03cff HS |
298 | int comedi_pci_enable(struct pci_dev *, const char *); |
299 | void comedi_pci_disable(struct pci_dev *); | |
d4899c6f HS |
300 | |
301 | int comedi_pci_driver_register(struct comedi_driver *, struct pci_driver *); | |
302 | void comedi_pci_driver_unregister(struct comedi_driver *, struct pci_driver *); | |
303 | ||
304 | /** | |
305 | * module_comedi_pci_driver() - Helper macro for registering a comedi PCI driver | |
306 | * @__comedi_driver: comedi_driver struct | |
307 | * @__pci_driver: pci_driver struct | |
308 | * | |
309 | * Helper macro for comedi PCI drivers which do not do anything special | |
310 | * in module init/exit. This eliminates a lot of boilerplate. Each | |
311 | * module may only use this macro once, and calling it replaces | |
312 | * module_init() and module_exit() | |
313 | */ | |
314 | #define module_comedi_pci_driver(__comedi_driver, __pci_driver) \ | |
315 | module_driver(__comedi_driver, comedi_pci_driver_register, \ | |
316 | comedi_pci_driver_unregister, &(__pci_driver)) | |
317 | ||
64255031 HS |
318 | struct usb_driver; |
319 | ||
320 | int comedi_usb_driver_register(struct comedi_driver *, struct usb_driver *); | |
321 | void comedi_usb_driver_unregister(struct comedi_driver *, struct usb_driver *); | |
322 | ||
323 | /** | |
324 | * module_comedi_usb_driver() - Helper macro for registering a comedi USB driver | |
325 | * @__comedi_driver: comedi_driver struct | |
326 | * @__usb_driver: usb_driver struct | |
327 | * | |
328 | * Helper macro for comedi USB drivers which do not do anything special | |
329 | * in module init/exit. This eliminates a lot of boilerplate. Each | |
330 | * module may only use this macro once, and calling it replaces | |
331 | * module_init() and module_exit() | |
332 | */ | |
333 | #define module_comedi_usb_driver(__comedi_driver, __usb_driver) \ | |
334 | module_driver(__comedi_driver, comedi_usb_driver_register, \ | |
335 | comedi_usb_driver_unregister, &(__usb_driver)) | |
336 | ||
ed9eccbe DS |
337 | void init_polling(void); |
338 | void cleanup_polling(void); | |
71b5f4f1 BP |
339 | void start_polling(struct comedi_device *); |
340 | void stop_polling(struct comedi_device *); | |
ed9eccbe | 341 | |
ed9eccbe DS |
342 | #ifdef CONFIG_PROC_FS |
343 | void comedi_proc_init(void); | |
344 | void comedi_proc_cleanup(void); | |
345 | #else | |
346 | static inline void comedi_proc_init(void) | |
347 | { | |
348 | } | |
0a85b6f0 | 349 | |
ed9eccbe DS |
350 | static inline void comedi_proc_cleanup(void) |
351 | { | |
352 | } | |
353 | #endif | |
354 | ||
355 | /* subdevice runflags */ | |
356 | enum subdevice_runflags { | |
357 | SRF_USER = 0x00000001, | |
358 | SRF_RT = 0x00000002, | |
e0dcef71 GKH |
359 | /* indicates an COMEDI_CB_ERROR event has occurred since the last |
360 | * command was started */ | |
ed9eccbe DS |
361 | SRF_ERROR = 0x00000004, |
362 | SRF_RUNNING = 0x08000000 | |
363 | }; | |
364 | ||
5e220112 MR |
365 | int comedi_check_chanlist(struct comedi_subdevice *s, |
366 | int n, | |
367 | unsigned int *chanlist); | |
34c43922 | 368 | unsigned comedi_get_subdevice_runflags(struct comedi_subdevice *s); |
ed9eccbe DS |
369 | |
370 | /* range stuff */ | |
371 | ||
e0dcef71 GKH |
372 | #define RANGE(a, b) {(a)*1e6, (b)*1e6, 0} |
373 | #define RANGE_ext(a, b) {(a)*1e6, (b)*1e6, RF_EXTERNAL} | |
374 | #define RANGE_mA(a, b) {(a)*1e6, (b)*1e6, UNIT_mA} | |
baf22b64 | 375 | #define RANGE_unitless(a, b) {(a)*1e6, (b)*1e6, 0} |
e0dcef71 GKH |
376 | #define BIP_RANGE(a) {-(a)*1e6, (a)*1e6, 0} |
377 | #define UNI_RANGE(a) {0, (a)*1e6, 0} | |
ed9eccbe | 378 | |
9ced1de6 BP |
379 | extern const struct comedi_lrange range_bipolar10; |
380 | extern const struct comedi_lrange range_bipolar5; | |
381 | extern const struct comedi_lrange range_bipolar2_5; | |
382 | extern const struct comedi_lrange range_unipolar10; | |
383 | extern const struct comedi_lrange range_unipolar5; | |
384 | extern const struct comedi_lrange range_unknown; | |
ed9eccbe DS |
385 | |
386 | #define range_digital range_unipolar5 | |
387 | ||
388 | #if __GNUC__ >= 3 | |
389 | #define GCC_ZERO_LENGTH_ARRAY | |
390 | #else | |
391 | #define GCC_ZERO_LENGTH_ARRAY 0 | |
392 | #endif | |
393 | ||
9ced1de6 | 394 | struct comedi_lrange { |
ed9eccbe | 395 | int length; |
1f6325d6 | 396 | struct comedi_krange range[GCC_ZERO_LENGTH_ARRAY]; |
ed9eccbe DS |
397 | }; |
398 | ||
399 | /* some silly little inline functions */ | |
400 | ||
34c43922 | 401 | static inline unsigned int bytes_per_sample(const struct comedi_subdevice *subd) |
ed9eccbe DS |
402 | { |
403 | if (subd->subdev_flags & SDF_LSAMPL) | |
790c5541 | 404 | return sizeof(unsigned int); |
ed9eccbe | 405 | else |
790c5541 | 406 | return sizeof(short); |
ed9eccbe DS |
407 | } |
408 | ||
409 | /* must be used in attach to set dev->hw_dev if you wish to dma directly | |
410 | into comedi's buffer */ | |
0a85b6f0 MT |
411 | static inline void comedi_set_hw_dev(struct comedi_device *dev, |
412 | struct device *hw_dev) | |
ed9eccbe | 413 | { |
0a7717df IA |
414 | if (dev->hw_dev == hw_dev) |
415 | return; | |
e0dcef71 | 416 | if (dev->hw_dev) |
ed9eccbe | 417 | put_device(dev->hw_dev); |
ed9eccbe DS |
418 | dev->hw_dev = hw_dev; |
419 | if (dev->hw_dev) { | |
420 | dev->hw_dev = get_device(dev->hw_dev); | |
421 | BUG_ON(dev->hw_dev == NULL); | |
422 | } | |
423 | } | |
424 | ||
ddb01367 HS |
425 | static inline struct pci_dev *comedi_to_pci_dev(struct comedi_device *dev) |
426 | { | |
427 | return dev->hw_dev ? to_pci_dev(dev->hw_dev) : NULL; | |
428 | } | |
429 | ||
0a577b82 IA |
430 | static inline struct usb_interface * |
431 | comedi_to_usb_interface(struct comedi_device *dev) | |
432 | { | |
433 | return dev->hw_dev ? to_usb_interface(dev->hw_dev) : NULL; | |
434 | } | |
435 | ||
d163679c BP |
436 | int comedi_buf_put(struct comedi_async *async, short x); |
437 | int comedi_buf_get(struct comedi_async *async, short *x); | |
ed9eccbe | 438 | |
d163679c | 439 | unsigned int comedi_buf_write_n_available(struct comedi_async *async); |
0a85b6f0 MT |
440 | unsigned int comedi_buf_write_alloc(struct comedi_async *async, |
441 | unsigned int nbytes); | |
d163679c | 442 | unsigned int comedi_buf_write_alloc_strict(struct comedi_async *async, |
0a85b6f0 | 443 | unsigned int nbytes); |
d163679c BP |
444 | unsigned comedi_buf_write_free(struct comedi_async *async, unsigned int nbytes); |
445 | unsigned comedi_buf_read_alloc(struct comedi_async *async, unsigned nbytes); | |
446 | unsigned comedi_buf_read_free(struct comedi_async *async, unsigned int nbytes); | |
447 | unsigned int comedi_buf_read_n_available(struct comedi_async *async); | |
448 | void comedi_buf_memcpy_to(struct comedi_async *async, unsigned int offset, | |
0a85b6f0 | 449 | const void *source, unsigned int num_bytes); |
d163679c | 450 | void comedi_buf_memcpy_from(struct comedi_async *async, unsigned int offset, |
0a85b6f0 | 451 | void *destination, unsigned int num_bytes); |
d163679c | 452 | static inline unsigned comedi_buf_write_n_allocated(struct comedi_async *async) |
ed9eccbe DS |
453 | { |
454 | return async->buf_write_alloc_count - async->buf_write_count; | |
455 | } | |
0a85b6f0 | 456 | |
d163679c | 457 | static inline unsigned comedi_buf_read_n_allocated(struct comedi_async *async) |
ed9eccbe DS |
458 | { |
459 | return async->buf_read_alloc_count - async->buf_read_count; | |
460 | } | |
461 | ||
ed9eccbe DS |
462 | static inline void *comedi_aux_data(int options[], int n) |
463 | { | |
464 | unsigned long address; | |
465 | unsigned long addressLow; | |
466 | int bit_shift; | |
467 | if (sizeof(int) >= sizeof(void *)) | |
468 | address = options[COMEDI_DEVCONF_AUX_DATA_LO]; | |
469 | else { | |
470 | address = options[COMEDI_DEVCONF_AUX_DATA_HI]; | |
471 | bit_shift = sizeof(int) * 8; | |
472 | address <<= bit_shift; | |
473 | addressLow = options[COMEDI_DEVCONF_AUX_DATA_LO]; | |
474 | addressLow &= (1UL << bit_shift) - 1; | |
475 | address |= addressLow; | |
476 | } | |
477 | if (n >= 1) | |
478 | address += options[COMEDI_DEVCONF_AUX_DATA0_LENGTH]; | |
479 | if (n >= 2) | |
480 | address += options[COMEDI_DEVCONF_AUX_DATA1_LENGTH]; | |
481 | if (n >= 3) | |
482 | address += options[COMEDI_DEVCONF_AUX_DATA2_LENGTH]; | |
483 | BUG_ON(n > 3); | |
484 | return (void *)address; | |
485 | } | |
486 | ||
0a85b6f0 MT |
487 | int comedi_alloc_subdevice_minor(struct comedi_device *dev, |
488 | struct comedi_subdevice *s); | |
34c43922 | 489 | void comedi_free_subdevice_minor(struct comedi_subdevice *s); |
8ed705af IA |
490 | int comedi_auto_config(struct device *hardware_device, |
491 | struct comedi_driver *driver, unsigned long context); | |
492 | void comedi_auto_unconfig(struct device *hardware_device); | |
581a7dde IA |
493 | |
494 | static inline int comedi_pci_auto_config(struct pci_dev *pcidev, | |
495 | struct comedi_driver *driver) | |
496 | { | |
497 | return comedi_auto_config(&pcidev->dev, driver, 0); | |
498 | } | |
499 | ||
500 | static inline void comedi_pci_auto_unconfig(struct pci_dev *pcidev) | |
501 | { | |
502 | comedi_auto_unconfig(&pcidev->dev); | |
503 | } | |
504 | ||
505 | static inline int comedi_usb_auto_config(struct usb_interface *intf, | |
506 | struct comedi_driver *driver) | |
507 | { | |
508 | return comedi_auto_config(&intf->dev, driver, 0); | |
509 | } | |
510 | ||
511 | static inline void comedi_usb_auto_unconfig(struct usb_interface *intf) | |
512 | { | |
513 | comedi_auto_unconfig(&intf->dev); | |
514 | } | |
ed9eccbe | 515 | |
ed9eccbe | 516 | #endif /* _COMEDIDEV_H */ |