blob: b75915f30f48492c99060bb23a805cc6721fe0b3 [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
22#include <linux/kernel.h>
23#include <linux/module.h>
David Schleefed9eccb2008-11-04 20:29:31 -080024#include <linux/kdev_t.h>
25#include <linux/slab.h>
Randy Dunlapf9c51372009-06-05 11:10:42 -070026#include <linux/delay.h>
David Schleefed9eccb2008-11-04 20:29:31 -080027#include <linux/errno.h>
28#include <linux/spinlock.h>
29#include <linux/mutex.h>
30#include <linux/wait.h>
31#include <linux/mm.h>
32#include <linux/init.h>
33#include <linux/vmalloc.h>
David Schleefed9eccb2008-11-04 20:29:31 -080034#include <linux/dma-mapping.h>
Greg Kroah-Hartmane0dcef72008-11-13 16:36:22 -080035#include <linux/uaccess.h>
36#include <linux/io.h>
Greg Kroah-Hartmanc7a5d702009-06-19 11:04:32 -070037#include <linux/timer.h>
David Schleefed9eccb2008-11-04 20:29:31 -080038
39#include "comedi.h"
40
Greg Kroah-Hartmane0dcef72008-11-13 16:36:22 -080041#define DPRINTK(format, args...) do { \
42 if (comedi_debug) \
Ian Abbott4f870fe2012-08-16 14:38:05 +010043 pr_debug("comedi: " format, ## args); \
Greg Kroah-Hartmane0dcef72008-11-13 16:36:22 -080044} while (0)
David Schleefed9eccb2008-11-04 20:29:31 -080045
Greg Kroah-Hartmane0dcef72008-11-13 16:36:22 -080046#define COMEDI_VERSION(a, b, c) (((a) << 16) + ((b) << 8) + (c))
Shane Warden62eeae92009-09-22 16:13:04 -070047#define COMEDI_VERSION_CODE COMEDI_VERSION(COMEDI_MAJORVERSION, \
48 COMEDI_MINORVERSION, COMEDI_MICROVERSION)
David Schleefed9eccb2008-11-04 20:29:31 -080049#define COMEDI_RELEASE VERSION
50
David Schleefed9eccb2008-11-04 20:29:31 -080051#define COMEDI_NUM_BOARD_MINORS 0x30
David Schleefed9eccb2008-11-04 20:29:31 -080052
Bill Pemberton34c43922009-03-16 22:05:14 -040053struct comedi_subdevice {
Bill Pemberton71b5f4f2009-03-16 22:05:08 -040054 struct comedi_device *device;
H Hartley Sweeten90a35c12012-12-19 17:27:02 -070055 int index;
David Schleefed9eccb2008-11-04 20:29:31 -080056 int type;
57 int n_chan;
Greg Kroah-Hartmanbaf22b62010-04-30 15:26:54 -070058 int subdev_flags;
David Schleefed9eccb2008-11-04 20:29:31 -080059 int len_chanlist; /* maximum length of channel/gain list */
60
61 void *private;
62
Bill Pembertond1636792009-03-16 22:05:20 -040063 struct comedi_async *async;
David Schleefed9eccb2008-11-04 20:29:31 -080064
65 void *lock;
66 void *busy;
67 unsigned runflags;
68 spinlock_t spin_lock;
69
H Hartley Sweetend4a7dc82012-06-18 14:45:42 -070070 unsigned int io_bits;
David Schleefed9eccb2008-11-04 20:29:31 -080071
Bill Pemberton790c5542009-03-16 22:05:02 -040072 unsigned int maxdata; /* if maxdata==0, use list */
73 const unsigned int *maxdata_list; /* list is channel specific */
David Schleefed9eccb2008-11-04 20:29:31 -080074
75 unsigned int flags;
76 const unsigned int *flaglist;
77
78 unsigned int settling_time_0;
79
Bill Pemberton9ced1de2009-03-16 22:05:31 -040080 const struct comedi_lrange *range_table;
81 const struct comedi_lrange *const *range_table_list;
David Schleefed9eccb2008-11-04 20:29:31 -080082
83 unsigned int *chanlist; /* driver-owned chanlist (not used) */
84
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +053085 int (*insn_read) (struct comedi_device *, struct comedi_subdevice *,
86 struct comedi_insn *, unsigned int *);
87 int (*insn_write) (struct comedi_device *, struct comedi_subdevice *,
88 struct comedi_insn *, unsigned int *);
89 int (*insn_bits) (struct comedi_device *, struct comedi_subdevice *,
90 struct comedi_insn *, unsigned int *);
91 int (*insn_config) (struct comedi_device *, struct comedi_subdevice *,
92 struct comedi_insn *, unsigned int *);
David Schleefed9eccb2008-11-04 20:29:31 -080093
Bill Pemberton34c43922009-03-16 22:05:14 -040094 int (*do_cmd) (struct comedi_device *, struct comedi_subdevice *);
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +053095 int (*do_cmdtest) (struct comedi_device *, struct comedi_subdevice *,
96 struct comedi_cmd *);
Bill Pemberton34c43922009-03-16 22:05:14 -040097 int (*poll) (struct comedi_device *, struct comedi_subdevice *);
98 int (*cancel) (struct comedi_device *, struct comedi_subdevice *);
Shane Warden62eeae92009-09-22 16:13:04 -070099 /* int (*do_lock)(struct comedi_device *, struct comedi_subdevice *); */
100 /* int (*do_unlock)(struct comedi_device *, \
101 struct comedi_subdevice *); */
David Schleefed9eccb2008-11-04 20:29:31 -0800102
103 /* called when the buffer changes */
Shane Warden62eeae92009-09-22 16:13:04 -0700104 int (*buf_change) (struct comedi_device *dev,
105 struct comedi_subdevice *s, unsigned long new_size);
David Schleefed9eccb2008-11-04 20:29:31 -0800106
Shane Warden62eeae92009-09-22 16:13:04 -0700107 void (*munge) (struct comedi_device *dev, struct comedi_subdevice *s,
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530108 void *data, unsigned int num_bytes,
109 unsigned int start_chan_index);
David Schleefed9eccb2008-11-04 20:29:31 -0800110 enum dma_data_direction async_dma_dir;
111
112 unsigned int state;
113
Bill Pemberton0bfbbe82009-03-16 22:05:36 -0400114 struct device *class_dev;
David Schleefed9eccb2008-11-04 20:29:31 -0800115 int minor;
116};
117
118struct comedi_buf_page {
119 void *virt_addr;
120 dma_addr_t dma_addr;
121};
122
Bill Pembertond1636792009-03-16 22:05:20 -0400123struct comedi_async {
Bill Pemberton34c43922009-03-16 22:05:14 -0400124 struct comedi_subdevice *subdevice;
David Schleefed9eccb2008-11-04 20:29:31 -0800125
126 void *prealloc_buf; /* pre-allocated buffer */
127 unsigned int prealloc_bufsz; /* buffer size, in bytes */
Shane Warden62eeae92009-09-22 16:13:04 -0700128 /* virtual and dma address of each page */
129 struct comedi_buf_page *buf_page_list;
David Schleefed9eccb2008-11-04 20:29:31 -0800130 unsigned n_buf_pages; /* num elements in buf_page_list */
131
132 unsigned int max_bufsize; /* maximum buffer size, bytes */
Shane Warden62eeae92009-09-22 16:13:04 -0700133 /* current number of mmaps of prealloc_buf */
134 unsigned int mmap_count;
David Schleefed9eccb2008-11-04 20:29:31 -0800135
Shane Warden62eeae92009-09-22 16:13:04 -0700136 /* byte count for writer (write completed) */
137 unsigned int buf_write_count;
138 /* byte count for writer (allocated for writing) */
139 unsigned int buf_write_alloc_count;
140 /* byte count for reader (read completed) */
141 unsigned int buf_read_count;
142 /* byte count for reader (allocated for reading) */
143 unsigned int buf_read_alloc_count;
David Schleefed9eccb2008-11-04 20:29:31 -0800144
145 unsigned int buf_write_ptr; /* buffer marker for writer */
146 unsigned int buf_read_ptr; /* buffer marker for reader */
147
148 unsigned int cur_chan; /* useless channel marker for interrupt */
149 /* number of bytes that have been received for current scan */
150 unsigned int scan_progress;
151 /* keeps track of where we are in chanlist as for munging */
152 unsigned int munge_chan;
153 /* number of bytes that have been munged */
154 unsigned int munge_count;
155 /* buffer marker for munging */
156 unsigned int munge_ptr;
157
158 unsigned int events; /* events that have occurred */
159
Bill Pembertonea6d0d42009-03-16 22:05:47 -0400160 struct comedi_cmd cmd;
David Schleefed9eccb2008-11-04 20:29:31 -0800161
162 wait_queue_head_t wait_head;
163
Greg Kroah-Hartmane0dcef72008-11-13 16:36:22 -0800164 /* callback stuff */
David Schleefed9eccb2008-11-04 20:29:31 -0800165 unsigned int cb_mask;
166 int (*cb_func) (unsigned int flags, void *);
167 void *cb_arg;
168
Shane Warden62eeae92009-09-22 16:13:04 -0700169 int (*inttrig) (struct comedi_device *dev, struct comedi_subdevice *s,
Greg Kroah-Hartmane0dcef72008-11-13 16:36:22 -0800170 unsigned int x);
David Schleefed9eccb2008-11-04 20:29:31 -0800171};
172
Bill Pemberton139dfbd2009-03-16 22:05:25 -0400173struct comedi_driver {
174 struct comedi_driver *next;
David Schleefed9eccb2008-11-04 20:29:31 -0800175
176 const char *driver_name;
177 struct module *module;
Bill Pemberton0707bb02009-03-16 22:06:20 -0400178 int (*attach) (struct comedi_device *, struct comedi_devconfig *);
H Hartley Sweeten484ecc92012-05-17 17:11:14 -0700179 void (*detach) (struct comedi_device *);
Ian Abbott8ed705a2012-10-27 21:44:14 +0100180 int (*auto_attach) (struct comedi_device *, unsigned long);
David Schleefed9eccb2008-11-04 20:29:31 -0800181
182 /* number of elements in board_name and board_id arrays */
183 unsigned int num_names;
184 const char *const *board_name;
185 /* offset in bytes from one board name pointer to the next */
186 int offset;
187};
188
Bill Pemberton71b5f4f2009-03-16 22:05:08 -0400189struct comedi_device {
David Schleefed9eccb2008-11-04 20:29:31 -0800190 int use_count;
Bill Pemberton139dfbd2009-03-16 22:05:25 -0400191 struct comedi_driver *driver;
David Schleefed9eccb2008-11-04 20:29:31 -0800192 void *private;
193
Bill Pemberton0bfbbe82009-03-16 22:05:36 -0400194 struct device *class_dev;
David Schleefed9eccb2008-11-04 20:29:31 -0800195 int minor;
Greg Kroah-Hartmane0dcef72008-11-13 16:36:22 -0800196 /* hw_dev is passed to dma_alloc_coherent when allocating async buffers
197 * for subdevices that have async_dma_dir set to something other than
198 * DMA_NONE */
David Schleefed9eccb2008-11-04 20:29:31 -0800199 struct device *hw_dev;
200
201 const char *board_name;
202 const void *board_ptr;
Ian Abbotta7401cd2013-03-15 13:15:33 +0000203 bool attached:1;
Ian Abbott13f12b52013-03-15 13:15:34 +0000204 bool in_request_module:1;
Ian Abbott00ca68842013-03-15 13:15:35 +0000205 bool ioenabled:1;
David Schleefed9eccb2008-11-04 20:29:31 -0800206 spinlock_t spinlock;
207 struct mutex mutex;
David Schleefed9eccb2008-11-04 20:29:31 -0800208
209 int n_subdevices;
Bill Pemberton34c43922009-03-16 22:05:14 -0400210 struct comedi_subdevice *subdevices;
David Schleefed9eccb2008-11-04 20:29:31 -0800211
212 /* dumb */
213 unsigned long iobase;
H Hartley Sweeten316f97f2013-04-18 14:31:29 -0700214 unsigned long iolen;
David Schleefed9eccb2008-11-04 20:29:31 -0800215 unsigned int irq;
216
Bill Pemberton34c43922009-03-16 22:05:14 -0400217 struct comedi_subdevice *read_subdev;
218 struct comedi_subdevice *write_subdev;
David Schleefed9eccb2008-11-04 20:29:31 -0800219
220 struct fasync_struct *async_queue;
221
Ian Abbott3c17ba072010-05-19 14:10:00 +0100222 int (*open) (struct comedi_device *dev);
Shane Warden62eeae92009-09-22 16:13:04 -0700223 void (*close) (struct comedi_device *dev);
David Schleefed9eccb2008-11-04 20:29:31 -0800224};
225
Ian Abbott4dba6c02012-11-02 19:18:00 +0000226static inline const void *comedi_board(const struct comedi_device *dev)
H Hartley Sweeten37859f82012-04-27 14:10:15 -0700227{
228 return dev->board_ptr;
229}
230
David Schleefed9eccb2008-11-04 20:29:31 -0800231#ifdef CONFIG_COMEDI_DEBUG
232extern int comedi_debug;
233#else
Greg Kroah-Hartmane0dcef72008-11-13 16:36:22 -0800234static const int comedi_debug;
David Schleefed9eccb2008-11-04 20:29:31 -0800235#endif
236
237/*
238 * function prototypes
239 */
240
Bill Pemberton34c43922009-03-16 22:05:14 -0400241void comedi_event(struct comedi_device *dev, struct comedi_subdevice *s);
Bill Pemberton71b5f4f2009-03-16 22:05:08 -0400242void comedi_error(const struct comedi_device *dev, const char *s);
David Schleefed9eccb2008-11-04 20:29:31 -0800243
244/* we can expand the number of bits used to encode devices/subdevices into
245 the minor number soon, after more distros support > 8 bit minor numbers
246 (like after Debian Etch gets released) */
247enum comedi_minor_bits {
248 COMEDI_DEVICE_MINOR_MASK = 0xf,
249 COMEDI_SUBDEVICE_MINOR_MASK = 0xf0
250};
251static const unsigned COMEDI_SUBDEVICE_MINOR_SHIFT = 4;
252static const unsigned COMEDI_SUBDEVICE_MINOR_OFFSET = 1;
253
H Hartley Sweeten85104e92012-12-19 15:34:40 -0700254struct comedi_device *comedi_dev_from_minor(unsigned minor);
255
David Schleefed9eccb2008-11-04 20:29:31 -0800256void init_polling(void);
257void cleanup_polling(void);
Bill Pemberton71b5f4f2009-03-16 22:05:08 -0400258void start_polling(struct comedi_device *);
259void stop_polling(struct comedi_device *);
David Schleefed9eccb2008-11-04 20:29:31 -0800260
David Schleefed9eccb2008-11-04 20:29:31 -0800261/* subdevice runflags */
262enum subdevice_runflags {
263 SRF_USER = 0x00000001,
264 SRF_RT = 0x00000002,
Greg Kroah-Hartmane0dcef72008-11-13 16:36:22 -0800265 /* indicates an COMEDI_CB_ERROR event has occurred since the last
266 * command was started */
David Schleefed9eccb2008-11-04 20:29:31 -0800267 SRF_ERROR = 0x00000004,
H Hartley Sweeten588ba6d2013-06-11 11:32:29 -0700268 SRF_RUNNING = 0x08000000,
269 SRF_FREE_SPRIV = 0x80000000, /* free s->private on detach */
David Schleefed9eccb2008-11-04 20:29:31 -0800270};
271
H Hartley Sweetene0dac312012-12-19 15:42:47 -0700272bool comedi_is_subdevice_running(struct comedi_subdevice *s);
H Hartley Sweeten0480bcb2013-06-19 15:24:36 -0700273
274void *comedi_alloc_spriv(struct comedi_subdevice *s, size_t size);
H Hartley Sweetene0dac312012-12-19 15:42:47 -0700275
Mark Rankilor5e220112010-05-06 17:49:37 +0800276int comedi_check_chanlist(struct comedi_subdevice *s,
277 int n,
278 unsigned int *chanlist);
David Schleefed9eccb2008-11-04 20:29:31 -0800279
280/* range stuff */
281
Greg Kroah-Hartmane0dcef72008-11-13 16:36:22 -0800282#define RANGE(a, b) {(a)*1e6, (b)*1e6, 0}
283#define RANGE_ext(a, b) {(a)*1e6, (b)*1e6, RF_EXTERNAL}
284#define RANGE_mA(a, b) {(a)*1e6, (b)*1e6, UNIT_mA}
Greg Kroah-Hartmanbaf22b62010-04-30 15:26:54 -0700285#define RANGE_unitless(a, b) {(a)*1e6, (b)*1e6, 0}
Greg Kroah-Hartmane0dcef72008-11-13 16:36:22 -0800286#define BIP_RANGE(a) {-(a)*1e6, (a)*1e6, 0}
287#define UNI_RANGE(a) {0, (a)*1e6, 0}
David Schleefed9eccb2008-11-04 20:29:31 -0800288
Bill Pemberton9ced1de2009-03-16 22:05:31 -0400289extern const struct comedi_lrange range_bipolar10;
290extern const struct comedi_lrange range_bipolar5;
291extern const struct comedi_lrange range_bipolar2_5;
292extern const struct comedi_lrange range_unipolar10;
293extern const struct comedi_lrange range_unipolar5;
H Hartley Sweeten5f8eb722013-04-03 13:38:26 -0700294extern const struct comedi_lrange range_unipolar2_5;
H Hartley Sweeten2c71c4f2013-04-03 13:40:13 -0700295extern const struct comedi_lrange range_0_20mA;
296extern const struct comedi_lrange range_4_20mA;
297extern const struct comedi_lrange range_0_32mA;
Bill Pemberton9ced1de2009-03-16 22:05:31 -0400298extern const struct comedi_lrange range_unknown;
David Schleefed9eccb2008-11-04 20:29:31 -0800299
300#define range_digital range_unipolar5
301
302#if __GNUC__ >= 3
303#define GCC_ZERO_LENGTH_ARRAY
304#else
305#define GCC_ZERO_LENGTH_ARRAY 0
306#endif
307
Bill Pemberton9ced1de2009-03-16 22:05:31 -0400308struct comedi_lrange {
David Schleefed9eccb2008-11-04 20:29:31 -0800309 int length;
Bill Pemberton1f6325d2009-03-16 22:06:31 -0400310 struct comedi_krange range[GCC_ZERO_LENGTH_ARRAY];
David Schleefed9eccb2008-11-04 20:29:31 -0800311};
312
H Hartley Sweetene3693fd2013-06-05 15:52:31 -0700313static inline bool comedi_range_is_bipolar(struct comedi_subdevice *s,
314 unsigned int range)
315{
316 return s->range_table->range[range].min < 0;
317}
318
319static inline bool comedi_range_is_unipolar(struct comedi_subdevice *s,
320 unsigned int range)
321{
322 return s->range_table->range[range].min >= 0;
323}
324
David Schleefed9eccb2008-11-04 20:29:31 -0800325/* some silly little inline functions */
326
Bill Pemberton34c43922009-03-16 22:05:14 -0400327static inline unsigned int bytes_per_sample(const struct comedi_subdevice *subd)
David Schleefed9eccb2008-11-04 20:29:31 -0800328{
329 if (subd->subdev_flags & SDF_LSAMPL)
Bill Pemberton790c5542009-03-16 22:05:02 -0400330 return sizeof(unsigned int);
David Schleefed9eccb2008-11-04 20:29:31 -0800331 else
Bill Pemberton790c5542009-03-16 22:05:02 -0400332 return sizeof(short);
David Schleefed9eccb2008-11-04 20:29:31 -0800333}
334
Ian Abbottbc3954b2013-01-29 16:20:17 +0000335/*
336 * Must set dev->hw_dev if you wish to dma directly into comedi's buffer.
337 * Also useful for retrieving a previously configured hardware device of
338 * known bus type. Set automatically for auto-configured devices.
339 * Automatically set to NULL when detaching hardware device.
340 */
Ian Abbottda717512013-02-01 13:23:19 +0000341int comedi_set_hw_dev(struct comedi_device *dev, struct device *hw_dev);
David Schleefed9eccb2008-11-04 20:29:31 -0800342
H Hartley Sweeten8ae560a2013-01-09 13:32:56 -0700343unsigned int comedi_buf_write_alloc(struct comedi_async *, unsigned int);
344unsigned int comedi_buf_write_free(struct comedi_async *, unsigned int);
David Schleefed9eccb2008-11-04 20:29:31 -0800345
H Hartley Sweeten8ae560a2013-01-09 13:32:56 -0700346unsigned int comedi_buf_read_n_available(struct comedi_async *);
347unsigned int comedi_buf_read_alloc(struct comedi_async *, unsigned int);
348unsigned int comedi_buf_read_free(struct comedi_async *, unsigned int);
349
350int comedi_buf_put(struct comedi_async *, short);
351int comedi_buf_get(struct comedi_async *, short *);
352
Bill Pembertond1636792009-03-16 22:05:20 -0400353void comedi_buf_memcpy_to(struct comedi_async *async, unsigned int offset,
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530354 const void *source, unsigned int num_bytes);
Bill Pembertond1636792009-03-16 22:05:20 -0400355void comedi_buf_memcpy_from(struct comedi_async *async, unsigned int offset,
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530356 void *destination, unsigned int num_bytes);
Mithlesh Thukral0a85b6f2009-06-08 21:04:41 +0530357
H Hartley Sweeten1ae6b202013-01-30 15:24:38 -0700358/* drivers.c - general comedi driver functions */
359
360int comedi_alloc_subdevices(struct comedi_device *, int);
361
H Hartley Sweeten9ff8b152013-05-17 11:17:00 -0700362int comedi_load_firmware(struct comedi_device *, struct device *,
363 const char *name,
364 int (*cb)(struct comedi_device *,
H Hartley Sweetend5695412013-05-17 11:18:01 -0700365 const u8 *data, size_t size,
366 unsigned long context),
367 unsigned long context);
H Hartley Sweeten9ff8b152013-05-17 11:17:00 -0700368
H Hartley Sweetenca8b2962013-04-09 16:30:11 -0700369int __comedi_request_region(struct comedi_device *,
370 unsigned long start, unsigned long len);
H Hartley Sweetenf375ac52013-04-09 16:05:54 -0700371int comedi_request_region(struct comedi_device *,
372 unsigned long start, unsigned long len);
H Hartley Sweeten316f97f2013-04-18 14:31:29 -0700373void comedi_legacy_detach(struct comedi_device *);
H Hartley Sweetenf375ac52013-04-09 16:05:54 -0700374
H Hartley Sweeten1ae6b202013-01-30 15:24:38 -0700375int comedi_auto_config(struct device *, struct comedi_driver *,
376 unsigned long context);
377void comedi_auto_unconfig(struct device *);
378
379int comedi_driver_register(struct comedi_driver *);
380int comedi_driver_unregister(struct comedi_driver *);
381
382/**
383 * module_comedi_driver() - Helper macro for registering a comedi driver
384 * @__comedi_driver: comedi_driver struct
385 *
386 * Helper macro for comedi drivers which do not do anything special in module
387 * init/exit. This eliminates a lot of boilerplate. Each module may only use
388 * this macro once, and calling it replaces module_init() and module_exit().
389 */
390#define module_comedi_driver(__comedi_driver) \
391 module_driver(__comedi_driver, comedi_driver_register, \
392 comedi_driver_unregister)
Ian Abbott581a7dd2012-11-14 13:10:40 +0000393
H Hartley Sweeten33782dd2013-01-30 15:22:21 -0700394#ifdef CONFIG_COMEDI_PCI_DRIVERS
395
396/* comedi_pci.c - comedi PCI driver specific functions */
397
398/*
399 * PCI Vendor IDs not in <linux/pci_ids.h>
400 */
401#define PCI_VENDOR_ID_KOLTER 0x1001
402#define PCI_VENDOR_ID_ICP 0x104c
403#define PCI_VENDOR_ID_AMCC 0x10e8
404#define PCI_VENDOR_ID_DT 0x1116
405#define PCI_VENDOR_ID_IOTECH 0x1616
406#define PCI_VENDOR_ID_CONTEC 0x1221
H Hartley Sweeten33782dd2013-01-30 15:22:21 -0700407#define PCI_VENDOR_ID_RTD 0x1435
H Hartley Sweeten33782dd2013-01-30 15:22:21 -0700408
409struct pci_dev;
410struct pci_driver;
411
412struct pci_dev *comedi_to_pci_dev(struct comedi_device *);
413
H Hartley Sweeten818f5692013-03-13 10:36:31 -0700414int comedi_pci_enable(struct comedi_device *);
H Hartley Sweeten7f072f52013-03-13 10:35:51 -0700415void comedi_pci_disable(struct comedi_device *);
H Hartley Sweeten33782dd2013-01-30 15:22:21 -0700416
H Hartley Sweetenb8f4ac22013-03-05 09:53:41 -0700417int comedi_pci_auto_config(struct pci_dev *, struct comedi_driver *,
418 unsigned long context);
H Hartley Sweeten33782dd2013-01-30 15:22:21 -0700419void comedi_pci_auto_unconfig(struct pci_dev *);
420
421int comedi_pci_driver_register(struct comedi_driver *, struct pci_driver *);
422void comedi_pci_driver_unregister(struct comedi_driver *, struct pci_driver *);
423
424/**
425 * module_comedi_pci_driver() - Helper macro for registering a comedi PCI driver
426 * @__comedi_driver: comedi_driver struct
427 * @__pci_driver: pci_driver struct
428 *
429 * Helper macro for comedi PCI drivers which do not do anything special
430 * in module init/exit. This eliminates a lot of boilerplate. Each
431 * module may only use this macro once, and calling it replaces
432 * module_init() and module_exit()
433 */
434#define module_comedi_pci_driver(__comedi_driver, __pci_driver) \
435 module_driver(__comedi_driver, comedi_pci_driver_register, \
436 comedi_pci_driver_unregister, &(__pci_driver))
437
438#else
439
440/*
441 * Some of the comedi mixed ISA/PCI drivers call the PCI specific
442 * functions. Provide some dummy functions if CONFIG_COMEDI_PCI_DRIVERS
443 * is not enabled.
444 */
445
446static inline struct pci_dev *comedi_to_pci_dev(struct comedi_device *dev)
Ian Abbott581a7dd2012-11-14 13:10:40 +0000447{
H Hartley Sweeten33782dd2013-01-30 15:22:21 -0700448 return NULL;
Ian Abbott581a7dd2012-11-14 13:10:40 +0000449}
450
H Hartley Sweeten818f5692013-03-13 10:36:31 -0700451static inline int comedi_pci_enable(struct comedi_device *dev)
H Hartley Sweeten33782dd2013-01-30 15:22:21 -0700452{
453 return -ENOSYS;
454}
455
H Hartley Sweeten7f072f52013-03-13 10:35:51 -0700456static inline void comedi_pci_disable(struct comedi_device *dev)
H Hartley Sweeten33782dd2013-01-30 15:22:21 -0700457{
458}
459
460#endif /* CONFIG_COMEDI_PCI_DRIVERS */
Ian Abbott581a7dd2012-11-14 13:10:40 +0000461
H Hartley Sweeten309231d2013-01-30 15:22:44 -0700462#ifdef CONFIG_COMEDI_PCMCIA_DRIVERS
463
464/* comedi_pcmcia.c - comedi PCMCIA driver specific functions */
465
466struct pcmcia_driver;
H Hartley Sweeten1f021e1f2013-01-30 15:23:06 -0700467struct pcmcia_device;
468
469struct pcmcia_device *comedi_to_pcmcia_dev(struct comedi_device *);
470
H Hartley Sweetena3ac9512013-02-05 18:16:07 -0700471int comedi_pcmcia_enable(struct comedi_device *,
472 int (*conf_check)(struct pcmcia_device *, void *));
H Hartley Sweetenddb2d0a2013-02-04 14:19:35 -0700473void comedi_pcmcia_disable(struct comedi_device *);
474
H Hartley Sweeten1f021e1f2013-01-30 15:23:06 -0700475int comedi_pcmcia_auto_config(struct pcmcia_device *, struct comedi_driver *);
476void comedi_pcmcia_auto_unconfig(struct pcmcia_device *);
H Hartley Sweeten309231d2013-01-30 15:22:44 -0700477
478int comedi_pcmcia_driver_register(struct comedi_driver *,
479 struct pcmcia_driver *);
480void comedi_pcmcia_driver_unregister(struct comedi_driver *,
481 struct pcmcia_driver *);
482
483/**
484 * module_comedi_pcmcia_driver() - Helper macro for registering a comedi PCMCIA driver
485 * @__comedi_driver: comedi_driver struct
486 * @__pcmcia_driver: pcmcia_driver struct
487 *
488 * Helper macro for comedi PCMCIA drivers which do not do anything special
489 * in module init/exit. This eliminates a lot of boilerplate. Each
490 * module may only use this macro once, and calling it replaces
491 * module_init() and module_exit()
492 */
493#define module_comedi_pcmcia_driver(__comedi_driver, __pcmcia_driver) \
494 module_driver(__comedi_driver, comedi_pcmcia_driver_register, \
495 comedi_pcmcia_driver_unregister, &(__pcmcia_driver))
496
497#endif /* CONFIG_COMEDI_PCMCIA_DRIVERS */
498
H Hartley Sweetenabac8b52013-01-30 15:21:49 -0700499#ifdef CONFIG_COMEDI_USB_DRIVERS
Ian Abbott581a7dd2012-11-14 13:10:40 +0000500
H Hartley Sweetenabac8b52013-01-30 15:21:49 -0700501/* comedi_usb.c - comedi USB driver specific functions */
502
503struct usb_driver;
504struct usb_interface;
505
506struct usb_interface *comedi_to_usb_interface(struct comedi_device *);
H Hartley Sweeten61dd1492013-05-20 14:20:02 -0700507struct usb_device *comedi_to_usb_dev(struct comedi_device *);
H Hartley Sweetenabac8b52013-01-30 15:21:49 -0700508
H Hartley Sweeten55ab4f62013-02-05 17:23:40 -0700509int comedi_usb_auto_config(struct usb_interface *, struct comedi_driver *,
510 unsigned long context);
H Hartley Sweetenabac8b52013-01-30 15:21:49 -0700511void comedi_usb_auto_unconfig(struct usb_interface *);
512
513int comedi_usb_driver_register(struct comedi_driver *, struct usb_driver *);
514void comedi_usb_driver_unregister(struct comedi_driver *, struct usb_driver *);
515
516/**
517 * module_comedi_usb_driver() - Helper macro for registering a comedi USB driver
518 * @__comedi_driver: comedi_driver struct
519 * @__usb_driver: usb_driver struct
520 *
521 * Helper macro for comedi USB drivers which do not do anything special
522 * in module init/exit. This eliminates a lot of boilerplate. Each
523 * module may only use this macro once, and calling it replaces
524 * module_init() and module_exit()
525 */
526#define module_comedi_usb_driver(__comedi_driver, __usb_driver) \
527 module_driver(__comedi_driver, comedi_usb_driver_register, \
528 comedi_usb_driver_unregister, &(__usb_driver))
529
530#endif /* CONFIG_COMEDI_USB_DRIVERS */
David Schleefed9eccb2008-11-04 20:29:31 -0800531
David Schleefed9eccb2008-11-04 20:29:31 -0800532#endif /* _COMEDIDEV_H */