David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 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> |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 29 | #include <linux/kdev_t.h> |
| 30 | #include <linux/slab.h> |
Randy Dunlap | f9c5137 | 2009-06-05 11:10:42 -0700 | [diff] [blame] | 31 | #include <linux/delay.h> |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 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> |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 39 | #include <linux/dma-mapping.h> |
Greg Kroah-Hartman | e0dcef7 | 2008-11-13 16:36:22 -0800 | [diff] [blame] | 40 | #include <linux/uaccess.h> |
| 41 | #include <linux/io.h> |
Greg Kroah-Hartman | c7a5d70 | 2009-06-19 11:04:32 -0700 | [diff] [blame] | 42 | #include <linux/timer.h> |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 43 | |
| 44 | #include "comedi.h" |
| 45 | |
Greg Kroah-Hartman | e0dcef7 | 2008-11-13 16:36:22 -0800 | [diff] [blame] | 46 | #define DPRINTK(format, args...) do { \ |
| 47 | if (comedi_debug) \ |
Ian Abbott | 4f870fe | 2012-08-16 14:38:05 +0100 | [diff] [blame] | 48 | pr_debug("comedi: " format, ## args); \ |
Greg Kroah-Hartman | e0dcef7 | 2008-11-13 16:36:22 -0800 | [diff] [blame] | 49 | } while (0) |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 50 | |
Greg Kroah-Hartman | e0dcef7 | 2008-11-13 16:36:22 -0800 | [diff] [blame] | 51 | #define COMEDI_VERSION(a, b, c) (((a) << 16) + ((b) << 8) + (c)) |
Shane Warden | 62eeae9 | 2009-09-22 16:13:04 -0700 | [diff] [blame] | 52 | #define COMEDI_VERSION_CODE COMEDI_VERSION(COMEDI_MAJORVERSION, \ |
| 53 | COMEDI_MINORVERSION, COMEDI_MICROVERSION) |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 54 | #define COMEDI_RELEASE VERSION |
| 55 | |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 56 | #define COMEDI_NUM_MINORS 0x100 |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 57 | #define COMEDI_NUM_BOARD_MINORS 0x30 |
| 58 | #define COMEDI_FIRST_SUBDEVICE_MINOR COMEDI_NUM_BOARD_MINORS |
| 59 | |
Bill Pemberton | 34c4392 | 2009-03-16 22:05:14 -0400 | [diff] [blame] | 60 | struct comedi_subdevice { |
Bill Pemberton | 71b5f4f | 2009-03-16 22:05:08 -0400 | [diff] [blame] | 61 | struct comedi_device *device; |
H Hartley Sweeten | 90a35c1 | 2012-12-19 17:27:02 -0700 | [diff] [blame] | 62 | int index; |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 63 | int type; |
| 64 | int n_chan; |
Greg Kroah-Hartman | baf22b6 | 2010-04-30 15:26:54 -0700 | [diff] [blame] | 65 | int subdev_flags; |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 66 | int len_chanlist; /* maximum length of channel/gain list */ |
| 67 | |
| 68 | void *private; |
| 69 | |
Bill Pemberton | d163679 | 2009-03-16 22:05:20 -0400 | [diff] [blame] | 70 | struct comedi_async *async; |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 71 | |
| 72 | void *lock; |
| 73 | void *busy; |
| 74 | unsigned runflags; |
| 75 | spinlock_t spin_lock; |
| 76 | |
H Hartley Sweeten | d4a7dc8 | 2012-06-18 14:45:42 -0700 | [diff] [blame] | 77 | unsigned int io_bits; |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 78 | |
Bill Pemberton | 790c554 | 2009-03-16 22:05:02 -0400 | [diff] [blame] | 79 | unsigned int maxdata; /* if maxdata==0, use list */ |
| 80 | const unsigned int *maxdata_list; /* list is channel specific */ |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 81 | |
| 82 | unsigned int flags; |
| 83 | const unsigned int *flaglist; |
| 84 | |
| 85 | unsigned int settling_time_0; |
| 86 | |
Bill Pemberton | 9ced1de | 2009-03-16 22:05:31 -0400 | [diff] [blame] | 87 | const struct comedi_lrange *range_table; |
| 88 | const struct comedi_lrange *const *range_table_list; |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 89 | |
| 90 | unsigned int *chanlist; /* driver-owned chanlist (not used) */ |
| 91 | |
Mithlesh Thukral | 0a85b6f | 2009-06-08 21:04:41 +0530 | [diff] [blame] | 92 | int (*insn_read) (struct comedi_device *, struct comedi_subdevice *, |
| 93 | struct comedi_insn *, unsigned int *); |
| 94 | int (*insn_write) (struct comedi_device *, struct comedi_subdevice *, |
| 95 | struct comedi_insn *, unsigned int *); |
| 96 | int (*insn_bits) (struct comedi_device *, struct comedi_subdevice *, |
| 97 | struct comedi_insn *, unsigned int *); |
| 98 | int (*insn_config) (struct comedi_device *, struct comedi_subdevice *, |
| 99 | struct comedi_insn *, unsigned int *); |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 100 | |
Bill Pemberton | 34c4392 | 2009-03-16 22:05:14 -0400 | [diff] [blame] | 101 | int (*do_cmd) (struct comedi_device *, struct comedi_subdevice *); |
Mithlesh Thukral | 0a85b6f | 2009-06-08 21:04:41 +0530 | [diff] [blame] | 102 | int (*do_cmdtest) (struct comedi_device *, struct comedi_subdevice *, |
| 103 | struct comedi_cmd *); |
Bill Pemberton | 34c4392 | 2009-03-16 22:05:14 -0400 | [diff] [blame] | 104 | int (*poll) (struct comedi_device *, struct comedi_subdevice *); |
| 105 | int (*cancel) (struct comedi_device *, struct comedi_subdevice *); |
Shane Warden | 62eeae9 | 2009-09-22 16:13:04 -0700 | [diff] [blame] | 106 | /* int (*do_lock)(struct comedi_device *, struct comedi_subdevice *); */ |
| 107 | /* int (*do_unlock)(struct comedi_device *, \ |
| 108 | struct comedi_subdevice *); */ |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 109 | |
| 110 | /* called when the buffer changes */ |
Shane Warden | 62eeae9 | 2009-09-22 16:13:04 -0700 | [diff] [blame] | 111 | int (*buf_change) (struct comedi_device *dev, |
| 112 | struct comedi_subdevice *s, unsigned long new_size); |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 113 | |
Shane Warden | 62eeae9 | 2009-09-22 16:13:04 -0700 | [diff] [blame] | 114 | void (*munge) (struct comedi_device *dev, struct comedi_subdevice *s, |
Mithlesh Thukral | 0a85b6f | 2009-06-08 21:04:41 +0530 | [diff] [blame] | 115 | void *data, unsigned int num_bytes, |
| 116 | unsigned int start_chan_index); |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 117 | enum dma_data_direction async_dma_dir; |
| 118 | |
| 119 | unsigned int state; |
| 120 | |
Bill Pemberton | 0bfbbe8 | 2009-03-16 22:05:36 -0400 | [diff] [blame] | 121 | struct device *class_dev; |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 122 | int minor; |
| 123 | }; |
| 124 | |
| 125 | struct comedi_buf_page { |
| 126 | void *virt_addr; |
| 127 | dma_addr_t dma_addr; |
| 128 | }; |
| 129 | |
Bill Pemberton | d163679 | 2009-03-16 22:05:20 -0400 | [diff] [blame] | 130 | struct comedi_async { |
Bill Pemberton | 34c4392 | 2009-03-16 22:05:14 -0400 | [diff] [blame] | 131 | struct comedi_subdevice *subdevice; |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 132 | |
| 133 | void *prealloc_buf; /* pre-allocated buffer */ |
| 134 | unsigned int prealloc_bufsz; /* buffer size, in bytes */ |
Shane Warden | 62eeae9 | 2009-09-22 16:13:04 -0700 | [diff] [blame] | 135 | /* virtual and dma address of each page */ |
| 136 | struct comedi_buf_page *buf_page_list; |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 137 | unsigned n_buf_pages; /* num elements in buf_page_list */ |
| 138 | |
| 139 | unsigned int max_bufsize; /* maximum buffer size, bytes */ |
Shane Warden | 62eeae9 | 2009-09-22 16:13:04 -0700 | [diff] [blame] | 140 | /* current number of mmaps of prealloc_buf */ |
| 141 | unsigned int mmap_count; |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 142 | |
Shane Warden | 62eeae9 | 2009-09-22 16:13:04 -0700 | [diff] [blame] | 143 | /* byte count for writer (write completed) */ |
| 144 | unsigned int buf_write_count; |
| 145 | /* byte count for writer (allocated for writing) */ |
| 146 | unsigned int buf_write_alloc_count; |
| 147 | /* byte count for reader (read completed) */ |
| 148 | unsigned int buf_read_count; |
| 149 | /* byte count for reader (allocated for reading) */ |
| 150 | unsigned int buf_read_alloc_count; |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 151 | |
| 152 | unsigned int buf_write_ptr; /* buffer marker for writer */ |
| 153 | unsigned int buf_read_ptr; /* buffer marker for reader */ |
| 154 | |
| 155 | unsigned int cur_chan; /* useless channel marker for interrupt */ |
| 156 | /* number of bytes that have been received for current scan */ |
| 157 | unsigned int scan_progress; |
| 158 | /* keeps track of where we are in chanlist as for munging */ |
| 159 | unsigned int munge_chan; |
| 160 | /* number of bytes that have been munged */ |
| 161 | unsigned int munge_count; |
| 162 | /* buffer marker for munging */ |
| 163 | unsigned int munge_ptr; |
| 164 | |
| 165 | unsigned int events; /* events that have occurred */ |
| 166 | |
Bill Pemberton | ea6d0d4 | 2009-03-16 22:05:47 -0400 | [diff] [blame] | 167 | struct comedi_cmd cmd; |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 168 | |
| 169 | wait_queue_head_t wait_head; |
| 170 | |
Greg Kroah-Hartman | e0dcef7 | 2008-11-13 16:36:22 -0800 | [diff] [blame] | 171 | /* callback stuff */ |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 172 | unsigned int cb_mask; |
| 173 | int (*cb_func) (unsigned int flags, void *); |
| 174 | void *cb_arg; |
| 175 | |
Shane Warden | 62eeae9 | 2009-09-22 16:13:04 -0700 | [diff] [blame] | 176 | int (*inttrig) (struct comedi_device *dev, struct comedi_subdevice *s, |
Greg Kroah-Hartman | e0dcef7 | 2008-11-13 16:36:22 -0800 | [diff] [blame] | 177 | unsigned int x); |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 178 | }; |
| 179 | |
Bill Pemberton | 139dfbd | 2009-03-16 22:05:25 -0400 | [diff] [blame] | 180 | struct comedi_driver { |
| 181 | struct comedi_driver *next; |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 182 | |
| 183 | const char *driver_name; |
| 184 | struct module *module; |
Bill Pemberton | 0707bb0 | 2009-03-16 22:06:20 -0400 | [diff] [blame] | 185 | int (*attach) (struct comedi_device *, struct comedi_devconfig *); |
H Hartley Sweeten | 484ecc9 | 2012-05-17 17:11:14 -0700 | [diff] [blame] | 186 | void (*detach) (struct comedi_device *); |
Ian Abbott | 8ed705a | 2012-10-27 21:44:14 +0100 | [diff] [blame] | 187 | int (*auto_attach) (struct comedi_device *, unsigned long); |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 188 | |
| 189 | /* number of elements in board_name and board_id arrays */ |
| 190 | unsigned int num_names; |
| 191 | const char *const *board_name; |
| 192 | /* offset in bytes from one board name pointer to the next */ |
| 193 | int offset; |
| 194 | }; |
| 195 | |
Bill Pemberton | 71b5f4f | 2009-03-16 22:05:08 -0400 | [diff] [blame] | 196 | struct comedi_device { |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 197 | int use_count; |
Bill Pemberton | 139dfbd | 2009-03-16 22:05:25 -0400 | [diff] [blame] | 198 | struct comedi_driver *driver; |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 199 | void *private; |
| 200 | |
Bill Pemberton | 0bfbbe8 | 2009-03-16 22:05:36 -0400 | [diff] [blame] | 201 | struct device *class_dev; |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 202 | int minor; |
Greg Kroah-Hartman | e0dcef7 | 2008-11-13 16:36:22 -0800 | [diff] [blame] | 203 | /* hw_dev is passed to dma_alloc_coherent when allocating async buffers |
| 204 | * for subdevices that have async_dma_dir set to something other than |
| 205 | * DMA_NONE */ |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 206 | struct device *hw_dev; |
| 207 | |
| 208 | const char *board_name; |
| 209 | const void *board_ptr; |
| 210 | int attached; |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 211 | spinlock_t spinlock; |
| 212 | struct mutex mutex; |
| 213 | int in_request_module; |
| 214 | |
| 215 | int n_subdevices; |
Bill Pemberton | 34c4392 | 2009-03-16 22:05:14 -0400 | [diff] [blame] | 216 | struct comedi_subdevice *subdevices; |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 217 | |
| 218 | /* dumb */ |
| 219 | unsigned long iobase; |
| 220 | unsigned int irq; |
| 221 | |
Bill Pemberton | 34c4392 | 2009-03-16 22:05:14 -0400 | [diff] [blame] | 222 | struct comedi_subdevice *read_subdev; |
| 223 | struct comedi_subdevice *write_subdev; |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 224 | |
| 225 | struct fasync_struct *async_queue; |
| 226 | |
Ian Abbott | 3c17ba07 | 2010-05-19 14:10:00 +0100 | [diff] [blame] | 227 | int (*open) (struct comedi_device *dev); |
Shane Warden | 62eeae9 | 2009-09-22 16:13:04 -0700 | [diff] [blame] | 228 | void (*close) (struct comedi_device *dev); |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 229 | }; |
| 230 | |
Ian Abbott | 4dba6c0 | 2012-11-02 19:18:00 +0000 | [diff] [blame] | 231 | static inline const void *comedi_board(const struct comedi_device *dev) |
H Hartley Sweeten | 37859f8 | 2012-04-27 14:10:15 -0700 | [diff] [blame] | 232 | { |
| 233 | return dev->board_ptr; |
| 234 | } |
| 235 | |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 236 | #ifdef CONFIG_COMEDI_DEBUG |
| 237 | extern int comedi_debug; |
| 238 | #else |
Greg Kroah-Hartman | e0dcef7 | 2008-11-13 16:36:22 -0800 | [diff] [blame] | 239 | static const int comedi_debug; |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 240 | #endif |
| 241 | |
| 242 | /* |
| 243 | * function prototypes |
| 244 | */ |
| 245 | |
Bill Pemberton | 34c4392 | 2009-03-16 22:05:14 -0400 | [diff] [blame] | 246 | void comedi_event(struct comedi_device *dev, struct comedi_subdevice *s); |
Bill Pemberton | 71b5f4f | 2009-03-16 22:05:08 -0400 | [diff] [blame] | 247 | void comedi_error(const struct comedi_device *dev, const char *s); |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 248 | |
| 249 | /* we can expand the number of bits used to encode devices/subdevices into |
| 250 | the minor number soon, after more distros support > 8 bit minor numbers |
| 251 | (like after Debian Etch gets released) */ |
| 252 | enum comedi_minor_bits { |
| 253 | COMEDI_DEVICE_MINOR_MASK = 0xf, |
| 254 | COMEDI_SUBDEVICE_MINOR_MASK = 0xf0 |
| 255 | }; |
| 256 | static const unsigned COMEDI_SUBDEVICE_MINOR_SHIFT = 4; |
| 257 | static const unsigned COMEDI_SUBDEVICE_MINOR_OFFSET = 1; |
| 258 | |
H Hartley Sweeten | 85104e9 | 2012-12-19 15:34:40 -0700 | [diff] [blame] | 259 | struct comedi_device *comedi_dev_from_minor(unsigned minor); |
| 260 | |
H Hartley Sweeten | 8b9ba6e | 2012-06-12 11:57:27 -0700 | [diff] [blame] | 261 | int comedi_alloc_subdevices(struct comedi_device *, int); |
H Hartley Sweeten | 2f0b9d0 | 2012-06-11 17:45:15 -0700 | [diff] [blame] | 262 | |
Bill Pemberton | 71b5f4f | 2009-03-16 22:05:08 -0400 | [diff] [blame] | 263 | void comedi_device_detach(struct comedi_device *dev); |
Mithlesh Thukral | 0a85b6f | 2009-06-08 21:04:41 +0530 | [diff] [blame] | 264 | int comedi_device_attach(struct comedi_device *dev, |
| 265 | struct comedi_devconfig *it); |
Bill Pemberton | 139dfbd | 2009-03-16 22:05:25 -0400 | [diff] [blame] | 266 | int comedi_driver_register(struct comedi_driver *); |
| 267 | int comedi_driver_unregister(struct comedi_driver *); |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 268 | |
H Hartley Sweeten | 2041625 | 2012-05-01 17:20:04 -0700 | [diff] [blame] | 269 | /** |
| 270 | * module_comedi_driver() - Helper macro for registering a comedi driver |
| 271 | * @__comedi_driver: comedi_driver struct |
| 272 | * |
| 273 | * Helper macro for comedi drivers which do not do anything special in module |
| 274 | * init/exit. This eliminates a lot of boilerplate. Each module may only use |
| 275 | * this macro once, and calling it replaces module_init() and module_exit(). |
| 276 | */ |
| 277 | #define module_comedi_driver(__comedi_driver) \ |
| 278 | module_driver(__comedi_driver, comedi_driver_register, \ |
| 279 | comedi_driver_unregister) |
| 280 | |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 281 | void init_polling(void); |
| 282 | void cleanup_polling(void); |
Bill Pemberton | 71b5f4f | 2009-03-16 22:05:08 -0400 | [diff] [blame] | 283 | void start_polling(struct comedi_device *); |
| 284 | void stop_polling(struct comedi_device *); |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 285 | |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 286 | #ifdef CONFIG_PROC_FS |
| 287 | void comedi_proc_init(void); |
| 288 | void comedi_proc_cleanup(void); |
| 289 | #else |
| 290 | static inline void comedi_proc_init(void) |
| 291 | { |
| 292 | } |
Mithlesh Thukral | 0a85b6f | 2009-06-08 21:04:41 +0530 | [diff] [blame] | 293 | |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 294 | static inline void comedi_proc_cleanup(void) |
| 295 | { |
| 296 | } |
| 297 | #endif |
| 298 | |
| 299 | /* subdevice runflags */ |
| 300 | enum subdevice_runflags { |
| 301 | SRF_USER = 0x00000001, |
| 302 | SRF_RT = 0x00000002, |
Greg Kroah-Hartman | e0dcef7 | 2008-11-13 16:36:22 -0800 | [diff] [blame] | 303 | /* indicates an COMEDI_CB_ERROR event has occurred since the last |
| 304 | * command was started */ |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 305 | SRF_ERROR = 0x00000004, |
| 306 | SRF_RUNNING = 0x08000000 |
| 307 | }; |
| 308 | |
H Hartley Sweeten | e0dac31 | 2012-12-19 15:42:47 -0700 | [diff] [blame] | 309 | bool comedi_is_subdevice_running(struct comedi_subdevice *s); |
| 310 | |
Mark Rankilor | 5e22011 | 2010-05-06 17:49:37 +0800 | [diff] [blame] | 311 | int comedi_check_chanlist(struct comedi_subdevice *s, |
| 312 | int n, |
| 313 | unsigned int *chanlist); |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 314 | |
| 315 | /* range stuff */ |
| 316 | |
Greg Kroah-Hartman | e0dcef7 | 2008-11-13 16:36:22 -0800 | [diff] [blame] | 317 | #define RANGE(a, b) {(a)*1e6, (b)*1e6, 0} |
| 318 | #define RANGE_ext(a, b) {(a)*1e6, (b)*1e6, RF_EXTERNAL} |
| 319 | #define RANGE_mA(a, b) {(a)*1e6, (b)*1e6, UNIT_mA} |
Greg Kroah-Hartman | baf22b6 | 2010-04-30 15:26:54 -0700 | [diff] [blame] | 320 | #define RANGE_unitless(a, b) {(a)*1e6, (b)*1e6, 0} |
Greg Kroah-Hartman | e0dcef7 | 2008-11-13 16:36:22 -0800 | [diff] [blame] | 321 | #define BIP_RANGE(a) {-(a)*1e6, (a)*1e6, 0} |
| 322 | #define UNI_RANGE(a) {0, (a)*1e6, 0} |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 323 | |
Bill Pemberton | 9ced1de | 2009-03-16 22:05:31 -0400 | [diff] [blame] | 324 | extern const struct comedi_lrange range_bipolar10; |
| 325 | extern const struct comedi_lrange range_bipolar5; |
| 326 | extern const struct comedi_lrange range_bipolar2_5; |
| 327 | extern const struct comedi_lrange range_unipolar10; |
| 328 | extern const struct comedi_lrange range_unipolar5; |
| 329 | extern const struct comedi_lrange range_unknown; |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 330 | |
| 331 | #define range_digital range_unipolar5 |
| 332 | |
| 333 | #if __GNUC__ >= 3 |
| 334 | #define GCC_ZERO_LENGTH_ARRAY |
| 335 | #else |
| 336 | #define GCC_ZERO_LENGTH_ARRAY 0 |
| 337 | #endif |
| 338 | |
Bill Pemberton | 9ced1de | 2009-03-16 22:05:31 -0400 | [diff] [blame] | 339 | struct comedi_lrange { |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 340 | int length; |
Bill Pemberton | 1f6325d | 2009-03-16 22:06:31 -0400 | [diff] [blame] | 341 | struct comedi_krange range[GCC_ZERO_LENGTH_ARRAY]; |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 342 | }; |
| 343 | |
| 344 | /* some silly little inline functions */ |
| 345 | |
Bill Pemberton | 34c4392 | 2009-03-16 22:05:14 -0400 | [diff] [blame] | 346 | static inline unsigned int bytes_per_sample(const struct comedi_subdevice *subd) |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 347 | { |
| 348 | if (subd->subdev_flags & SDF_LSAMPL) |
Bill Pemberton | 790c554 | 2009-03-16 22:05:02 -0400 | [diff] [blame] | 349 | return sizeof(unsigned int); |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 350 | else |
Bill Pemberton | 790c554 | 2009-03-16 22:05:02 -0400 | [diff] [blame] | 351 | return sizeof(short); |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 352 | } |
| 353 | |
Ian Abbott | bc3954b | 2013-01-29 16:20:17 +0000 | [diff] [blame] | 354 | /* |
| 355 | * Must set dev->hw_dev if you wish to dma directly into comedi's buffer. |
| 356 | * Also useful for retrieving a previously configured hardware device of |
| 357 | * known bus type. Set automatically for auto-configured devices. |
| 358 | * Automatically set to NULL when detaching hardware device. |
| 359 | */ |
Mithlesh Thukral | 0a85b6f | 2009-06-08 21:04:41 +0530 | [diff] [blame] | 360 | static inline void comedi_set_hw_dev(struct comedi_device *dev, |
| 361 | struct device *hw_dev) |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 362 | { |
Ian Abbott | bc3954b | 2013-01-29 16:20:17 +0000 | [diff] [blame] | 363 | struct device *old_hw_dev = dev->hw_dev; |
| 364 | |
| 365 | dev->hw_dev = get_device(hw_dev); |
| 366 | put_device(old_hw_dev); |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 367 | } |
| 368 | |
H Hartley Sweeten | 8ae560a | 2013-01-09 13:32:56 -0700 | [diff] [blame] | 369 | unsigned int comedi_buf_write_alloc(struct comedi_async *, unsigned int); |
| 370 | unsigned int comedi_buf_write_free(struct comedi_async *, unsigned int); |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 371 | |
H Hartley Sweeten | 8ae560a | 2013-01-09 13:32:56 -0700 | [diff] [blame] | 372 | unsigned int comedi_buf_read_n_available(struct comedi_async *); |
| 373 | unsigned int comedi_buf_read_alloc(struct comedi_async *, unsigned int); |
| 374 | unsigned int comedi_buf_read_free(struct comedi_async *, unsigned int); |
| 375 | |
| 376 | int comedi_buf_put(struct comedi_async *, short); |
| 377 | int comedi_buf_get(struct comedi_async *, short *); |
| 378 | |
Bill Pemberton | d163679 | 2009-03-16 22:05:20 -0400 | [diff] [blame] | 379 | void comedi_buf_memcpy_to(struct comedi_async *async, unsigned int offset, |
Mithlesh Thukral | 0a85b6f | 2009-06-08 21:04:41 +0530 | [diff] [blame] | 380 | const void *source, unsigned int num_bytes); |
Bill Pemberton | d163679 | 2009-03-16 22:05:20 -0400 | [diff] [blame] | 381 | void comedi_buf_memcpy_from(struct comedi_async *async, unsigned int offset, |
Mithlesh Thukral | 0a85b6f | 2009-06-08 21:04:41 +0530 | [diff] [blame] | 382 | void *destination, unsigned int num_bytes); |
Mithlesh Thukral | 0a85b6f | 2009-06-08 21:04:41 +0530 | [diff] [blame] | 383 | |
Mithlesh Thukral | 0a85b6f | 2009-06-08 21:04:41 +0530 | [diff] [blame] | 384 | int comedi_alloc_subdevice_minor(struct comedi_device *dev, |
| 385 | struct comedi_subdevice *s); |
Bill Pemberton | 34c4392 | 2009-03-16 22:05:14 -0400 | [diff] [blame] | 386 | void comedi_free_subdevice_minor(struct comedi_subdevice *s); |
Ian Abbott | 8ed705a | 2012-10-27 21:44:14 +0100 | [diff] [blame] | 387 | int comedi_auto_config(struct device *hardware_device, |
| 388 | struct comedi_driver *driver, unsigned long context); |
| 389 | void comedi_auto_unconfig(struct device *hardware_device); |
Ian Abbott | 581a7dd | 2012-11-14 13:10:40 +0000 | [diff] [blame] | 390 | |
H Hartley Sweeten | 33782dd | 2013-01-30 15:22:21 -0700 | [diff] [blame] | 391 | #ifdef CONFIG_COMEDI_PCI_DRIVERS |
| 392 | |
| 393 | /* comedi_pci.c - comedi PCI driver specific functions */ |
| 394 | |
| 395 | /* |
| 396 | * PCI Vendor IDs not in <linux/pci_ids.h> |
| 397 | */ |
| 398 | #define PCI_VENDOR_ID_KOLTER 0x1001 |
| 399 | #define PCI_VENDOR_ID_ICP 0x104c |
| 400 | #define PCI_VENDOR_ID_AMCC 0x10e8 |
| 401 | #define PCI_VENDOR_ID_DT 0x1116 |
| 402 | #define PCI_VENDOR_ID_IOTECH 0x1616 |
| 403 | #define PCI_VENDOR_ID_CONTEC 0x1221 |
| 404 | #define PCI_VENDOR_ID_CB 0x1307 /* Measurement Computing */ |
| 405 | #define PCI_VENDOR_ID_ADVANTECH 0x13fe |
| 406 | #define PCI_VENDOR_ID_MEILHAUS 0x1402 |
| 407 | #define PCI_VENDOR_ID_RTD 0x1435 |
| 408 | #define PCI_VENDOR_ID_ADLINK 0x144a |
| 409 | #define PCI_VENDOR_ID_AMPLICON 0x14dc |
| 410 | |
| 411 | struct pci_dev; |
| 412 | struct pci_driver; |
| 413 | |
| 414 | struct pci_dev *comedi_to_pci_dev(struct comedi_device *); |
| 415 | |
| 416 | int comedi_pci_enable(struct pci_dev *, const char *); |
| 417 | void comedi_pci_disable(struct pci_dev *); |
| 418 | |
| 419 | int comedi_pci_auto_config(struct pci_dev *, struct comedi_driver *); |
| 420 | void comedi_pci_auto_unconfig(struct pci_dev *); |
| 421 | |
| 422 | int comedi_pci_driver_register(struct comedi_driver *, struct pci_driver *); |
| 423 | void comedi_pci_driver_unregister(struct comedi_driver *, struct pci_driver *); |
| 424 | |
| 425 | /** |
| 426 | * module_comedi_pci_driver() - Helper macro for registering a comedi PCI driver |
| 427 | * @__comedi_driver: comedi_driver struct |
| 428 | * @__pci_driver: pci_driver struct |
| 429 | * |
| 430 | * Helper macro for comedi PCI drivers which do not do anything special |
| 431 | * in module init/exit. This eliminates a lot of boilerplate. Each |
| 432 | * module may only use this macro once, and calling it replaces |
| 433 | * module_init() and module_exit() |
| 434 | */ |
| 435 | #define module_comedi_pci_driver(__comedi_driver, __pci_driver) \ |
| 436 | module_driver(__comedi_driver, comedi_pci_driver_register, \ |
| 437 | comedi_pci_driver_unregister, &(__pci_driver)) |
| 438 | |
| 439 | #else |
| 440 | |
| 441 | /* |
| 442 | * Some of the comedi mixed ISA/PCI drivers call the PCI specific |
| 443 | * functions. Provide some dummy functions if CONFIG_COMEDI_PCI_DRIVERS |
| 444 | * is not enabled. |
| 445 | */ |
| 446 | |
| 447 | static inline struct pci_dev *comedi_to_pci_dev(struct comedi_device *dev) |
Ian Abbott | 581a7dd | 2012-11-14 13:10:40 +0000 | [diff] [blame] | 448 | { |
H Hartley Sweeten | 33782dd | 2013-01-30 15:22:21 -0700 | [diff] [blame] | 449 | return NULL; |
Ian Abbott | 581a7dd | 2012-11-14 13:10:40 +0000 | [diff] [blame] | 450 | } |
| 451 | |
H Hartley Sweeten | 33782dd | 2013-01-30 15:22:21 -0700 | [diff] [blame] | 452 | static inline int comedi_pci_enable(struct pci_dev *dev, const char *name) |
| 453 | { |
| 454 | return -ENOSYS; |
| 455 | } |
| 456 | |
| 457 | static inline void comedi_pci_disable(struct pci_dev *dev) |
| 458 | { |
| 459 | } |
| 460 | |
| 461 | #endif /* CONFIG_COMEDI_PCI_DRIVERS */ |
Ian Abbott | 581a7dd | 2012-11-14 13:10:40 +0000 | [diff] [blame] | 462 | |
H Hartley Sweeten | 309231d | 2013-01-30 15:22:44 -0700 | [diff] [blame^] | 463 | #ifdef CONFIG_COMEDI_PCMCIA_DRIVERS |
| 464 | |
| 465 | /* comedi_pcmcia.c - comedi PCMCIA driver specific functions */ |
| 466 | |
| 467 | struct pcmcia_driver; |
| 468 | |
| 469 | int comedi_pcmcia_driver_register(struct comedi_driver *, |
| 470 | struct pcmcia_driver *); |
| 471 | void comedi_pcmcia_driver_unregister(struct comedi_driver *, |
| 472 | struct pcmcia_driver *); |
| 473 | |
| 474 | /** |
| 475 | * module_comedi_pcmcia_driver() - Helper macro for registering a comedi PCMCIA driver |
| 476 | * @__comedi_driver: comedi_driver struct |
| 477 | * @__pcmcia_driver: pcmcia_driver struct |
| 478 | * |
| 479 | * Helper macro for comedi PCMCIA drivers which do not do anything special |
| 480 | * in module init/exit. This eliminates a lot of boilerplate. Each |
| 481 | * module may only use this macro once, and calling it replaces |
| 482 | * module_init() and module_exit() |
| 483 | */ |
| 484 | #define module_comedi_pcmcia_driver(__comedi_driver, __pcmcia_driver) \ |
| 485 | module_driver(__comedi_driver, comedi_pcmcia_driver_register, \ |
| 486 | comedi_pcmcia_driver_unregister, &(__pcmcia_driver)) |
| 487 | |
| 488 | #endif /* CONFIG_COMEDI_PCMCIA_DRIVERS */ |
| 489 | |
H Hartley Sweeten | abac8b5 | 2013-01-30 15:21:49 -0700 | [diff] [blame] | 490 | #ifdef CONFIG_COMEDI_USB_DRIVERS |
Ian Abbott | 581a7dd | 2012-11-14 13:10:40 +0000 | [diff] [blame] | 491 | |
H Hartley Sweeten | abac8b5 | 2013-01-30 15:21:49 -0700 | [diff] [blame] | 492 | /* comedi_usb.c - comedi USB driver specific functions */ |
| 493 | |
| 494 | struct usb_driver; |
| 495 | struct usb_interface; |
| 496 | |
| 497 | struct usb_interface *comedi_to_usb_interface(struct comedi_device *); |
| 498 | |
| 499 | int comedi_usb_auto_config(struct usb_interface *, struct comedi_driver *); |
| 500 | void comedi_usb_auto_unconfig(struct usb_interface *); |
| 501 | |
| 502 | int comedi_usb_driver_register(struct comedi_driver *, struct usb_driver *); |
| 503 | void comedi_usb_driver_unregister(struct comedi_driver *, struct usb_driver *); |
| 504 | |
| 505 | /** |
| 506 | * module_comedi_usb_driver() - Helper macro for registering a comedi USB driver |
| 507 | * @__comedi_driver: comedi_driver struct |
| 508 | * @__usb_driver: usb_driver struct |
| 509 | * |
| 510 | * Helper macro for comedi USB drivers which do not do anything special |
| 511 | * in module init/exit. This eliminates a lot of boilerplate. Each |
| 512 | * module may only use this macro once, and calling it replaces |
| 513 | * module_init() and module_exit() |
| 514 | */ |
| 515 | #define module_comedi_usb_driver(__comedi_driver, __usb_driver) \ |
| 516 | module_driver(__comedi_driver, comedi_usb_driver_register, \ |
| 517 | comedi_usb_driver_unregister, &(__usb_driver)) |
| 518 | |
| 519 | #endif /* CONFIG_COMEDI_USB_DRIVERS */ |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 520 | |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 521 | #endif /* _COMEDIDEV_H */ |