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