2 * Copyright (C) 2005 Meilhaus Electronic GmbH (support@meilhaus.de)
4 * Source File : memain.h
5 * Author : GG (Guenter Gebhardt) <g.gebhardt@meilhaus.de>
11 #include "meinternal.h"
17 /*#include "me1000_device.h"
18 #include "me1400_device.h"
19 #include "me1600_device.h"*/
20 #include "me4600_device.h"
21 /*#include "me6000_device.h"
22 #include "me0600_device.h"
23 #include "me8100_device.h"
24 #include "me8200_device.h"
25 #include "me0900_device.h"*/
30 /*=============================================================================
32 This is used by modprobe to translate PCI IDs to drivers.
33 ===========================================================================*/
35 static struct pci_device_id me_pci_table[] __devinitdata = {
36 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME1000, PCI_ANY_ID,
38 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME1000_A, PCI_ANY_ID,
40 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME1000_B, PCI_ANY_ID,
43 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME1400, PCI_ANY_ID,
45 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME140A, PCI_ANY_ID,
47 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME140B, PCI_ANY_ID,
49 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME14E0, PCI_ANY_ID,
51 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME14EA, PCI_ANY_ID,
53 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME14EB, PCI_ANY_ID,
55 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME140C, PCI_ANY_ID,
57 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME140D, PCI_ANY_ID,
60 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME1600_4U, PCI_ANY_ID,
62 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME1600_8U, PCI_ANY_ID,
64 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME1600_12U, PCI_ANY_ID,
66 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME1600_16U, PCI_ANY_ID,
68 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME1600_16U_8I,
69 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
71 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME4610, PCI_ANY_ID,
73 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME4650, PCI_ANY_ID,
75 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME4660, PCI_ANY_ID,
77 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME4660I, PCI_ANY_ID,
79 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME4670, PCI_ANY_ID,
81 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME4670I, PCI_ANY_ID,
83 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME4670S, PCI_ANY_ID,
85 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME4670IS, PCI_ANY_ID,
87 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME4680, PCI_ANY_ID,
89 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME4680I, PCI_ANY_ID,
91 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME4680S, PCI_ANY_ID,
93 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME4680IS, PCI_ANY_ID,
96 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME6004, PCI_ANY_ID,
98 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME6008, PCI_ANY_ID,
100 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME600F, PCI_ANY_ID,
101 PCI_ANY_ID, 0, 0, 0},
103 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME6014, PCI_ANY_ID,
104 PCI_ANY_ID, 0, 0, 0},
105 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME6018, PCI_ANY_ID,
106 PCI_ANY_ID, 0, 0, 0},
107 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME601F, PCI_ANY_ID,
108 PCI_ANY_ID, 0, 0, 0},
110 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME6034, PCI_ANY_ID,
111 PCI_ANY_ID, 0, 0, 0},
112 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME6038, PCI_ANY_ID,
113 PCI_ANY_ID, 0, 0, 0},
114 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME603F, PCI_ANY_ID,
115 PCI_ANY_ID, 0, 0, 0},
117 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME6104, PCI_ANY_ID,
118 PCI_ANY_ID, 0, 0, 0},
119 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME6108, PCI_ANY_ID,
120 PCI_ANY_ID, 0, 0, 0},
121 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME610F, PCI_ANY_ID,
122 PCI_ANY_ID, 0, 0, 0},
124 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME6114, PCI_ANY_ID,
125 PCI_ANY_ID, 0, 0, 0},
126 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME6118, PCI_ANY_ID,
127 PCI_ANY_ID, 0, 0, 0},
128 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME611F, PCI_ANY_ID,
129 PCI_ANY_ID, 0, 0, 0},
131 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME6134, PCI_ANY_ID,
132 PCI_ANY_ID, 0, 0, 0},
133 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME6138, PCI_ANY_ID,
134 PCI_ANY_ID, 0, 0, 0},
135 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME613F, PCI_ANY_ID,
136 PCI_ANY_ID, 0, 0, 0},
138 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME6044, PCI_ANY_ID,
139 PCI_ANY_ID, 0, 0, 0},
140 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME6048, PCI_ANY_ID,
141 PCI_ANY_ID, 0, 0, 0},
142 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME604F, PCI_ANY_ID,
143 PCI_ANY_ID, 0, 0, 0},
145 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME6054, PCI_ANY_ID,
146 PCI_ANY_ID, 0, 0, 0},
147 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME6058, PCI_ANY_ID,
148 PCI_ANY_ID, 0, 0, 0},
149 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME605F, PCI_ANY_ID,
150 PCI_ANY_ID, 0, 0, 0},
152 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME6074, PCI_ANY_ID,
153 PCI_ANY_ID, 0, 0, 0},
154 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME6078, PCI_ANY_ID,
155 PCI_ANY_ID, 0, 0, 0},
156 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME607F, PCI_ANY_ID,
157 PCI_ANY_ID, 0, 0, 0},
159 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME6144, PCI_ANY_ID,
160 PCI_ANY_ID, 0, 0, 0},
161 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME6148, PCI_ANY_ID,
162 PCI_ANY_ID, 0, 0, 0},
163 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME614F, PCI_ANY_ID,
164 PCI_ANY_ID, 0, 0, 0},
166 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME6154, PCI_ANY_ID,
167 PCI_ANY_ID, 0, 0, 0},
168 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME6158, PCI_ANY_ID,
169 PCI_ANY_ID, 0, 0, 0},
170 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME615F, PCI_ANY_ID,
171 PCI_ANY_ID, 0, 0, 0},
173 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME6174, PCI_ANY_ID,
174 PCI_ANY_ID, 0, 0, 0},
175 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME6178, PCI_ANY_ID,
176 PCI_ANY_ID, 0, 0, 0},
177 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME617F, PCI_ANY_ID,
178 PCI_ANY_ID, 0, 0, 0},
180 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME6259, PCI_ANY_ID,
181 PCI_ANY_ID, 0, 0, 0},
183 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME6359, PCI_ANY_ID,
184 PCI_ANY_ID, 0, 0, 0},
186 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME0630, PCI_ANY_ID,
187 PCI_ANY_ID, 0, 0, 0},
189 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME8100_A, PCI_ANY_ID,
190 PCI_ANY_ID, 0, 0, 0},
191 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME8100_B, PCI_ANY_ID,
192 PCI_ANY_ID, 0, 0, 0},
194 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME8200_A, PCI_ANY_ID,
195 PCI_ANY_ID, 0, 0, 0},
196 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME8200_B, PCI_ANY_ID,
197 PCI_ANY_ID, 0, 0, 0},
199 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME0940, PCI_ANY_ID,
200 PCI_ANY_ID, 0, 0, 0},
201 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME0950, PCI_ANY_ID,
202 PCI_ANY_ID, 0, 0, 0},
203 {PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME0960, PCI_ANY_ID,
204 PCI_ANY_ID, 0, 0, 0},
209 MODULE_DEVICE_TABLE(pci, me_pci_table);
211 /*=============================================================================
213 This is used by modprobe to translate USB IDs to drivers.
214 ===========================================================================*/
216 static struct usb_device_id me_usb_table[] __devinitdata = {
217 { USB_DEVICE(USB_VENDOR_ID_MEPHISTO_S1, USB_DEVICE_ID_MEPHISTO_S1) },
221 MODULE_DEVICE_TABLE (usb, me_usb_table);
224 /*=============================================================================
226 ===========================================================================*/
228 #define ME_LOCK_MULTIPLEX_TEMPLATE(NAME, TYPE, CALL, DEV_CALL, ARGS) \
229 static int CALL(struct file *filep, TYPE *arg){ \
232 struct list_head *pos; \
233 me_device_t *device; \
236 PDEBUG("executed.\n"); \
238 err = copy_from_user(&karg, arg, sizeof(TYPE)); \
240 PERROR("Can't copy arguments to kernel space\n"); \
244 down_read(&me_rwsem); \
246 list_for_each(pos, &me_device_list){ \
247 if(k == karg.device){ \
248 device = list_entry(pos, me_device_t, list); \
254 if(pos == &me_device_list){ \
255 PERROR("Invalid device number specified\n"); \
256 karg.errno = ME_ERRNO_INVALID_DEVICE; \
259 spin_lock(&me_lock); \
260 if((me_filep != NULL) && (me_filep != filep)){ \
261 spin_unlock(&me_lock); \
262 PERROR("Resource is locked by another process\n"); \
263 if(karg.lock == ME_LOCK_SET) \
264 karg.errno = ME_ERRNO_LOCKED; \
265 else if(karg.lock == ME_LOCK_RELEASE) \
266 karg.errno = ME_ERRNO_SUCCESS; \
268 PERROR("Invalid lock specified\n"); \
269 karg.errno = ME_ERRNO_INVALID_LOCK; \
274 spin_unlock(&me_lock); \
276 karg.errno = device->DEV_CALL ARGS; \
278 spin_lock(&me_lock); \
280 spin_unlock(&me_lock); \
284 up_read(&me_rwsem); \
286 err = copy_to_user(arg, &karg, sizeof(TYPE)); \
288 PERROR("Can't copy arguments back to user space\n"); \
292 return ME_ERRNO_SUCCESS; \
295 #define ME_IO_MULTIPLEX_TEMPLATE(NAME, TYPE, CALL, DEV_CALL, ARGS) \
296 static int CALL(struct file *filep, TYPE *arg){ \
299 struct list_head *pos; \
300 me_device_t *device; \
303 PDEBUG("executed.\n"); \
305 err = copy_from_user(&karg, arg, sizeof(TYPE)); \
307 PERROR("Can't copy arguments to kernel space\n"); \
311 down_read(&me_rwsem); \
313 list_for_each(pos, &me_device_list){ \
314 if(k == karg.device){ \
315 device = list_entry(pos, me_device_t, list); \
321 if(pos == &me_device_list){ \
322 PERROR("Invalid device number specified\n"); \
323 karg.errno = ME_ERRNO_INVALID_DEVICE; \
326 spin_lock(&me_lock); \
327 if((me_filep != NULL) && (me_filep != filep)){ \
328 spin_unlock(&me_lock); \
329 PERROR("Resource is locked by another process\n"); \
330 karg.errno = ME_ERRNO_LOCKED; \
334 spin_unlock(&me_lock); \
336 karg.errno = device->DEV_CALL ARGS; \
338 spin_lock(&me_lock); \
340 spin_unlock(&me_lock); \
344 up_read(&me_rwsem); \
346 err = copy_to_user(arg, &karg, sizeof(TYPE)); \
348 PERROR("Can't copy arguments back to user space\n"); \
352 return ME_ERRNO_SUCCESS; \
355 #define ME_QUERY_MULTIPLEX_STR_TEMPLATE(NAME, TYPE, CALL, DEV_CALL, ARGS) \
356 static int CALL(struct file *filep, TYPE *arg){ \
359 struct list_head *pos; \
360 me_device_t *device; \
364 PDEBUG("executed.\n"); \
366 err = copy_from_user(&karg, arg, sizeof(TYPE)); \
368 PERROR("Can't copy arguments to kernel space\n"); \
372 down_read(&me_rwsem); \
374 list_for_each(pos, &me_device_list){ \
375 if(k == karg.device){ \
376 device = list_entry(pos, me_device_t, list); \
382 if(pos == &me_device_list){ \
383 PERROR("Invalid device number specified\n"); \
384 karg.errno = ME_ERRNO_INVALID_DEVICE; \
387 karg.errno = device->DEV_CALL ARGS; \
389 if((strlen(msg) + 1) > karg.count){ \
390 PERROR("User buffer for device name is to little\n"); \
391 karg.errno = ME_ERRNO_USER_BUFFER_SIZE; \
394 err = copy_to_user(karg.name, msg, strlen(msg) + 1); \
396 PERROR("Can't copy device name to user space\n"); \
403 up_read(&me_rwsem); \
405 err = copy_to_user(arg, &karg, sizeof(TYPE)); \
407 PERROR("Can't copy query back to user space\n"); \
411 return ME_ERRNO_SUCCESS; \
414 #define ME_QUERY_MULTIPLEX_TEMPLATE(NAME, TYPE, CALL, DEV_CALL, ARGS) \
415 static int CALL(struct file *filep, TYPE *arg){ \
418 struct list_head *pos; \
419 me_device_t *device; \
422 PDEBUG("executed.\n"); \
424 err = copy_from_user(&karg, arg, sizeof(TYPE)); \
426 PERROR("Can't copy arguments from user space\n"); \
430 down_read(&me_rwsem); \
432 list_for_each(pos, &me_device_list){ \
433 if(k == karg.device){ \
434 device = list_entry(pos, me_device_t, list); \
440 if(pos == &me_device_list){ \
441 PERROR("Invalid device number specified\n"); \
442 karg.errno = ME_ERRNO_INVALID_DEVICE; \
445 karg.errno = device->DEV_CALL ARGS; \
448 up_read(&me_rwsem); \
450 err = copy_to_user(arg, &karg, sizeof(TYPE)); \
452 PERROR("Can't copy arguments to user space\n"); \
456 return ME_ERRNO_SUCCESS; \