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> |
ed9eccbe DS |
43 | |
44 | #include "comedi.h" | |
45 | ||
e0dcef71 GKH |
46 | #define DPRINTK(format, args...) do { \ |
47 | if (comedi_debug) \ | |
48 | printk(KERN_DEBUG "comedi: " format , ## args); \ | |
49 | } while (0) | |
ed9eccbe | 50 | |
e0dcef71 | 51 | #define COMEDI_VERSION(a, b, c) (((a) << 16) + ((b) << 8) + (c)) |
62eeae93 SW |
52 | #define COMEDI_VERSION_CODE COMEDI_VERSION(COMEDI_MAJORVERSION, \ |
53 | COMEDI_MINORVERSION, COMEDI_MICROVERSION) | |
ed9eccbe DS |
54 | #define COMEDI_RELEASE VERSION |
55 | ||
56 | #define COMEDI_INITCLEANUP_NOMODULE(x) \ | |
57 | static int __init x ## _init_module(void) \ | |
51b713a6 | 58 | {return comedi_driver_register(&(x)); } \ |
ed9eccbe | 59 | static void __exit x ## _cleanup_module(void) \ |
51b713a6 | 60 | {comedi_driver_unregister(&(x)); } \ |
ed9eccbe | 61 | module_init(x ## _init_module); \ |
62eeae93 | 62 | module_exit(x ## _cleanup_module); |
ed9eccbe DS |
63 | |
64 | #define COMEDI_MODULE_MACROS \ | |
65 | MODULE_AUTHOR("Comedi http://www.comedi.org"); \ | |
66 | MODULE_DESCRIPTION("Comedi low-level driver"); \ | |
62eeae93 | 67 | MODULE_LICENSE("GPL"); |
ed9eccbe DS |
68 | |
69 | #define COMEDI_INITCLEANUP(x) \ | |
70 | COMEDI_MODULE_MACROS \ | |
71 | COMEDI_INITCLEANUP_NOMODULE(x) | |
72 | ||
73 | #define COMEDI_PCI_INITCLEANUP_NOMODULE(comedi_driver, pci_id_table) \ | |
74 | static int __devinit comedi_driver ## _pci_probe(struct pci_dev *dev, \ | |
75 | const struct pci_device_id *ent) \ | |
76 | { \ | |
77 | return comedi_pci_auto_config(dev, comedi_driver.driver_name); \ | |
78 | } \ | |
62eeae93 SW |
79 | static void __devexit comedi_driver ## _pci_remove(\ |
80 | struct pci_dev *dev) \ | |
ed9eccbe DS |
81 | { \ |
82 | comedi_pci_auto_unconfig(dev); \ | |
83 | } \ | |
84 | static struct pci_driver comedi_driver ## _pci_driver = \ | |
85 | { \ | |
86 | .id_table = pci_id_table, \ | |
e0dcef71 GKH |
87 | .probe = &comedi_driver ## _pci_probe, \ |
88 | .remove = __devexit_p(&comedi_driver ## _pci_remove) \ | |
ed9eccbe DS |
89 | }; \ |
90 | static int __init comedi_driver ## _init_module(void) \ | |
91 | { \ | |
92 | int retval; \ | |
e0dcef71 GKH |
93 | retval = comedi_driver_register(&comedi_driver); \ |
94 | if (retval < 0) \ | |
95 | return retval; \ | |
62eeae93 SW |
96 | comedi_driver ## _pci_driver.name = \ |
97 | (char *)comedi_driver.driver_name; \ | |
e0dcef71 | 98 | return pci_register_driver(&comedi_driver ## _pci_driver); \ |
ed9eccbe DS |
99 | } \ |
100 | static void __exit comedi_driver ## _cleanup_module(void) \ | |
101 | { \ | |
e0dcef71 GKH |
102 | pci_unregister_driver(&comedi_driver ## _pci_driver); \ |
103 | comedi_driver_unregister(&comedi_driver); \ | |
ed9eccbe DS |
104 | } \ |
105 | module_init(comedi_driver ## _init_module); \ | |
106 | module_exit(comedi_driver ## _cleanup_module); | |
107 | ||
108 | #define COMEDI_PCI_INITCLEANUP(comedi_driver, pci_id_table) \ | |
109 | COMEDI_MODULE_MACROS \ | |
110 | COMEDI_PCI_INITCLEANUP_NOMODULE(comedi_driver, pci_id_table) | |
111 | ||
112 | #define PCI_VENDOR_ID_INOVA 0x104c | |
113 | #define PCI_VENDOR_ID_NATINST 0x1093 | |
114 | #define PCI_VENDOR_ID_DATX 0x1116 | |
115 | #define PCI_VENDOR_ID_COMPUTERBOARDS 0x1307 | |
116 | #define PCI_VENDOR_ID_ADVANTECH 0x13fe | |
117 | #define PCI_VENDOR_ID_RTD 0x1435 | |
118 | #define PCI_VENDOR_ID_AMPLICON 0x14dc | |
119 | #define PCI_VENDOR_ID_ADLINK 0x144a | |
120 | #define PCI_VENDOR_ID_ICP 0x104c | |
121 | #define PCI_VENDOR_ID_CONTEC 0x1221 | |
122 | #define PCI_VENDOR_ID_MEILHAUS 0x1402 | |
123 | ||
124 | #define COMEDI_NUM_MINORS 0x100 | |
ed9eccbe DS |
125 | #define COMEDI_NUM_BOARD_MINORS 0x30 |
126 | #define COMEDI_FIRST_SUBDEVICE_MINOR COMEDI_NUM_BOARD_MINORS | |
127 | ||
ed9eccbe DS |
128 | #define COMEDI_DEVICE_CREATE(cs, parent, devt, drvdata, device, fmt...) \ |
129 | device_create(cs, ((parent) ? (parent) : (device)), devt, drvdata, fmt) | |
130 | ||
34c43922 | 131 | struct comedi_subdevice { |
71b5f4f1 | 132 | struct comedi_device *device; |
ed9eccbe DS |
133 | int type; |
134 | int n_chan; | |
135 | volatile int subdev_flags; | |
136 | int len_chanlist; /* maximum length of channel/gain list */ | |
137 | ||
138 | void *private; | |
139 | ||
d163679c | 140 | struct comedi_async *async; |
ed9eccbe DS |
141 | |
142 | void *lock; | |
143 | void *busy; | |
144 | unsigned runflags; | |
145 | spinlock_t spin_lock; | |
146 | ||
147 | int io_bits; | |
148 | ||
790c5541 BP |
149 | unsigned int maxdata; /* if maxdata==0, use list */ |
150 | const unsigned int *maxdata_list; /* list is channel specific */ | |
ed9eccbe DS |
151 | |
152 | unsigned int flags; | |
153 | const unsigned int *flaglist; | |
154 | ||
155 | unsigned int settling_time_0; | |
156 | ||
9ced1de6 BP |
157 | const struct comedi_lrange *range_table; |
158 | const struct comedi_lrange *const *range_table_list; | |
ed9eccbe DS |
159 | |
160 | unsigned int *chanlist; /* driver-owned chanlist (not used) */ | |
161 | ||
0a85b6f0 MT |
162 | int (*insn_read) (struct comedi_device *, struct comedi_subdevice *, |
163 | struct comedi_insn *, unsigned int *); | |
164 | int (*insn_write) (struct comedi_device *, struct comedi_subdevice *, | |
165 | struct comedi_insn *, unsigned int *); | |
166 | int (*insn_bits) (struct comedi_device *, struct comedi_subdevice *, | |
167 | struct comedi_insn *, unsigned int *); | |
168 | int (*insn_config) (struct comedi_device *, struct comedi_subdevice *, | |
169 | struct comedi_insn *, unsigned int *); | |
ed9eccbe | 170 | |
34c43922 | 171 | int (*do_cmd) (struct comedi_device *, struct comedi_subdevice *); |
0a85b6f0 MT |
172 | int (*do_cmdtest) (struct comedi_device *, struct comedi_subdevice *, |
173 | struct comedi_cmd *); | |
34c43922 BP |
174 | int (*poll) (struct comedi_device *, struct comedi_subdevice *); |
175 | int (*cancel) (struct comedi_device *, struct comedi_subdevice *); | |
62eeae93 SW |
176 | /* int (*do_lock)(struct comedi_device *, struct comedi_subdevice *); */ |
177 | /* int (*do_unlock)(struct comedi_device *, \ | |
178 | struct comedi_subdevice *); */ | |
ed9eccbe DS |
179 | |
180 | /* called when the buffer changes */ | |
62eeae93 SW |
181 | int (*buf_change) (struct comedi_device *dev, |
182 | struct comedi_subdevice *s, unsigned long new_size); | |
ed9eccbe | 183 | |
62eeae93 | 184 | void (*munge) (struct comedi_device *dev, struct comedi_subdevice *s, |
0a85b6f0 MT |
185 | void *data, unsigned int num_bytes, |
186 | unsigned int start_chan_index); | |
ed9eccbe DS |
187 | enum dma_data_direction async_dma_dir; |
188 | ||
189 | unsigned int state; | |
190 | ||
0bfbbe8f | 191 | struct device *class_dev; |
ed9eccbe DS |
192 | int minor; |
193 | }; | |
194 | ||
195 | struct comedi_buf_page { | |
196 | void *virt_addr; | |
197 | dma_addr_t dma_addr; | |
198 | }; | |
199 | ||
d163679c | 200 | struct comedi_async { |
34c43922 | 201 | struct comedi_subdevice *subdevice; |
ed9eccbe DS |
202 | |
203 | void *prealloc_buf; /* pre-allocated buffer */ | |
204 | unsigned int prealloc_bufsz; /* buffer size, in bytes */ | |
62eeae93 SW |
205 | /* virtual and dma address of each page */ |
206 | struct comedi_buf_page *buf_page_list; | |
ed9eccbe DS |
207 | unsigned n_buf_pages; /* num elements in buf_page_list */ |
208 | ||
209 | unsigned int max_bufsize; /* maximum buffer size, bytes */ | |
62eeae93 SW |
210 | /* current number of mmaps of prealloc_buf */ |
211 | unsigned int mmap_count; | |
212 | ||
213 | /* byte count for writer (write completed) */ | |
214 | unsigned int buf_write_count; | |
215 | /* byte count for writer (allocated for writing) */ | |
216 | unsigned int buf_write_alloc_count; | |
217 | /* byte count for reader (read completed) */ | |
218 | unsigned int buf_read_count; | |
219 | /* byte count for reader (allocated for reading) */ | |
220 | unsigned int buf_read_alloc_count; | |
ed9eccbe DS |
221 | |
222 | unsigned int buf_write_ptr; /* buffer marker for writer */ | |
223 | unsigned int buf_read_ptr; /* buffer marker for reader */ | |
224 | ||
225 | unsigned int cur_chan; /* useless channel marker for interrupt */ | |
226 | /* number of bytes that have been received for current scan */ | |
227 | unsigned int scan_progress; | |
228 | /* keeps track of where we are in chanlist as for munging */ | |
229 | unsigned int munge_chan; | |
230 | /* number of bytes that have been munged */ | |
231 | unsigned int munge_count; | |
232 | /* buffer marker for munging */ | |
233 | unsigned int munge_ptr; | |
234 | ||
235 | unsigned int events; /* events that have occurred */ | |
236 | ||
ea6d0d4c | 237 | struct comedi_cmd cmd; |
ed9eccbe DS |
238 | |
239 | wait_queue_head_t wait_head; | |
240 | ||
e0dcef71 | 241 | /* callback stuff */ |
ed9eccbe DS |
242 | unsigned int cb_mask; |
243 | int (*cb_func) (unsigned int flags, void *); | |
244 | void *cb_arg; | |
245 | ||
62eeae93 | 246 | int (*inttrig) (struct comedi_device *dev, struct comedi_subdevice *s, |
e0dcef71 | 247 | unsigned int x); |
ed9eccbe DS |
248 | }; |
249 | ||
139dfbdf BP |
250 | struct comedi_driver { |
251 | struct comedi_driver *next; | |
ed9eccbe DS |
252 | |
253 | const char *driver_name; | |
254 | struct module *module; | |
0707bb04 | 255 | int (*attach) (struct comedi_device *, struct comedi_devconfig *); |
71b5f4f1 | 256 | int (*detach) (struct comedi_device *); |
ed9eccbe DS |
257 | |
258 | /* number of elements in board_name and board_id arrays */ | |
259 | unsigned int num_names; | |
260 | const char *const *board_name; | |
261 | /* offset in bytes from one board name pointer to the next */ | |
262 | int offset; | |
263 | }; | |
264 | ||
71b5f4f1 | 265 | struct comedi_device { |
ed9eccbe | 266 | int use_count; |
139dfbdf | 267 | struct comedi_driver *driver; |
ed9eccbe DS |
268 | void *private; |
269 | ||
0bfbbe8f | 270 | struct device *class_dev; |
ed9eccbe | 271 | int minor; |
e0dcef71 GKH |
272 | /* hw_dev is passed to dma_alloc_coherent when allocating async buffers |
273 | * for subdevices that have async_dma_dir set to something other than | |
274 | * DMA_NONE */ | |
ed9eccbe DS |
275 | struct device *hw_dev; |
276 | ||
277 | const char *board_name; | |
278 | const void *board_ptr; | |
279 | int attached; | |
ed9eccbe DS |
280 | spinlock_t spinlock; |
281 | struct mutex mutex; | |
282 | int in_request_module; | |
283 | ||
284 | int n_subdevices; | |
34c43922 | 285 | struct comedi_subdevice *subdevices; |
ed9eccbe DS |
286 | |
287 | /* dumb */ | |
288 | unsigned long iobase; | |
289 | unsigned int irq; | |
290 | ||
34c43922 BP |
291 | struct comedi_subdevice *read_subdev; |
292 | struct comedi_subdevice *write_subdev; | |
ed9eccbe DS |
293 | |
294 | struct fasync_struct *async_queue; | |
295 | ||
62eeae93 SW |
296 | void (*open) (struct comedi_device *dev); |
297 | void (*close) (struct comedi_device *dev); | |
ed9eccbe DS |
298 | }; |
299 | ||
300 | struct comedi_device_file_info { | |
71b5f4f1 | 301 | struct comedi_device *device; |
34c43922 BP |
302 | struct comedi_subdevice *read_subdevice; |
303 | struct comedi_subdevice *write_subdevice; | |
ed9eccbe DS |
304 | }; |
305 | ||
306 | #ifdef CONFIG_COMEDI_DEBUG | |
307 | extern int comedi_debug; | |
308 | #else | |
e0dcef71 | 309 | static const int comedi_debug; |
ed9eccbe DS |
310 | #endif |
311 | ||
312 | /* | |
313 | * function prototypes | |
314 | */ | |
315 | ||
34c43922 | 316 | void comedi_event(struct comedi_device *dev, struct comedi_subdevice *s); |
71b5f4f1 | 317 | void comedi_error(const struct comedi_device *dev, const char *s); |
ed9eccbe DS |
318 | |
319 | /* we can expand the number of bits used to encode devices/subdevices into | |
320 | the minor number soon, after more distros support > 8 bit minor numbers | |
321 | (like after Debian Etch gets released) */ | |
322 | enum comedi_minor_bits { | |
323 | COMEDI_DEVICE_MINOR_MASK = 0xf, | |
324 | COMEDI_SUBDEVICE_MINOR_MASK = 0xf0 | |
325 | }; | |
326 | static const unsigned COMEDI_SUBDEVICE_MINOR_SHIFT = 4; | |
327 | static const unsigned COMEDI_SUBDEVICE_MINOR_OFFSET = 1; | |
328 | ||
e0dcef71 | 329 | struct comedi_device_file_info *comedi_get_device_file_info(unsigned minor); |
ed9eccbe | 330 | |
62eeae93 SW |
331 | static inline struct comedi_subdevice *comedi_get_read_subdevice( |
332 | const struct comedi_device_file_info *info) | |
ed9eccbe | 333 | { |
e0dcef71 GKH |
334 | if (info->read_subdevice) |
335 | return info->read_subdevice; | |
336 | if (info->device == NULL) | |
337 | return NULL; | |
ed9eccbe DS |
338 | return info->device->read_subdev; |
339 | } | |
340 | ||
62eeae93 SW |
341 | static inline struct comedi_subdevice *comedi_get_write_subdevice( |
342 | const struct comedi_device_file_info *info) | |
ed9eccbe | 343 | { |
e0dcef71 GKH |
344 | if (info->write_subdevice) |
345 | return info->write_subdevice; | |
346 | if (info->device == NULL) | |
347 | return NULL; | |
ed9eccbe DS |
348 | return info->device->write_subdev; |
349 | } | |
350 | ||
71b5f4f1 | 351 | void comedi_device_detach(struct comedi_device *dev); |
0a85b6f0 MT |
352 | int comedi_device_attach(struct comedi_device *dev, |
353 | struct comedi_devconfig *it); | |
139dfbdf BP |
354 | int comedi_driver_register(struct comedi_driver *); |
355 | int comedi_driver_unregister(struct comedi_driver *); | |
ed9eccbe DS |
356 | |
357 | void init_polling(void); | |
358 | void cleanup_polling(void); | |
71b5f4f1 BP |
359 | void start_polling(struct comedi_device *); |
360 | void stop_polling(struct comedi_device *); | |
ed9eccbe | 361 | |
0a85b6f0 MT |
362 | int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s, |
363 | unsigned long new_size); | |
ed9eccbe DS |
364 | |
365 | #ifdef CONFIG_PROC_FS | |
366 | void comedi_proc_init(void); | |
367 | void comedi_proc_cleanup(void); | |
368 | #else | |
369 | static inline void comedi_proc_init(void) | |
370 | { | |
371 | } | |
0a85b6f0 | 372 | |
ed9eccbe DS |
373 | static inline void comedi_proc_cleanup(void) |
374 | { | |
375 | } | |
376 | #endif | |
377 | ||
378 | /* subdevice runflags */ | |
379 | enum subdevice_runflags { | |
380 | SRF_USER = 0x00000001, | |
381 | SRF_RT = 0x00000002, | |
e0dcef71 GKH |
382 | /* indicates an COMEDI_CB_ERROR event has occurred since the last |
383 | * command was started */ | |
ed9eccbe DS |
384 | SRF_ERROR = 0x00000004, |
385 | SRF_RUNNING = 0x08000000 | |
386 | }; | |
387 | ||
388 | /* | |
389 | various internal comedi functions | |
390 | */ | |
391 | ||
d0a353f6 | 392 | int do_rangeinfo_ioctl(struct comedi_device *dev, struct comedi_rangeinfo *arg); |
34c43922 BP |
393 | int check_chanlist(struct comedi_subdevice *s, int n, unsigned int *chanlist); |
394 | void comedi_set_subdevice_runflags(struct comedi_subdevice *s, unsigned mask, | |
0a85b6f0 | 395 | unsigned bits); |
34c43922 BP |
396 | unsigned comedi_get_subdevice_runflags(struct comedi_subdevice *s); |
397 | int insn_inval(struct comedi_device *dev, struct comedi_subdevice *s, | |
0a85b6f0 | 398 | struct comedi_insn *insn, unsigned int *data); |
ed9eccbe DS |
399 | |
400 | /* range stuff */ | |
401 | ||
e0dcef71 GKH |
402 | #define RANGE(a, b) {(a)*1e6, (b)*1e6, 0} |
403 | #define RANGE_ext(a, b) {(a)*1e6, (b)*1e6, RF_EXTERNAL} | |
404 | #define RANGE_mA(a, b) {(a)*1e6, (b)*1e6, UNIT_mA} | |
405 | #define RANGE_unitless(a, b) {(a)*1e6, (b)*1e6, 0} /* XXX */ | |
406 | #define BIP_RANGE(a) {-(a)*1e6, (a)*1e6, 0} | |
407 | #define UNI_RANGE(a) {0, (a)*1e6, 0} | |
ed9eccbe | 408 | |
9ced1de6 BP |
409 | extern const struct comedi_lrange range_bipolar10; |
410 | extern const struct comedi_lrange range_bipolar5; | |
411 | extern const struct comedi_lrange range_bipolar2_5; | |
412 | extern const struct comedi_lrange range_unipolar10; | |
413 | extern const struct comedi_lrange range_unipolar5; | |
414 | extern const struct comedi_lrange range_unknown; | |
ed9eccbe DS |
415 | |
416 | #define range_digital range_unipolar5 | |
417 | ||
418 | #if __GNUC__ >= 3 | |
419 | #define GCC_ZERO_LENGTH_ARRAY | |
420 | #else | |
421 | #define GCC_ZERO_LENGTH_ARRAY 0 | |
422 | #endif | |
423 | ||
9ced1de6 | 424 | struct comedi_lrange { |
ed9eccbe | 425 | int length; |
1f6325d6 | 426 | struct comedi_krange range[GCC_ZERO_LENGTH_ARRAY]; |
ed9eccbe DS |
427 | }; |
428 | ||
429 | /* some silly little inline functions */ | |
430 | ||
71b5f4f1 | 431 | static inline int alloc_subdevices(struct comedi_device *dev, |
e0dcef71 | 432 | unsigned int num_subdevices) |
ed9eccbe DS |
433 | { |
434 | unsigned i; | |
435 | ||
436 | dev->n_subdevices = num_subdevices; | |
437 | dev->subdevices = | |
0a85b6f0 MT |
438 | kcalloc(num_subdevices, sizeof(struct comedi_subdevice), |
439 | GFP_KERNEL); | |
ed9eccbe DS |
440 | if (!dev->subdevices) |
441 | return -ENOMEM; | |
442 | for (i = 0; i < num_subdevices; ++i) { | |
443 | dev->subdevices[i].device = dev; | |
444 | dev->subdevices[i].async_dma_dir = DMA_NONE; | |
445 | spin_lock_init(&dev->subdevices[i].spin_lock); | |
446 | dev->subdevices[i].minor = -1; | |
447 | } | |
448 | return 0; | |
449 | } | |
450 | ||
71b5f4f1 | 451 | static inline int alloc_private(struct comedi_device *dev, int size) |
ed9eccbe DS |
452 | { |
453 | dev->private = kzalloc(size, GFP_KERNEL); | |
454 | if (!dev->private) | |
455 | return -ENOMEM; | |
456 | return 0; | |
457 | } | |
458 | ||
34c43922 | 459 | static inline unsigned int bytes_per_sample(const struct comedi_subdevice *subd) |
ed9eccbe DS |
460 | { |
461 | if (subd->subdev_flags & SDF_LSAMPL) | |
790c5541 | 462 | return sizeof(unsigned int); |
ed9eccbe | 463 | else |
790c5541 | 464 | return sizeof(short); |
ed9eccbe DS |
465 | } |
466 | ||
467 | /* must be used in attach to set dev->hw_dev if you wish to dma directly | |
468 | into comedi's buffer */ | |
0a85b6f0 MT |
469 | static inline void comedi_set_hw_dev(struct comedi_device *dev, |
470 | struct device *hw_dev) | |
ed9eccbe | 471 | { |
e0dcef71 | 472 | if (dev->hw_dev) |
ed9eccbe | 473 | put_device(dev->hw_dev); |
e0dcef71 | 474 | |
ed9eccbe DS |
475 | dev->hw_dev = hw_dev; |
476 | if (dev->hw_dev) { | |
477 | dev->hw_dev = get_device(dev->hw_dev); | |
478 | BUG_ON(dev->hw_dev == NULL); | |
479 | } | |
480 | } | |
481 | ||
d163679c BP |
482 | int comedi_buf_put(struct comedi_async *async, short x); |
483 | int comedi_buf_get(struct comedi_async *async, short *x); | |
ed9eccbe | 484 | |
d163679c | 485 | unsigned int comedi_buf_write_n_available(struct comedi_async *async); |
0a85b6f0 MT |
486 | unsigned int comedi_buf_write_alloc(struct comedi_async *async, |
487 | unsigned int nbytes); | |
d163679c | 488 | unsigned int comedi_buf_write_alloc_strict(struct comedi_async *async, |
0a85b6f0 | 489 | unsigned int nbytes); |
d163679c BP |
490 | unsigned comedi_buf_write_free(struct comedi_async *async, unsigned int nbytes); |
491 | unsigned comedi_buf_read_alloc(struct comedi_async *async, unsigned nbytes); | |
492 | unsigned comedi_buf_read_free(struct comedi_async *async, unsigned int nbytes); | |
493 | unsigned int comedi_buf_read_n_available(struct comedi_async *async); | |
494 | void comedi_buf_memcpy_to(struct comedi_async *async, unsigned int offset, | |
0a85b6f0 | 495 | const void *source, unsigned int num_bytes); |
d163679c | 496 | void comedi_buf_memcpy_from(struct comedi_async *async, unsigned int offset, |
0a85b6f0 | 497 | void *destination, unsigned int num_bytes); |
d163679c | 498 | static inline unsigned comedi_buf_write_n_allocated(struct comedi_async *async) |
ed9eccbe DS |
499 | { |
500 | return async->buf_write_alloc_count - async->buf_write_count; | |
501 | } | |
0a85b6f0 | 502 | |
d163679c | 503 | static inline unsigned comedi_buf_read_n_allocated(struct comedi_async *async) |
ed9eccbe DS |
504 | { |
505 | return async->buf_read_alloc_count - async->buf_read_count; | |
506 | } | |
507 | ||
d163679c | 508 | void comedi_reset_async_buf(struct comedi_async *async); |
ed9eccbe DS |
509 | |
510 | static inline void *comedi_aux_data(int options[], int n) | |
511 | { | |
512 | unsigned long address; | |
513 | unsigned long addressLow; | |
514 | int bit_shift; | |
515 | if (sizeof(int) >= sizeof(void *)) | |
516 | address = options[COMEDI_DEVCONF_AUX_DATA_LO]; | |
517 | else { | |
518 | address = options[COMEDI_DEVCONF_AUX_DATA_HI]; | |
519 | bit_shift = sizeof(int) * 8; | |
520 | address <<= bit_shift; | |
521 | addressLow = options[COMEDI_DEVCONF_AUX_DATA_LO]; | |
522 | addressLow &= (1UL << bit_shift) - 1; | |
523 | address |= addressLow; | |
524 | } | |
525 | if (n >= 1) | |
526 | address += options[COMEDI_DEVCONF_AUX_DATA0_LENGTH]; | |
527 | if (n >= 2) | |
528 | address += options[COMEDI_DEVCONF_AUX_DATA1_LENGTH]; | |
529 | if (n >= 3) | |
530 | address += options[COMEDI_DEVCONF_AUX_DATA2_LENGTH]; | |
531 | BUG_ON(n > 3); | |
532 | return (void *)address; | |
533 | } | |
534 | ||
535 | int comedi_alloc_board_minor(struct device *hardware_device); | |
536 | void comedi_free_board_minor(unsigned minor); | |
0a85b6f0 MT |
537 | int comedi_alloc_subdevice_minor(struct comedi_device *dev, |
538 | struct comedi_subdevice *s); | |
34c43922 | 539 | void comedi_free_subdevice_minor(struct comedi_subdevice *s); |
ed9eccbe DS |
540 | int comedi_pci_auto_config(struct pci_dev *pcidev, const char *board_name); |
541 | void comedi_pci_auto_unconfig(struct pci_dev *pcidev); | |
0a85b6f0 | 542 | struct usb_device; /* forward declaration */ |
c28264da BP |
543 | int comedi_usb_auto_config(struct usb_device *usbdev, const char *board_name); |
544 | void comedi_usb_auto_unconfig(struct usb_device *usbdev); | |
ed9eccbe | 545 | |
056d3ce5 | 546 | #ifdef CONFIG_COMEDI_PCI_DRIVERS |
0a85b6f0 | 547 | #define CONFIG_COMEDI_PCI |
056d3ce5 GKH |
548 | #endif |
549 | #ifdef CONFIG_COMEDI_PCI_DRIVERS_MODULE | |
0a85b6f0 | 550 | #define CONFIG_COMEDI_PCI |
056d3ce5 GKH |
551 | #endif |
552 | #ifdef CONFIG_COMEDI_PCMCIA_DRIVERS | |
0a85b6f0 | 553 | #define CONFIG_COMEDI_PCMCIA |
056d3ce5 GKH |
554 | #endif |
555 | #ifdef CONFIG_COMEDI_PCMCIA_DRIVERS_MODULE | |
0a85b6f0 | 556 | #define CONFIG_COMEDI_PCMCIA |
056d3ce5 GKH |
557 | #endif |
558 | ||
ed9eccbe | 559 | #endif /* _COMEDIDEV_H */ |