blob: 143be8076a2e72361d11f88a2b64db8c4b89855b [file] [log] [blame]
David Schleefed9eccb2008-11-04 20:29:31 -08001/*
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 Schleefed9eccb2008-11-04 20:29:31 -080017*/
18
19#ifndef _COMEDIDEV_H
20#define _COMEDIDEV_H
21
David Schleefed9eccb2008-11-04 20:29:31 -080022#include <linux/dma-mapping.h>
David Schleefed9eccb2008-11-04 20:29:31 -080023
24#include "comedi.h"
25
Greg Kroah-Hartmane0dcef72008-11-13 16:36:22 -080026#define DPRINTK(format, args...) do { \
27 if (comedi_debug) \
Ian Abbott4f870fe2012-08-16 14:38:05 +010028 pr_debug("comedi: " format, ## args); \
Greg Kroah-Hartmane0dcef72008-11-13 16:36:22 -080029} while (0)
David Schleefed9eccb2008-11-04 20:29:31 -080030
Greg Kroah-Hartmane0dcef72008-11-13 16:36:22 -080031#define COMEDI_VERSION(a, b, c) (((a) << 16) + ((b) << 8) + (c))
Shane Warden62eeae92009-09-22 16:13:04 -070032#define COMEDI_VERSION_CODE COMEDI_VERSION(COMEDI_MAJORVERSION, \
33 COMEDI_MINORVERSION, COMEDI_MICROVERSION)
David Schleefed9eccb2008-11-04 20:29:31 -080034#define COMEDI_RELEASE VERSION
35
David Schleefed9eccb2008-11-04 20:29:31 -080036#define COMEDI_NUM_BOARD_MINORS 0x30
David Schleefed9eccb2008-11-04 20:29:31 -080037
Bill Pemberton34c43922009-03-16 22:05:14 -040038struct comedi_subdevice {
Bill Pemberton71b5f4f2009-03-16 22:05:08 -040039 struct comedi_device *device;
H Hartley Sweeten90a35c12012-12-19 17:27:02 -070040 int index;
David Schleefed9eccb2008-11-04 20:29:31 -080041 int type;
42 int n_chan;
Greg Kroah-Hartmanbaf22b62010-04-30 15:26:54 -070043 int subdev_flags;
David Schleefed9eccb2008-11-04 20:29:31 -080044 int len_chanlist; /* maximum length of channel/gain list */
45
46 void *private;
47
Bill Pembertond1636792009-03-16 22:05:20 -040048 struct comedi_async *async;
David Schleefed9eccb2008-11-04 20:29:31 -080049
50 void *lock;
51 void *busy;
52 unsigned runflags;
53 spinlock_t spin_lock;
54
H Hartley Sweetend4a7dc82012-06-18 14:45:42 -070055 unsigned int io_bits;
David Schleefed9eccb2008-11-04 20:29:31 -080056
Bill Pemberton790c5542009-03-16 22:05:02 -040057 unsigned int maxdata; /* if maxdata==0, use list */
58 const unsigned int *maxdata_list; /* list is channel specific */
David Schleefed9eccb2008-11-04 20:29:31 -080059
Bill Pemberton9ced1de2009-03-16 22:05:31 -040060 const struct comedi_lrange *range_table;
61 const struct comedi_lrange *const *range_table_list;
David Schleefed9eccb2008-11-04 20:29:31 -080062
63 unsigned int *chanlist; /* driver-owned chanlist (not used) */
64
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +053065 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 Schleefed9eccb2008-11-04 20:29:31 -080073
Bill Pemberton34c43922009-03-16 22:05:14 -040074 int (*do_cmd) (struct comedi_device *, struct comedi_subdevice *);
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +053075 int (*do_cmdtest) (struct comedi_device *, struct comedi_subdevice *,
76 struct comedi_cmd *);
Bill Pemberton34c43922009-03-16 22:05:14 -040077 int (*poll) (struct comedi_device *, struct comedi_subdevice *);
78 int (*cancel) (struct comedi_device *, struct comedi_subdevice *);
Shane Warden62eeae92009-09-22 16:13:04 -070079 /* int (*do_lock)(struct comedi_device *, struct comedi_subdevice *); */
80 /* int (*do_unlock)(struct comedi_device *, \
81 struct comedi_subdevice *); */
David Schleefed9eccb2008-11-04 20:29:31 -080082
83 /* called when the buffer changes */
Shane Warden62eeae92009-09-22 16:13:04 -070084 int (*buf_change) (struct comedi_device *dev,
85 struct comedi_subdevice *s, unsigned long new_size);
David Schleefed9eccb2008-11-04 20:29:31 -080086
Shane Warden62eeae92009-09-22 16:13:04 -070087 void (*munge) (struct comedi_device *dev, struct comedi_subdevice *s,
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +053088 void *data, unsigned int num_bytes,
89 unsigned int start_chan_index);
David Schleefed9eccb2008-11-04 20:29:31 -080090 enum dma_data_direction async_dma_dir;
91
92 unsigned int state;
93
Bill Pemberton0bfbbe82009-03-16 22:05:36 -040094 struct device *class_dev;
David Schleefed9eccb2008-11-04 20:29:31 -080095 int minor;
96};
97
98struct comedi_buf_page {
99 void *virt_addr;
100 dma_addr_t dma_addr;
101};
102
Bill Pembertond1636792009-03-16 22:05:20 -0400103struct comedi_async {
Bill Pemberton34c43922009-03-16 22:05:14 -0400104 struct comedi_subdevice *subdevice;
David Schleefed9eccb2008-11-04 20:29:31 -0800105
106 void *prealloc_buf; /* pre-allocated buffer */
107 unsigned int prealloc_bufsz; /* buffer size, in bytes */
Shane Warden62eeae92009-09-22 16:13:04 -0700108 /* virtual and dma address of each page */
109 struct comedi_buf_page *buf_page_list;
David Schleefed9eccb2008-11-04 20:29:31 -0800110 unsigned n_buf_pages; /* num elements in buf_page_list */
111
112 unsigned int max_bufsize; /* maximum buffer size, bytes */
Shane Warden62eeae92009-09-22 16:13:04 -0700113 /* current number of mmaps of prealloc_buf */
114 unsigned int mmap_count;
David Schleefed9eccb2008-11-04 20:29:31 -0800115
Shane Warden62eeae92009-09-22 16:13:04 -0700116 /* 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 Schleefed9eccb2008-11-04 20:29:31 -0800124
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 Pembertonea6d0d42009-03-16 22:05:47 -0400140 struct comedi_cmd cmd;
David Schleefed9eccb2008-11-04 20:29:31 -0800141
142 wait_queue_head_t wait_head;
143
Greg Kroah-Hartmane0dcef72008-11-13 16:36:22 -0800144 /* callback stuff */
David Schleefed9eccb2008-11-04 20:29:31 -0800145 unsigned int cb_mask;
146 int (*cb_func) (unsigned int flags, void *);
147 void *cb_arg;
148
Shane Warden62eeae92009-09-22 16:13:04 -0700149 int (*inttrig) (struct comedi_device *dev, struct comedi_subdevice *s,
Greg Kroah-Hartmane0dcef72008-11-13 16:36:22 -0800150 unsigned int x);
David Schleefed9eccb2008-11-04 20:29:31 -0800151};
152
Bill Pemberton139dfbd2009-03-16 22:05:25 -0400153struct comedi_driver {
154 struct comedi_driver *next;
David Schleefed9eccb2008-11-04 20:29:31 -0800155
156 const char *driver_name;
157 struct module *module;
Bill Pemberton0707bb02009-03-16 22:06:20 -0400158 int (*attach) (struct comedi_device *, struct comedi_devconfig *);
H Hartley Sweeten484ecc92012-05-17 17:11:14 -0700159 void (*detach) (struct comedi_device *);
Ian Abbott8ed705a2012-10-27 21:44:14 +0100160 int (*auto_attach) (struct comedi_device *, unsigned long);
David Schleefed9eccb2008-11-04 20:29:31 -0800161
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 Pemberton71b5f4f2009-03-16 22:05:08 -0400169struct comedi_device {
David Schleefed9eccb2008-11-04 20:29:31 -0800170 int use_count;
Bill Pemberton139dfbd2009-03-16 22:05:25 -0400171 struct comedi_driver *driver;
David Schleefed9eccb2008-11-04 20:29:31 -0800172 void *private;
173
Bill Pemberton0bfbbe82009-03-16 22:05:36 -0400174 struct device *class_dev;
David Schleefed9eccb2008-11-04 20:29:31 -0800175 int minor;
Greg Kroah-Hartmane0dcef72008-11-13 16:36:22 -0800176 /* 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 Schleefed9eccb2008-11-04 20:29:31 -0800179 struct device *hw_dev;
180
181 const char *board_name;
182 const void *board_ptr;
Ian Abbotta7401cd2013-03-15 13:15:33 +0000183 bool attached:1;
Ian Abbott13f12b52013-03-15 13:15:34 +0000184 bool in_request_module:1;
Ian Abbott00ca68842013-03-15 13:15:35 +0000185 bool ioenabled:1;
David Schleefed9eccb2008-11-04 20:29:31 -0800186 spinlock_t spinlock;
187 struct mutex mutex;
David Schleefed9eccb2008-11-04 20:29:31 -0800188
189 int n_subdevices;
Bill Pemberton34c43922009-03-16 22:05:14 -0400190 struct comedi_subdevice *subdevices;
David Schleefed9eccb2008-11-04 20:29:31 -0800191
192 /* dumb */
193 unsigned long iobase;
H Hartley Sweeten316f97f2013-04-18 14:31:29 -0700194 unsigned long iolen;
David Schleefed9eccb2008-11-04 20:29:31 -0800195 unsigned int irq;
196
Bill Pemberton34c43922009-03-16 22:05:14 -0400197 struct comedi_subdevice *read_subdev;
198 struct comedi_subdevice *write_subdev;
David Schleefed9eccb2008-11-04 20:29:31 -0800199
200 struct fasync_struct *async_queue;
201
Ian Abbott3c17ba072010-05-19 14:10:00 +0100202 int (*open) (struct comedi_device *dev);
Shane Warden62eeae92009-09-22 16:13:04 -0700203 void (*close) (struct comedi_device *dev);
David Schleefed9eccb2008-11-04 20:29:31 -0800204};
205
Ian Abbott4dba6c02012-11-02 19:18:00 +0000206static inline const void *comedi_board(const struct comedi_device *dev)
H Hartley Sweeten37859f82012-04-27 14:10:15 -0700207{
208 return dev->board_ptr;
209}
210
David Schleefed9eccb2008-11-04 20:29:31 -0800211#ifdef CONFIG_COMEDI_DEBUG
212extern int comedi_debug;
213#else
Greg Kroah-Hartmane0dcef72008-11-13 16:36:22 -0800214static const int comedi_debug;
David Schleefed9eccb2008-11-04 20:29:31 -0800215#endif
216
217/*
218 * function prototypes
219 */
220
Bill Pemberton34c43922009-03-16 22:05:14 -0400221void comedi_event(struct comedi_device *dev, struct comedi_subdevice *s);
Bill Pemberton71b5f4f2009-03-16 22:05:08 -0400222void comedi_error(const struct comedi_device *dev, const char *s);
David Schleefed9eccb2008-11-04 20:29:31 -0800223
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) */
227enum comedi_minor_bits {
228 COMEDI_DEVICE_MINOR_MASK = 0xf,
229 COMEDI_SUBDEVICE_MINOR_MASK = 0xf0
230};
231static const unsigned COMEDI_SUBDEVICE_MINOR_SHIFT = 4;
232static const unsigned COMEDI_SUBDEVICE_MINOR_OFFSET = 1;
233
H Hartley Sweeten85104e92012-12-19 15:34:40 -0700234struct comedi_device *comedi_dev_from_minor(unsigned minor);
235
David Schleefed9eccb2008-11-04 20:29:31 -0800236void init_polling(void);
237void cleanup_polling(void);
Bill Pemberton71b5f4f2009-03-16 22:05:08 -0400238void start_polling(struct comedi_device *);
239void stop_polling(struct comedi_device *);
David Schleefed9eccb2008-11-04 20:29:31 -0800240
David Schleefed9eccb2008-11-04 20:29:31 -0800241/* subdevice runflags */
242enum subdevice_runflags {
243 SRF_USER = 0x00000001,
244 SRF_RT = 0x00000002,
Greg Kroah-Hartmane0dcef72008-11-13 16:36:22 -0800245 /* indicates an COMEDI_CB_ERROR event has occurred since the last
246 * command was started */
David Schleefed9eccb2008-11-04 20:29:31 -0800247 SRF_ERROR = 0x00000004,
H Hartley Sweeten588ba6d2013-06-11 11:32:29 -0700248 SRF_RUNNING = 0x08000000,
249 SRF_FREE_SPRIV = 0x80000000, /* free s->private on detach */
David Schleefed9eccb2008-11-04 20:29:31 -0800250};
251
H Hartley Sweetene0dac312012-12-19 15:42:47 -0700252bool comedi_is_subdevice_running(struct comedi_subdevice *s);
H Hartley Sweeten0480bcb2013-06-19 15:24:36 -0700253
254void *comedi_alloc_spriv(struct comedi_subdevice *s, size_t size);
H Hartley Sweetene0dac312012-12-19 15:42:47 -0700255
Mark Rankilor5e220112010-05-06 17:49:37 +0800256int comedi_check_chanlist(struct comedi_subdevice *s,
257 int n,
258 unsigned int *chanlist);
David Schleefed9eccb2008-11-04 20:29:31 -0800259
260/* range stuff */
261
Greg Kroah-Hartmane0dcef72008-11-13 16:36:22 -0800262#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-Hartmanbaf22b62010-04-30 15:26:54 -0700265#define RANGE_unitless(a, b) {(a)*1e6, (b)*1e6, 0}
Greg Kroah-Hartmane0dcef72008-11-13 16:36:22 -0800266#define BIP_RANGE(a) {-(a)*1e6, (a)*1e6, 0}
267#define UNI_RANGE(a) {0, (a)*1e6, 0}
David Schleefed9eccb2008-11-04 20:29:31 -0800268
Bill Pemberton9ced1de2009-03-16 22:05:31 -0400269extern const struct comedi_lrange range_bipolar10;
270extern const struct comedi_lrange range_bipolar5;
271extern const struct comedi_lrange range_bipolar2_5;
272extern const struct comedi_lrange range_unipolar10;
273extern const struct comedi_lrange range_unipolar5;
H Hartley Sweeten5f8eb722013-04-03 13:38:26 -0700274extern const struct comedi_lrange range_unipolar2_5;
H Hartley Sweeten2c71c4f2013-04-03 13:40:13 -0700275extern const struct comedi_lrange range_0_20mA;
276extern const struct comedi_lrange range_4_20mA;
277extern const struct comedi_lrange range_0_32mA;
Bill Pemberton9ced1de2009-03-16 22:05:31 -0400278extern const struct comedi_lrange range_unknown;
David Schleefed9eccb2008-11-04 20:29:31 -0800279
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 Pemberton9ced1de2009-03-16 22:05:31 -0400288struct comedi_lrange {
David Schleefed9eccb2008-11-04 20:29:31 -0800289 int length;
Bill Pemberton1f6325d2009-03-16 22:06:31 -0400290 struct comedi_krange range[GCC_ZERO_LENGTH_ARRAY];
David Schleefed9eccb2008-11-04 20:29:31 -0800291};
292
H Hartley Sweetene3693fd2013-06-05 15:52:31 -0700293static 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
299static 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 Sweeten49162112013-09-25 15:35:06 -0700305static 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
312static 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 Sweetenf0b215d2013-09-18 11:49:33 -0700319/* munge between offset binary and two's complement values */
320static 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 Schleefed9eccb2008-11-04 20:29:31 -0800325
Bill Pemberton34c43922009-03-16 22:05:14 -0400326static inline unsigned int bytes_per_sample(const struct comedi_subdevice *subd)
David Schleefed9eccb2008-11-04 20:29:31 -0800327{
328 if (subd->subdev_flags & SDF_LSAMPL)
Bill Pemberton790c5542009-03-16 22:05:02 -0400329 return sizeof(unsigned int);
David Schleefed9eccb2008-11-04 20:29:31 -0800330 else
Bill Pemberton790c5542009-03-16 22:05:02 -0400331 return sizeof(short);
David Schleefed9eccb2008-11-04 20:29:31 -0800332}
333
Ian Abbottbc3954b2013-01-29 16:20:17 +0000334/*
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 Abbottda717512013-02-01 13:23:19 +0000340int comedi_set_hw_dev(struct comedi_device *dev, struct device *hw_dev);
David Schleefed9eccb2008-11-04 20:29:31 -0800341
H Hartley Sweeten8ae560a2013-01-09 13:32:56 -0700342unsigned int comedi_buf_write_alloc(struct comedi_async *, unsigned int);
343unsigned int comedi_buf_write_free(struct comedi_async *, unsigned int);
David Schleefed9eccb2008-11-04 20:29:31 -0800344
H Hartley Sweeten8ae560a2013-01-09 13:32:56 -0700345unsigned int comedi_buf_read_n_available(struct comedi_async *);
346unsigned int comedi_buf_read_alloc(struct comedi_async *, unsigned int);
347unsigned int comedi_buf_read_free(struct comedi_async *, unsigned int);
348
Ian Abbott0a6fd022013-10-16 14:40:04 +0100349int comedi_buf_put(struct comedi_async *, unsigned short);
350int comedi_buf_get(struct comedi_async *, unsigned short *);
H Hartley Sweeten8ae560a2013-01-09 13:32:56 -0700351
Bill Pembertond1636792009-03-16 22:05:20 -0400352void comedi_buf_memcpy_to(struct comedi_async *async, unsigned int offset,
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530353 const void *source, unsigned int num_bytes);
Bill Pembertond1636792009-03-16 22:05:20 -0400354void comedi_buf_memcpy_from(struct comedi_async *async, unsigned int offset,
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530355 void *destination, unsigned int num_bytes);
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530356
H Hartley Sweeten1ae6b202013-01-30 15:24:38 -0700357/* drivers.c - general comedi driver functions */
358
H Hartley Sweetene523c6c2013-08-06 09:31:35 -0700359int comedi_dio_insn_config(struct comedi_device *, struct comedi_subdevice *,
360 struct comedi_insn *, unsigned int *data,
361 unsigned int mask);
H Hartley Sweeten05e60b12013-08-30 11:04:56 -0700362unsigned int comedi_dio_update_state(struct comedi_subdevice *,
363 unsigned int *data);
H Hartley Sweetene523c6c2013-08-06 09:31:35 -0700364
H Hartley Sweeten54db9962013-06-24 16:55:14 -0700365void *comedi_alloc_devpriv(struct comedi_device *, size_t);
H Hartley Sweeten1ae6b202013-01-30 15:24:38 -0700366int comedi_alloc_subdevices(struct comedi_device *, int);
367
H Hartley Sweeten9ff8b152013-05-17 11:17:00 -0700368int comedi_load_firmware(struct comedi_device *, struct device *,
369 const char *name,
370 int (*cb)(struct comedi_device *,
H Hartley Sweetend5695412013-05-17 11:18:01 -0700371 const u8 *data, size_t size,
372 unsigned long context),
373 unsigned long context);
H Hartley Sweeten9ff8b152013-05-17 11:17:00 -0700374
H Hartley Sweetenca8b2962013-04-09 16:30:11 -0700375int __comedi_request_region(struct comedi_device *,
376 unsigned long start, unsigned long len);
H Hartley Sweetenf375ac52013-04-09 16:05:54 -0700377int comedi_request_region(struct comedi_device *,
378 unsigned long start, unsigned long len);
H Hartley Sweeten316f97f2013-04-18 14:31:29 -0700379void comedi_legacy_detach(struct comedi_device *);
H Hartley Sweetenf375ac52013-04-09 16:05:54 -0700380
H Hartley Sweeten1ae6b202013-01-30 15:24:38 -0700381int comedi_auto_config(struct device *, struct comedi_driver *,
382 unsigned long context);
383void comedi_auto_unconfig(struct device *);
384
385int comedi_driver_register(struct comedi_driver *);
Ian Abbott99c0e262013-06-27 14:50:57 +0100386void comedi_driver_unregister(struct comedi_driver *);
H Hartley Sweeten1ae6b202013-01-30 15:24:38 -0700387
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 Abbott581a7dd2012-11-14 13:10:40 +0000399
H Hartley Sweeten33782dd2013-01-30 15:22:21 -0700400#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 Sweeten33782dd2013-01-30 15:22:21 -0700409#define PCI_VENDOR_ID_DT 0x1116
410#define PCI_VENDOR_ID_IOTECH 0x1616
411#define PCI_VENDOR_ID_CONTEC 0x1221
H Hartley Sweeten33782dd2013-01-30 15:22:21 -0700412#define PCI_VENDOR_ID_RTD 0x1435
H Hartley Sweeten33782dd2013-01-30 15:22:21 -0700413
414struct pci_dev;
415struct pci_driver;
416
417struct pci_dev *comedi_to_pci_dev(struct comedi_device *);
418
H Hartley Sweeten818f5692013-03-13 10:36:31 -0700419int comedi_pci_enable(struct comedi_device *);
H Hartley Sweeten7f072f52013-03-13 10:35:51 -0700420void comedi_pci_disable(struct comedi_device *);
H Hartley Sweeten33782dd2013-01-30 15:22:21 -0700421
H Hartley Sweetenb8f4ac22013-03-05 09:53:41 -0700422int comedi_pci_auto_config(struct pci_dev *, struct comedi_driver *,
423 unsigned long context);
H Hartley Sweeten33782dd2013-01-30 15:22:21 -0700424void comedi_pci_auto_unconfig(struct pci_dev *);
425
426int comedi_pci_driver_register(struct comedi_driver *, struct pci_driver *);
427void 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
451static inline struct pci_dev *comedi_to_pci_dev(struct comedi_device *dev)
Ian Abbott581a7dd2012-11-14 13:10:40 +0000452{
H Hartley Sweeten33782dd2013-01-30 15:22:21 -0700453 return NULL;
Ian Abbott581a7dd2012-11-14 13:10:40 +0000454}
455
H Hartley Sweeten818f5692013-03-13 10:36:31 -0700456static inline int comedi_pci_enable(struct comedi_device *dev)
H Hartley Sweeten33782dd2013-01-30 15:22:21 -0700457{
458 return -ENOSYS;
459}
460
H Hartley Sweeten7f072f52013-03-13 10:35:51 -0700461static inline void comedi_pci_disable(struct comedi_device *dev)
H Hartley Sweeten33782dd2013-01-30 15:22:21 -0700462{
463}
464
465#endif /* CONFIG_COMEDI_PCI_DRIVERS */
Ian Abbott581a7dd2012-11-14 13:10:40 +0000466
H Hartley Sweeten309231d2013-01-30 15:22:44 -0700467#ifdef CONFIG_COMEDI_PCMCIA_DRIVERS
468
469/* comedi_pcmcia.c - comedi PCMCIA driver specific functions */
470
471struct pcmcia_driver;
H Hartley Sweeten1f021e1f2013-01-30 15:23:06 -0700472struct pcmcia_device;
473
474struct pcmcia_device *comedi_to_pcmcia_dev(struct comedi_device *);
475
H Hartley Sweetena3ac9512013-02-05 18:16:07 -0700476int comedi_pcmcia_enable(struct comedi_device *,
477 int (*conf_check)(struct pcmcia_device *, void *));
H Hartley Sweetenddb2d0a2013-02-04 14:19:35 -0700478void comedi_pcmcia_disable(struct comedi_device *);
479
H Hartley Sweeten1f021e1f2013-01-30 15:23:06 -0700480int comedi_pcmcia_auto_config(struct pcmcia_device *, struct comedi_driver *);
481void comedi_pcmcia_auto_unconfig(struct pcmcia_device *);
H Hartley Sweeten309231d2013-01-30 15:22:44 -0700482
483int comedi_pcmcia_driver_register(struct comedi_driver *,
484 struct pcmcia_driver *);
485void 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 Sweetenabac8b52013-01-30 15:21:49 -0700504#ifdef CONFIG_COMEDI_USB_DRIVERS
Ian Abbott581a7dd2012-11-14 13:10:40 +0000505
H Hartley Sweetenabac8b52013-01-30 15:21:49 -0700506/* comedi_usb.c - comedi USB driver specific functions */
507
508struct usb_driver;
509struct usb_interface;
510
511struct usb_interface *comedi_to_usb_interface(struct comedi_device *);
H Hartley Sweeten61dd1492013-05-20 14:20:02 -0700512struct usb_device *comedi_to_usb_dev(struct comedi_device *);
H Hartley Sweetenabac8b52013-01-30 15:21:49 -0700513
H Hartley Sweeten55ab4f62013-02-05 17:23:40 -0700514int comedi_usb_auto_config(struct usb_interface *, struct comedi_driver *,
515 unsigned long context);
H Hartley Sweetenabac8b52013-01-30 15:21:49 -0700516void comedi_usb_auto_unconfig(struct usb_interface *);
517
518int comedi_usb_driver_register(struct comedi_driver *, struct usb_driver *);
519void 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 Schleefed9eccb2008-11-04 20:29:31 -0800536
David Schleefed9eccb2008-11-04 20:29:31 -0800537#endif /* _COMEDIDEV_H */