staging: meilhaus, annotate cpi functions
[linux-2.6/mini2440.git] / drivers / staging / meilhaus / memain.c
blob2631587fa0509ec2bd3d43ae1fd649bb2a149590
1 /**
2 * @file memain.c
4 * @brief Main Meilhaus device driver.
5 * @note Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de)
6 * @author Guenter Gebhardt
7 * @author Krzysztof Gantzke (k.gantzke@meilhaus.de)
8 */
11 * Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de)
13 * This file is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #ifndef __KERNEL__
29 # define __KERNEL__
30 #endif
32 #ifndef MODULE
33 # define MODULE
34 #endif
36 #include <linux/module.h>
37 #include <linux/pci.h>
38 //#include <linux/usb.h>
39 #include <linux/errno.h>
40 #include <linux/uaccess.h>
41 #include <linux/miscdevice.h>
42 #include <linux/rwsem.h>
44 #include "medefines.h"
45 #include "metypes.h"
46 #include "meerror.h"
48 #include "medebug.h"
49 #include "memain.h"
50 #include "medevice.h"
51 #include "meioctl.h"
52 #include "mecommon.h"
54 /* Module parameters
57 #ifdef BOSCH
58 static unsigned int me_bosch_fw = 0;
59 EXPORT_SYMBOL(me_bosch_fw);
61 # ifdef module_param
62 module_param(me_bosch_fw, int, S_IRUGO);
63 # else
64 MODULE_PARM(me_bosch_fw, "i");
65 # endif
67 MODULE_PARM_DESC(me_bosch_fw,
68 "Flags which signals the ME-4600 driver to load the bosch firmware (default = 0).");
69 #endif //BOSCH
71 /* Global Driver Lock
74 static struct file *me_filep = NULL;
75 static int me_count = 0;
76 static DEFINE_SPINLOCK(me_lock);
77 static DECLARE_RWSEM(me_rwsem);
79 /* Board instances are kept in a global list */
80 LIST_HEAD(me_device_list);
82 /* Prototypes
85 static int me_probe_pci(struct pci_dev *dev, const struct pci_device_id *id);
86 static void me_remove_pci(struct pci_dev *dev);
87 static int insert_to_device_list(me_device_t *n_device);
88 static int replace_with_dummy(int vendor_id, int device_id, int serial_no);
89 static void clear_device_list(void);
90 static int me_open(struct inode *inode_ptr, struct file *filep);
91 static int me_release(struct inode *, struct file *);
92 static int me_ioctl(struct inode *, struct file *, unsigned int, unsigned long);
93 //static int me_probe_usb(struct usb_interface *interface, const struct usb_device_id *id);
94 //static void me_disconnect_usb(struct usb_interface *interface);
96 /* File operations provided by the module
99 static const struct file_operations me_file_operations = {
100 .owner = THIS_MODULE,
101 .ioctl = me_ioctl,
102 .open = me_open,
103 .release = me_release,
106 static struct pci_driver me_pci_driver = {
107 .name = MEMAIN_NAME,
108 .id_table = me_pci_table,
109 .probe = me_probe_pci,
110 .remove = __devexit_p(me_remove_pci),
113 /* //me_usb_driver
114 static struct usb_driver me_usb_driver =
116 .name = MEMAIN_NAME,
117 .id_table = me_usb_table,
118 .probe = me_probe_usb,
119 .disconnect = me_disconnect_usb
123 #ifdef ME_LOCK_MULTIPLEX_TEMPLATE
124 ME_LOCK_MULTIPLEX_TEMPLATE("me_lock_device",
125 me_lock_device_t,
126 me_lock_device,
127 me_device_lock_device,
128 (device, filep, karg.lock, karg.flags))
130 ME_LOCK_MULTIPLEX_TEMPLATE("me_lock_subdevice",
131 me_lock_subdevice_t,
132 me_lock_subdevice,
133 me_device_lock_subdevice,
134 (device, filep, karg.subdevice, karg.lock,
135 karg.flags))
136 #else
137 #error macro ME_LOCK_MULTIPLEX_TEMPLATE not defined
138 #endif
140 #ifdef ME_IO_MULTIPLEX_TEMPLATE
141 ME_IO_MULTIPLEX_TEMPLATE("me_io_irq_start",
142 me_io_irq_start_t,
143 me_io_irq_start,
144 me_device_io_irq_start,
145 (device,
146 filep,
147 karg.subdevice,
148 karg.channel,
149 karg.irq_source,
150 karg.irq_edge, karg.irq_arg, karg.flags))
152 ME_IO_MULTIPLEX_TEMPLATE("me_io_irq_wait",
153 me_io_irq_wait_t,
154 me_io_irq_wait,
155 me_device_io_irq_wait,
156 (device,
157 filep,
158 karg.subdevice,
159 karg.channel,
160 &karg.irq_count, &karg.value, karg.time_out, karg.flags))
162 ME_IO_MULTIPLEX_TEMPLATE("me_io_irq_stop",
163 me_io_irq_stop_t,
164 me_io_irq_stop,
165 me_device_io_irq_stop,
166 (device,
167 filep, karg.subdevice, karg.channel, karg.flags))
169 ME_IO_MULTIPLEX_TEMPLATE("me_io_reset_device",
170 me_io_reset_device_t,
171 me_io_reset_device,
172 me_device_io_reset_device, (device, filep, karg.flags))
174 ME_IO_MULTIPLEX_TEMPLATE("me_io_reset_subdevice",
175 me_io_reset_subdevice_t,
176 me_io_reset_subdevice,
177 me_device_io_reset_subdevice,
178 (device, filep, karg.subdevice, karg.flags))
180 ME_IO_MULTIPLEX_TEMPLATE("me_io_single_config",
181 me_io_single_config_t,
182 me_io_single_config,
183 me_device_io_single_config,
184 (device,
185 filep,
186 karg.subdevice,
187 karg.channel,
188 karg.single_config,
189 karg.ref,
190 karg.trig_chan,
191 karg.trig_type, karg.trig_edge, karg.flags))
193 ME_IO_MULTIPLEX_TEMPLATE("me_io_stream_new_values",
194 me_io_stream_new_values_t,
195 me_io_stream_new_values,
196 me_device_io_stream_new_values,
197 (device,
198 filep,
199 karg.subdevice, karg.time_out, &karg.count, karg.flags))
201 ME_IO_MULTIPLEX_TEMPLATE("me_io_stream_read",
202 me_io_stream_read_t,
203 me_io_stream_read,
204 me_device_io_stream_read,
205 (device,
206 filep,
207 karg.subdevice,
208 karg.read_mode, karg.values, &karg.count, karg.flags))
210 ME_IO_MULTIPLEX_TEMPLATE("me_io_stream_status",
211 me_io_stream_status_t,
212 me_io_stream_status,
213 me_device_io_stream_status,
214 (device,
215 filep,
216 karg.subdevice,
217 karg.wait, &karg.status, &karg.count, karg.flags))
219 ME_IO_MULTIPLEX_TEMPLATE("me_io_stream_write",
220 me_io_stream_write_t,
221 me_io_stream_write,
222 me_device_io_stream_write,
223 (device,
224 filep,
225 karg.subdevice,
226 karg.write_mode, karg.values, &karg.count, karg.flags))
227 #else
228 #error macro ME_IO_MULTIPLEX_TEMPLATE not defined
229 #endif
231 #ifdef ME_QUERY_MULTIPLEX_STR_TEMPLATE
232 ME_QUERY_MULTIPLEX_STR_TEMPLATE("me_query_name_device",
233 me_query_name_device_t,
234 me_query_name_device,
235 me_device_query_name_device, (device, &msg))
237 ME_QUERY_MULTIPLEX_STR_TEMPLATE("me_query_name_device_driver",
238 me_query_name_device_driver_t,
239 me_query_name_device_driver,
240 me_device_query_name_device_driver,
241 (device, &msg))
243 ME_QUERY_MULTIPLEX_STR_TEMPLATE("me_query_description_device",
244 me_query_description_device_t,
245 me_query_description_device,
246 me_device_query_description_device,
247 (device, &msg))
248 #else
249 #error macro ME_QUERY_MULTIPLEX_STR_TEMPLATE not defined
250 #endif
252 #ifdef ME_QUERY_MULTIPLEX_TEMPLATE
253 ME_QUERY_MULTIPLEX_TEMPLATE("me_query_info_device",
254 me_query_info_device_t,
255 me_query_info_device,
256 me_device_query_info_device,
257 (device,
258 &karg.vendor_id,
259 &karg.device_id,
260 &karg.serial_no,
261 &karg.bus_type,
262 &karg.bus_no,
263 &karg.dev_no, &karg.func_no, &karg.plugged))
265 ME_QUERY_MULTIPLEX_TEMPLATE("me_query_number_subdevices",
266 me_query_number_subdevices_t,
267 me_query_number_subdevices,
268 me_device_query_number_subdevices,
269 (device, &karg.number))
271 ME_QUERY_MULTIPLEX_TEMPLATE("me_query_number_channels",
272 me_query_number_channels_t,
273 me_query_number_channels,
274 me_device_query_number_channels,
275 (device, karg.subdevice, &karg.number))
277 ME_QUERY_MULTIPLEX_TEMPLATE("me_query_subdevice_by_type",
278 me_query_subdevice_by_type_t,
279 me_query_subdevice_by_type,
280 me_device_query_subdevice_by_type,
281 (device,
282 karg.start_subdevice,
283 karg.type, karg.subtype, &karg.subdevice))
285 ME_QUERY_MULTIPLEX_TEMPLATE("me_query_subdevice_type",
286 me_query_subdevice_type_t,
287 me_query_subdevice_type,
288 me_device_query_subdevice_type,
289 (device, karg.subdevice, &karg.type, &karg.subtype))
291 ME_QUERY_MULTIPLEX_TEMPLATE("me_query_subdevice_caps",
292 me_query_subdevice_caps_t,
293 me_query_subdevice_caps,
294 me_device_query_subdevice_caps,
295 (device, karg.subdevice, &karg.caps))
297 ME_QUERY_MULTIPLEX_TEMPLATE("me_query_subdevice_caps_args",
298 me_query_subdevice_caps_args_t,
299 me_query_subdevice_caps_args,
300 me_device_query_subdevice_caps_args,
301 (device, karg.subdevice, karg.cap, karg.args,
302 karg.count))
304 ME_QUERY_MULTIPLEX_TEMPLATE("me_query_number_ranges",
305 me_query_number_ranges_t,
306 me_query_number_ranges,
307 me_device_query_number_ranges,
308 (device, karg.subdevice, karg.unit, &karg.number))
310 ME_QUERY_MULTIPLEX_TEMPLATE("me_query_range_by_min_max",
311 me_query_range_by_min_max_t,
312 me_query_range_by_min_max,
313 me_device_query_range_by_min_max,
314 (device,
315 karg.subdevice,
316 karg.unit,
317 &karg.min, &karg.max, &karg.max_data, &karg.range))
319 ME_QUERY_MULTIPLEX_TEMPLATE("me_query_range_info",
320 me_query_range_info_t,
321 me_query_range_info,
322 me_device_query_range_info,
323 (device,
324 karg.subdevice,
325 karg.range,
326 &karg.unit, &karg.min, &karg.max, &karg.max_data))
328 ME_QUERY_MULTIPLEX_TEMPLATE("me_query_timer",
329 me_query_timer_t,
330 me_query_timer,
331 me_device_query_timer,
332 (device,
333 karg.subdevice,
334 karg.timer,
335 &karg.base_frequency,
336 &karg.min_ticks, &karg.max_ticks))
338 ME_QUERY_MULTIPLEX_TEMPLATE("me_query_version_device_driver",
339 me_query_version_device_driver_t,
340 me_query_version_device_driver,
341 me_device_query_version_device_driver,
342 (device, &karg.version))
343 #else
344 #error macro ME_QUERY_MULTIPLEX_TEMPLATE not defined
345 #endif
347 /** ******************************************************************************** **/
349 static me_device_t *get_dummy_instance(unsigned short vendor_id,
350 unsigned short device_id,
351 unsigned int serial_no,
352 int bus_type,
353 int bus_no, int dev_no, int func_no)
355 int err;
356 me_dummy_constructor_t constructor = NULL;
357 me_device_t *instance;
359 PDEBUG("executed.\n");
361 if ((constructor = symbol_get(medummy_constructor)) == NULL) {
362 err = request_module(MEDUMMY_NAME);
364 if (err) {
365 PERROR("Error while request for module %s.\n",
366 MEDUMMY_NAME);
367 return NULL;
370 if ((constructor = symbol_get(medummy_constructor)) == NULL) {
371 PERROR("Can't get %s driver module constructor.\n",
372 MEDUMMY_NAME);
373 return NULL;
377 if ((instance = (*constructor) (vendor_id,
378 device_id,
379 serial_no,
380 bus_type,
381 bus_no, dev_no, func_no)) == NULL)
382 symbol_put(medummy_constructor);
384 return instance;
387 static int __devinit me_probe_pci(struct pci_dev *dev,
388 const struct pci_device_id *id)
390 int err;
391 me_pci_constructor_t constructor = NULL;
392 #ifdef BOSCH
393 me_bosch_constructor_t constructor_bosch = NULL;
394 #endif
395 me_device_t *n_device = NULL;
396 uint32_t device;
398 char constructor_name[24] = "me0000_pci_constructor";
399 char module_name[7] = "me0000";
401 PDEBUG("executed.\n");
402 device = dev->device;
403 if ((device & 0xF000) == 0x6000) { // Exceptions: me61xx, me62xx, me63xx are handled by one driver.
404 device &= 0xF0FF;
407 constructor_name[2] += (char)((device >> 12) & 0x000F);
408 constructor_name[3] += (char)((device >> 8) & 0x000F);
409 PDEBUG("constructor_name: %s\n", constructor_name);
410 module_name[2] += (char)((device >> 12) & 0x000F);
411 module_name[3] += (char)((device >> 8) & 0x000F);
412 PDEBUG("module_name: %s\n", module_name);
414 if ((constructor =
415 (me_pci_constructor_t) symbol_get(constructor_name)) == NULL) {
416 if (request_module(module_name)) {
417 PERROR("Error while request for module %s.\n",
418 module_name);
419 return -ENODEV;
422 if ((constructor =
423 (me_pci_constructor_t) symbol_get(constructor_name)) ==
424 NULL) {
425 PERROR("Can't get %s driver module constructor.\n",
426 module_name);
427 return -ENODEV;
430 #ifdef BOSCH
431 if ((device & 0xF000) == 0x4000) { // Bosch build has differnt constructor for me4600.
432 if ((n_device =
433 (*constructor_bosch) (dev, me_bosch_fw)) == NULL) {
434 symbol_put(constructor_name);
435 PERROR
436 ("Can't get device instance of %s driver module.\n",
437 module_name);
438 return -ENODEV;
440 } else {
441 #endif
442 if ((n_device = (*constructor) (dev)) == NULL) {
443 symbol_put(constructor_name);
444 PERROR
445 ("Can't get device instance of %s driver module.\n",
446 module_name);
447 return -ENODEV;
449 #ifdef BOSCH
451 #endif
453 insert_to_device_list(n_device);
454 err =
455 n_device->me_device_io_reset_device(n_device, NULL,
456 ME_IO_RESET_DEVICE_NO_FLAGS);
457 if (err) {
458 PERROR("Error while reseting device.\n");
459 } else {
460 PDEBUG("Reseting device was sucessful.\n");
462 return ME_ERRNO_SUCCESS;
465 static void release_instance(me_device_t *device)
467 int vendor_id;
468 int device_id;
469 int serial_no;
470 int bus_type;
471 int bus_no;
472 int dev_no;
473 int func_no;
474 int plugged;
476 uint32_t dev_id;
478 char constructor_name[24] = "me0000_pci_constructor";
480 PDEBUG("executed.\n");
482 device->me_device_query_info_device(device,
483 &vendor_id,
484 &device_id,
485 &serial_no,
486 &bus_type,
487 &bus_no,
488 &dev_no, &func_no, &plugged);
490 dev_id = device_id;
491 device->me_device_destructor(device);
493 if (plugged != ME_PLUGGED_IN) {
494 PDEBUG("release: medummy_constructor\n");
496 symbol_put("medummy_constructor");
497 } else {
498 if ((dev_id & 0xF000) == 0x6000) { // Exceptions: me61xx, me62xx, me63xx are handled by one driver.
499 dev_id &= 0xF0FF;
502 constructor_name[2] += (char)((dev_id >> 12) & 0x000F);
503 constructor_name[3] += (char)((dev_id >> 8) & 0x000F);
504 PDEBUG("release: %s\n", constructor_name);
506 symbol_put(constructor_name);
510 static int insert_to_device_list(me_device_t *n_device)
512 me_device_t *o_device = NULL;
514 struct list_head *pos;
515 int n_vendor_id;
516 int n_device_id;
517 int n_serial_no;
518 int n_bus_type;
519 int n_bus_no;
520 int n_dev_no;
521 int n_func_no;
522 int n_plugged;
523 int o_vendor_id;
524 int o_device_id;
525 int o_serial_no;
526 int o_bus_type;
527 int o_bus_no;
528 int o_dev_no;
529 int o_func_no;
530 int o_plugged;
532 PDEBUG("executed.\n");
534 n_device->me_device_query_info_device(n_device,
535 &n_vendor_id,
536 &n_device_id,
537 &n_serial_no,
538 &n_bus_type,
539 &n_bus_no,
540 &n_dev_no,
541 &n_func_no, &n_plugged);
543 down_write(&me_rwsem);
545 list_for_each(pos, &me_device_list) {
546 o_device = list_entry(pos, me_device_t, list);
547 o_device->me_device_query_info_device(o_device,
548 &o_vendor_id,
549 &o_device_id,
550 &o_serial_no,
551 &o_bus_type,
552 &o_bus_no,
553 &o_dev_no,
554 &o_func_no, &o_plugged);
556 if (o_plugged == ME_PLUGGED_OUT) {
557 if (((o_vendor_id == n_vendor_id) &&
558 (o_device_id == n_device_id) &&
559 (o_serial_no == n_serial_no) &&
560 (o_bus_type == n_bus_type)) ||
561 ((o_vendor_id == n_vendor_id) &&
562 (o_device_id == n_device_id) &&
563 (o_bus_type == n_bus_type) &&
564 (o_bus_no == n_bus_no) &&
565 (o_dev_no == n_dev_no) &&
566 (o_func_no == n_func_no))) {
567 n_device->list.prev = pos->prev;
568 n_device->list.next = pos->next;
569 pos->prev->next = &n_device->list;
570 pos->next->prev = &n_device->list;
571 release_instance(o_device);
572 break;
577 if (pos == &me_device_list) {
578 list_add_tail(&n_device->list, &me_device_list);
581 up_write(&me_rwsem);
583 return 0;
586 static void __devexit me_remove_pci(struct pci_dev *dev)
588 int vendor_id = dev->vendor;
589 int device_id = dev->device;
590 int subsystem_vendor = dev->subsystem_vendor;
591 int subsystem_device = dev->subsystem_device;
592 int serial_no = (subsystem_device << 16) | subsystem_vendor;
594 PDEBUG("executed.\n");
596 PINFO("Vendor id = 0x%08X\n", vendor_id);
597 PINFO("Device id = 0x%08X\n", device_id);
598 PINFO("Serial Number = 0x%08X\n", serial_no);
600 replace_with_dummy(vendor_id, device_id, serial_no);
603 static int replace_with_dummy(int vendor_id, int device_id, int serial_no)
606 struct list_head *pos;
607 me_device_t *n_device = NULL;
608 me_device_t *o_device = NULL;
609 int o_vendor_id;
610 int o_device_id;
611 int o_serial_no;
612 int o_bus_type;
613 int o_bus_no;
614 int o_dev_no;
615 int o_func_no;
616 int o_plugged;
618 PDEBUG("executed.\n");
620 down_write(&me_rwsem);
622 list_for_each(pos, &me_device_list) {
623 o_device = list_entry(pos, me_device_t, list);
624 o_device->me_device_query_info_device(o_device,
625 &o_vendor_id,
626 &o_device_id,
627 &o_serial_no,
628 &o_bus_type,
629 &o_bus_no,
630 &o_dev_no,
631 &o_func_no, &o_plugged);
633 if (o_plugged == ME_PLUGGED_IN) {
634 if (((o_vendor_id == vendor_id) &&
635 (o_device_id == device_id) &&
636 (o_serial_no == serial_no))) {
637 n_device = get_dummy_instance(o_vendor_id,
638 o_device_id,
639 o_serial_no,
640 o_bus_type,
641 o_bus_no,
642 o_dev_no,
643 o_func_no);
645 if (!n_device) {
646 up_write(&me_rwsem);
647 PERROR("Cannot get dummy instance.\n");
648 return 1;
651 n_device->list.prev = pos->prev;
653 n_device->list.next = pos->next;
654 pos->prev->next = &n_device->list;
655 pos->next->prev = &n_device->list;
656 release_instance(o_device);
657 break;
662 up_write(&me_rwsem);
664 return 0;
667 static void clear_device_list(void)
670 struct list_head *entry;
671 me_device_t *device;
673 // Clear the device info list .
674 down_write(&me_rwsem);
676 while (!list_empty(&me_device_list)) {
677 entry = me_device_list.next;
678 device = list_entry(entry, me_device_t, list);
679 list_del(entry);
680 release_instance(device);
683 up_write(&me_rwsem);
686 static int lock_driver(struct file *filep, int lock, int flags)
688 int err = ME_ERRNO_SUCCESS;
689 me_device_t *device;
691 PDEBUG("executed.\n");
693 down_read(&me_rwsem);
695 spin_lock(&me_lock);
697 switch (lock) {
699 case ME_LOCK_SET:
700 if (me_count) {
701 PERROR
702 ("Driver System is currently used by another process.\n");
703 err = ME_ERRNO_USED;
704 } else if ((me_filep != NULL) && (me_filep != filep)) {
705 PERROR
706 ("Driver System is already logged by another process.\n");
707 err = ME_ERRNO_LOCKED;
708 } else {
709 list_for_each_entry(device, &me_device_list, list) {
710 err =
711 device->me_device_lock_device(device, filep,
712 ME_LOCK_CHECK,
713 flags);
715 if (err)
716 break;
719 if (!err)
720 me_filep = filep;
723 break;
725 case ME_LOCK_RELEASE:
726 if ((me_filep != NULL) && (me_filep != filep)) {
727 err = ME_ERRNO_SUCCESS;
728 } else {
729 list_for_each_entry(device, &me_device_list, list) {
730 device->me_device_lock_device(device, filep,
731 ME_LOCK_RELEASE,
732 flags);
735 me_filep = NULL;
738 break;
740 default:
741 PERROR("Invalid lock specified.\n");
743 err = ME_ERRNO_INVALID_LOCK;
745 break;
748 spin_unlock(&me_lock);
750 up_read(&me_rwsem);
752 return err;
755 static int me_lock_driver(struct file *filep, me_lock_driver_t *arg)
757 int err = 0;
759 me_lock_driver_t lock;
761 PDEBUG("executed.\n");
763 err = copy_from_user(&lock, arg, sizeof(me_lock_driver_t));
765 if (err) {
766 PERROR("Can't copy arguments to kernel space.\n");
767 return -EFAULT;
770 lock.errno = lock_driver(filep, lock.lock, lock.flags);
772 err = copy_to_user(arg, &lock, sizeof(me_lock_driver_t));
774 if (err) {
775 PERROR("Can't copy query back to user space.\n");
776 return -EFAULT;
779 return ME_ERRNO_SUCCESS;
782 static int me_open(struct inode *inode_ptr, struct file *filep)
785 PDEBUG("executed.\n");
786 // Nothing to do here.
787 return 0;
790 static int me_release(struct inode *inode_ptr, struct file *filep)
793 PDEBUG("executed.\n");
794 lock_driver(filep, ME_LOCK_RELEASE, ME_LOCK_DRIVER_NO_FLAGS);
796 return 0;
799 static int me_query_version_main_driver(struct file *filep,
800 me_query_version_main_driver_t *arg)
802 int err;
803 me_query_version_main_driver_t karg;
805 PDEBUG("executed.\n");
807 karg.version = ME_VERSION_DRIVER;
808 karg.errno = ME_ERRNO_SUCCESS;
810 err = copy_to_user(arg, &karg, sizeof(me_query_version_main_driver_t));
812 if (err) {
813 PERROR("Can't copy query back to user space.\n");
814 return -EFAULT;
817 return 0;
820 static int me_config_load_device(struct file *filep,
821 me_cfg_device_entry_t *karg, int device_no)
824 int err = ME_ERRNO_SUCCESS;
825 int k = 0;
827 struct list_head *pos = NULL;
828 me_device_t *device = NULL;
830 PDEBUG("executed.\n");
832 list_for_each(pos, &me_device_list) {
833 if (k == device_no) {
834 device = list_entry(pos, me_device_t, list);
835 break;
838 k++;
841 if (pos == &me_device_list) {
842 PERROR("Invalid device number specified.\n");
843 return ME_ERRNO_INVALID_DEVICE;
844 } else {
845 spin_lock(&me_lock);
847 if ((me_filep != NULL) && (me_filep != filep)) {
848 spin_unlock(&me_lock);
849 PERROR("Resource is locked by another process.\n");
850 return ME_ERRNO_LOCKED;
851 } else {
852 me_count++;
853 spin_unlock(&me_lock);
855 err =
856 device->me_device_config_load(device, filep, karg);
858 spin_lock(&me_lock);
859 me_count--;
860 spin_unlock(&me_lock);
864 return err;
867 static int me_config_load(struct file *filep, me_config_load_t *arg)
869 int err;
870 int i;
871 me_config_load_t cfg_setup;
872 me_config_load_t karg_cfg_setup;
874 struct list_head *pos = NULL;
876 struct list_head new_list;
877 me_device_t *o_device;
878 me_device_t *n_device;
879 int o_vendor_id;
880 int o_device_id;
881 int o_serial_no;
882 int o_bus_type;
883 int o_bus_no;
884 int o_dev_no;
885 int o_func_no;
886 int o_plugged;
888 PDEBUG("executed.\n");
890 // Copy argument to kernel space.
891 err = copy_from_user(&karg_cfg_setup, arg, sizeof(me_config_load_t));
893 if (err) {
894 PERROR("Can't copy arguments to kernel space.\n");
895 return -EFAULT;
897 // Allocate kernel buffer for device list.
898 cfg_setup.device_list =
899 kmalloc(sizeof(me_cfg_device_entry_t) * karg_cfg_setup.count,
900 GFP_KERNEL);
902 if (!cfg_setup.device_list) {
903 PERROR("Can't get buffer %li for device list.\n",
904 sizeof(me_cfg_device_entry_t) * karg_cfg_setup.count);
905 return -ENOMEM;
907 // Copy device list to kernel space.
908 err =
909 copy_from_user(cfg_setup.device_list, karg_cfg_setup.device_list,
910 sizeof(me_cfg_device_entry_t) *
911 karg_cfg_setup.count);
913 if (err) {
914 PERROR("Can't copy device list to kernel space.\n");
915 kfree(cfg_setup.device_list);
916 return -EFAULT;
919 cfg_setup.count = karg_cfg_setup.count;
921 INIT_LIST_HEAD(&new_list);
923 down_write(&me_rwsem);
925 spin_lock(&me_lock);
927 if ((me_filep != NULL) && (me_filep != filep)) {
928 spin_unlock(&me_lock);
929 PERROR("Driver System is logged by another process.\n");
930 karg_cfg_setup.errno = ME_ERRNO_LOCKED;
931 } else {
932 me_count++;
933 spin_unlock(&me_lock);
935 for (i = 0; i < karg_cfg_setup.count; i++) {
936 PDEBUG("me_config_load() device=%d.\n", i);
937 if (cfg_setup.device_list[i].tcpip.access_type ==
938 ME_ACCESS_TYPE_LOCAL) {
939 list_for_each(pos, &me_device_list) {
940 o_device =
941 list_entry(pos, me_device_t, list);
942 o_device->
943 me_device_query_info_device
944 (o_device, &o_vendor_id,
945 &o_device_id, &o_serial_no,
946 &o_bus_type, &o_bus_no, &o_dev_no,
947 &o_func_no, &o_plugged);
949 if (cfg_setup.device_list[i].info.
950 hw_location.bus_type ==
951 ME_BUS_TYPE_PCI) {
952 if (((o_vendor_id ==
953 cfg_setup.device_list[i].
954 info.vendor_id)
955 && (o_device_id ==
956 cfg_setup.
957 device_list[i].info.
958 device_id)
959 && (o_serial_no ==
960 cfg_setup.
961 device_list[i].info.
962 serial_no)
963 && (o_bus_type ==
964 cfg_setup.
965 device_list[i].info.
966 hw_location.bus_type))
968 ((o_vendor_id ==
969 cfg_setup.device_list[i].
970 info.vendor_id)
971 && (o_device_id ==
972 cfg_setup.
973 device_list[i].info.
974 device_id)
975 && (o_bus_type ==
976 cfg_setup.
977 device_list[i].info.
978 hw_location.bus_type)
979 && (o_bus_no ==
980 cfg_setup.
981 device_list[i].info.
982 hw_location.pci.bus_no)
983 && (o_dev_no ==
984 cfg_setup.
985 device_list[i].info.
986 hw_location.pci.
987 device_no)
988 && (o_func_no ==
989 cfg_setup.
990 device_list[i].info.
991 hw_location.pci.
992 function_no))) {
993 list_move_tail(pos,
994 &new_list);
995 break;
999 else if (cfg_setup.device_list[i].info.hw_location.bus_type == ME_BUS_TYPE_USB)
1001 if (((o_vendor_id == cfg_setup.device_list[i].info.vendor_id) &&
1002 (o_device_id == cfg_setup.device_list[i].info.device_id) &&
1003 (o_serial_no == cfg_setup.device_list[i].info.serial_no) &&
1004 (o_bus_type == cfg_setup.device_list[i].info.hw_location.bus_type)) ||
1005 ((o_vendor_id == cfg_setup.device_list[i].info.vendor_id) &&
1006 (o_device_id == cfg_setup.device_list[i].info.device_id) &&
1007 (o_bus_type == cfg_setup.device_list[i].info.hw_location.bus_type) &&
1008 (o_bus_no == cfg_setup.device_list[i].info.hw_location.usb.root_hub_no)))
1010 list_move_tail(pos, &new_list);
1011 break;
1015 else {
1016 PERROR("Wrong bus type: %d.\n",
1017 cfg_setup.device_list[i].
1018 info.hw_location.
1019 bus_type);
1023 if (pos == &me_device_list) { // Device is not already in the list
1024 if (cfg_setup.device_list[i].info.
1025 hw_location.bus_type ==
1026 ME_BUS_TYPE_PCI) {
1027 n_device =
1028 get_dummy_instance
1029 (cfg_setup.device_list[i].
1030 info.vendor_id,
1031 cfg_setup.device_list[i].
1032 info.device_id,
1033 cfg_setup.device_list[i].
1034 info.serial_no,
1035 cfg_setup.device_list[i].
1036 info.hw_location.bus_type,
1037 cfg_setup.device_list[i].
1038 info.hw_location.pci.
1039 bus_no,
1040 cfg_setup.device_list[i].
1041 info.hw_location.pci.
1042 device_no,
1043 cfg_setup.device_list[i].
1044 info.hw_location.pci.
1045 function_no);
1047 if (!n_device) {
1048 PERROR
1049 ("Can't get dummy instance.\n");
1050 kfree(cfg_setup.
1051 device_list);
1052 spin_lock(&me_lock);
1053 me_count--;
1054 spin_unlock(&me_lock);
1055 up_write(&me_rwsem);
1056 return -EFAULT;
1059 list_add_tail(&n_device->list,
1060 &new_list);
1063 else if (cfg_setup.device_list[i].info.hw_location.bus_type == ME_BUS_TYPE_USB)
1065 n_device = get_dummy_instance(
1066 cfg_setup.device_list[i].info.vendor_id,
1067 cfg_setup.device_list[i].info.device_id,
1068 cfg_setup.device_list[i].info.serial_no,
1069 cfg_setup.device_list[i].info.hw_location.bus_type,
1070 cfg_setup.device_list[i].info.hw_location.usb.root_hub_no,
1074 if (!n_device)
1076 PERROR("Can't get dummy instance.\n");
1077 kfree(cfg_setup.device_list);
1078 spin_lock(&me_lock);
1079 me_count--;
1080 spin_unlock(&me_lock);
1081 up_write(&me_rwsem);
1082 return -EFAULT;
1085 list_add_tail(&n_device->list, &new_list);
1089 } else {
1090 n_device = get_dummy_instance(0,
1091 0, 0, 0, 0, 0, 0);
1093 if (!n_device) {
1094 PERROR("Can't get dummy instance.\n");
1095 kfree(cfg_setup.device_list);
1096 spin_lock(&me_lock);
1097 me_count--;
1098 spin_unlock(&me_lock);
1099 up_write(&me_rwsem);
1100 return -EFAULT;
1103 list_add_tail(&n_device->list, &new_list);
1107 while (!list_empty(&me_device_list)) {
1108 o_device =
1109 list_entry(me_device_list.next, me_device_t, list);
1110 o_device->me_device_query_info_device(o_device,
1111 &o_vendor_id,
1112 &o_device_id,
1113 &o_serial_no,
1114 &o_bus_type,
1115 &o_bus_no,
1116 &o_dev_no,
1117 &o_func_no,
1118 &o_plugged);
1120 if (o_plugged == ME_PLUGGED_IN) {
1121 list_move_tail(me_device_list.next, &new_list);
1122 } else {
1123 list_del(me_device_list.next);
1124 release_instance(o_device);
1128 // Move temporary new list to global driver list.
1129 list_splice(&new_list, &me_device_list);
1131 karg_cfg_setup.errno = ME_ERRNO_SUCCESS;
1134 for (i = 0; i < cfg_setup.count; i++) {
1136 karg_cfg_setup.errno =
1137 me_config_load_device(filep, &cfg_setup.device_list[i], i);
1138 if (karg_cfg_setup.errno) {
1139 PERROR("me_config_load_device(%d)=%d\n", i,
1140 karg_cfg_setup.errno);
1141 break;
1145 spin_lock(&me_lock);
1147 me_count--;
1148 spin_unlock(&me_lock);
1149 up_write(&me_rwsem);
1151 err = copy_to_user(arg, &karg_cfg_setup, sizeof(me_config_load_t));
1153 if (err) {
1154 PERROR("Can't copy config list to user space.\n");
1155 kfree(cfg_setup.device_list);
1156 return -EFAULT;
1159 kfree(cfg_setup.device_list);
1160 return 0;
1163 static int me_io_stream_start(struct file *filep, me_io_stream_start_t *arg)
1165 int err;
1166 int i, k;
1168 struct list_head *pos;
1169 me_device_t *device;
1170 me_io_stream_start_t karg;
1171 meIOStreamStart_t *list;
1173 PDEBUG("executed.\n");
1175 err = copy_from_user(&karg, arg, sizeof(me_io_stream_start_t));
1177 if (err) {
1178 PERROR("Can't copy arguments to kernel space.\n");
1179 return -EFAULT;
1182 karg.errno = ME_ERRNO_SUCCESS;
1184 list = kmalloc(sizeof(meIOStreamStart_t) * karg.count, GFP_KERNEL);
1186 if (!list) {
1187 PERROR("Can't get buffer for start list.\n");
1188 return -ENOMEM;
1191 err =
1192 copy_from_user(list, karg.start_list,
1193 sizeof(meIOStreamStart_t) * karg.count);
1195 if (err) {
1196 PERROR("Can't copy start list to kernel space.\n");
1197 kfree(list);
1198 return -EFAULT;
1201 spin_lock(&me_lock);
1203 if ((me_filep != NULL) && (me_filep != filep)) {
1204 spin_unlock(&me_lock);
1205 PERROR("Driver System is logged by another process.\n");
1207 for (i = 0; i < karg.count; i++) {
1208 list[i].iErrno = ME_ERRNO_LOCKED;
1210 } else {
1211 me_count++;
1212 spin_unlock(&me_lock);
1214 for (i = 0; i < karg.count; i++) {
1215 down_read(&me_rwsem);
1216 k = 0;
1217 list_for_each(pos, &me_device_list) {
1218 if (k == list[i].iDevice) {
1219 device =
1220 list_entry(pos, me_device_t, list);
1221 break;
1224 k++;
1227 if (pos == &me_device_list) {
1228 up_read(&me_rwsem);
1229 PERROR("Invalid device number specified.\n");
1230 list[i].iErrno = ME_ERRNO_INVALID_DEVICE;
1231 karg.errno = ME_ERRNO_INVALID_DEVICE;
1232 break;
1233 } else {
1234 list[i].iErrno =
1235 device->me_device_io_stream_start(device,
1236 filep,
1237 list[i].
1238 iSubdevice,
1239 list[i].
1240 iStartMode,
1241 list[i].
1242 iTimeOut,
1243 list[i].
1244 iFlags);
1246 if (list[i].iErrno) {
1247 up_read(&me_rwsem);
1248 karg.errno = list[i].iErrno;
1249 break;
1253 up_read(&me_rwsem);
1256 spin_lock(&me_lock);
1258 me_count--;
1259 spin_unlock(&me_lock);
1262 err = copy_to_user(arg, &karg, sizeof(me_io_stream_start_t));
1264 if (err) {
1265 PERROR("Can't copy arguments to user space.\n");
1266 kfree(list);
1267 return -EFAULT;
1270 err =
1271 copy_to_user(karg.start_list, list,
1272 sizeof(meIOStreamStart_t) * karg.count);
1274 if (err) {
1275 PERROR("Can't copy start list to user space.\n");
1276 kfree(list);
1277 return -EFAULT;
1280 kfree(list);
1282 return err;
1285 static int me_io_single(struct file *filep, me_io_single_t *arg)
1287 int err;
1288 int i, k;
1290 struct list_head *pos;
1291 me_device_t *device;
1292 me_io_single_t karg;
1293 meIOSingle_t *list;
1295 PDEBUG("executed.\n");
1297 err = copy_from_user(&karg, arg, sizeof(me_io_single_t));
1299 if (err) {
1300 PERROR("Can't copy arguments to kernel space.\n");
1301 return -EFAULT;
1304 karg.errno = ME_ERRNO_SUCCESS;
1306 list = kmalloc(sizeof(meIOSingle_t) * karg.count, GFP_KERNEL);
1308 if (!list) {
1309 PERROR("Can't get buffer for single list.\n");
1310 return -ENOMEM;
1313 err =
1314 copy_from_user(list, karg.single_list,
1315 sizeof(meIOSingle_t) * karg.count);
1317 if (err) {
1318 PERROR("Can't copy single list to kernel space.\n");
1319 kfree(list);
1320 return -EFAULT;
1323 spin_lock(&me_lock);
1325 if ((me_filep != NULL) && (me_filep != filep)) {
1326 spin_unlock(&me_lock);
1327 PERROR("Driver System is logged by another process.\n");
1329 for (i = 0; i < karg.count; i++) {
1330 list[i].iErrno = ME_ERRNO_LOCKED;
1332 } else {
1333 me_count++;
1334 spin_unlock(&me_lock);
1336 for (i = 0; i < karg.count; i++) {
1337 k = 0;
1339 down_read(&me_rwsem);
1341 list_for_each(pos, &me_device_list) {
1342 if (k == list[i].iDevice) {
1343 device =
1344 list_entry(pos, me_device_t, list);
1345 break;
1348 k++;
1351 if (pos == &me_device_list) {
1352 up_read(&me_rwsem);
1353 PERROR("Invalid device number specified.\n");
1354 list[i].iErrno = ME_ERRNO_INVALID_DEVICE;
1355 karg.errno = ME_ERRNO_INVALID_DEVICE;
1356 break;
1357 } else {
1358 if (list[i].iDir == ME_DIR_OUTPUT) {
1359 list[i].iErrno =
1360 device->
1361 me_device_io_single_write(device,
1362 filep,
1363 list[i].
1364 iSubdevice,
1365 list[i].
1366 iChannel,
1367 list[i].
1368 iValue,
1369 list[i].
1370 iTimeOut,
1371 list[i].
1372 iFlags);
1374 if (list[i].iErrno) {
1375 up_read(&me_rwsem);
1376 karg.errno = list[i].iErrno;
1377 break;
1379 } else if (list[i].iDir == ME_DIR_INPUT) {
1380 list[i].iErrno =
1381 device->
1382 me_device_io_single_read(device,
1383 filep,
1384 list[i].
1385 iSubdevice,
1386 list[i].
1387 iChannel,
1388 &list[i].
1389 iValue,
1390 list[i].
1391 iTimeOut,
1392 list[i].
1393 iFlags);
1395 if (list[i].iErrno) {
1396 up_read(&me_rwsem);
1397 karg.errno = list[i].iErrno;
1398 break;
1400 } else {
1401 up_read(&me_rwsem);
1402 PERROR
1403 ("Invalid single direction specified.\n");
1404 list[i].iErrno = ME_ERRNO_INVALID_DIR;
1405 karg.errno = ME_ERRNO_INVALID_DIR;
1406 break;
1410 up_read(&me_rwsem);
1413 spin_lock(&me_lock);
1415 me_count--;
1416 spin_unlock(&me_lock);
1419 err = copy_to_user(arg, &karg, sizeof(me_io_single_t));
1421 if (err) {
1422 PERROR("Can't copy arguments to user space.\n");
1423 return -EFAULT;
1426 err =
1427 copy_to_user(karg.single_list, list,
1428 sizeof(meIOSingle_t) * karg.count);
1430 if (err) {
1431 PERROR("Can't copy single list to user space.\n");
1432 kfree(list);
1433 return -EFAULT;
1436 kfree(list);
1438 return err;
1441 static int me_io_stream_config(struct file *filep, me_io_stream_config_t *arg)
1443 int err;
1444 int k = 0;
1446 struct list_head *pos;
1447 me_device_t *device;
1448 me_io_stream_config_t karg;
1449 meIOStreamConfig_t *list;
1451 PDEBUG("executed.\n");
1453 err = copy_from_user(&karg, arg, sizeof(me_io_stream_config_t));
1455 if (err) {
1456 PERROR("Can't copy arguments to kernel space.\n");
1457 return -EFAULT;
1460 list = kmalloc(sizeof(meIOStreamConfig_t) * karg.count, GFP_KERNEL);
1462 if (!list) {
1463 PERROR("Can't get buffer for config list.\n");
1464 return -ENOMEM;
1467 err =
1468 copy_from_user(list, karg.config_list,
1469 sizeof(meIOStreamConfig_t) * karg.count);
1471 if (err) {
1472 PERROR("Can't copy config list to kernel space.\n");
1473 kfree(list);
1474 return -EFAULT;
1477 spin_lock(&me_lock);
1479 if ((me_filep != NULL) && (me_filep != filep)) {
1480 spin_unlock(&me_lock);
1481 PERROR("Driver System is logged by another process.\n");
1482 karg.errno = ME_ERRNO_LOCKED;
1483 } else {
1484 me_count++;
1485 spin_unlock(&me_lock);
1487 down_read(&me_rwsem);
1489 list_for_each(pos, &me_device_list) {
1490 if (k == karg.device) {
1491 device = list_entry(pos, me_device_t, list);
1492 break;
1495 k++;
1498 if (pos == &me_device_list) {
1499 PERROR("Invalid device number specified.\n");
1500 karg.errno = ME_ERRNO_INVALID_DEVICE;
1501 } else {
1502 karg.errno =
1503 device->me_device_io_stream_config(device, filep,
1504 karg.subdevice,
1505 list, karg.count,
1506 &karg.trigger,
1507 karg.
1508 fifo_irq_threshold,
1509 karg.flags);
1512 up_read(&me_rwsem);
1514 spin_lock(&me_lock);
1515 me_count--;
1516 spin_unlock(&me_lock);
1519 err = copy_to_user(arg, &karg, sizeof(me_io_stream_config_t));
1521 if (err) {
1522 PERROR("Can't copy back to user space.\n");
1523 kfree(list);
1524 return -EFAULT;
1527 kfree(list);
1529 return err;
1532 static int me_query_number_devices(struct file *filep,
1533 me_query_number_devices_t *arg)
1535 int err;
1536 me_query_number_devices_t karg;
1538 struct list_head *pos;
1540 PDEBUG("executed.\n");
1542 karg.number = 0;
1543 down_read(&me_rwsem);
1544 list_for_each(pos, &me_device_list) {
1545 karg.number++;
1548 up_read(&me_rwsem);
1550 karg.errno = ME_ERRNO_SUCCESS;
1552 err = copy_to_user(arg, &karg, sizeof(me_query_number_devices_t));
1554 if (err) {
1555 PERROR("Can't copy query back to user space.\n");
1556 return -EFAULT;
1559 return 0;
1562 static int me_io_stream_stop(struct file *filep, me_io_stream_stop_t *arg)
1564 int err;
1565 int i, k;
1567 struct list_head *pos;
1568 me_device_t *device;
1569 me_io_stream_stop_t karg;
1570 meIOStreamStop_t *list;
1572 PDEBUG("executed.\n");
1574 err = copy_from_user(&karg, arg, sizeof(me_io_stream_stop_t));
1576 if (err) {
1577 PERROR("Can't copy arguments to kernel space.\n");
1578 return -EFAULT;
1581 karg.errno = ME_ERRNO_SUCCESS;
1583 list = kmalloc(sizeof(meIOStreamStop_t) * karg.count, GFP_KERNEL);
1585 if (!list) {
1586 PERROR("Can't get buffer for stop list.\n");
1587 return -ENOMEM;
1590 err =
1591 copy_from_user(list, karg.stop_list,
1592 sizeof(meIOStreamStop_t) * karg.count);
1594 if (err) {
1595 PERROR("Can't copy stop list to kernel space.\n");
1596 kfree(list);
1597 return -EFAULT;
1600 spin_lock(&me_lock);
1602 if ((me_filep != NULL) && (me_filep != filep)) {
1603 spin_unlock(&me_lock);
1604 PERROR("Driver System is logged by another process.\n");
1606 for (i = 0; i < karg.count; i++) {
1607 list[i].iErrno = ME_ERRNO_LOCKED;
1609 } else {
1610 me_count++;
1611 spin_unlock(&me_lock);
1613 for (i = 0; i < karg.count; i++) {
1614 k = 0;
1615 down_read(&me_rwsem);
1616 list_for_each(pos, &me_device_list) {
1617 if (k == list[i].iDevice) {
1618 device =
1619 list_entry(pos, me_device_t, list);
1620 break;
1623 k++;
1626 if (pos == &me_device_list) {
1627 up_read(&me_rwsem);
1628 PERROR("Invalid device number specified.\n");
1629 list[i].iErrno = ME_ERRNO_INVALID_DEVICE;
1630 karg.errno = ME_ERRNO_INVALID_DEVICE;
1631 break;
1632 } else {
1633 list[i].iErrno =
1634 device->me_device_io_stream_stop(device,
1635 filep,
1636 list[i].
1637 iSubdevice,
1638 list[i].
1639 iStopMode,
1640 list[i].
1641 iFlags);
1643 if (list[i].iErrno) {
1644 up_read(&me_rwsem);
1645 karg.errno = list[i].iErrno;
1646 break;
1650 up_read(&me_rwsem);
1653 spin_lock(&me_lock);
1655 me_count--;
1656 spin_unlock(&me_lock);
1659 err = copy_to_user(arg, &karg, sizeof(me_io_stream_stop_t));
1661 if (err) {
1662 PERROR("Can't copy arguments to user space.\n");
1663 return -EFAULT;
1666 err =
1667 copy_to_user(karg.stop_list, list,
1668 sizeof(meIOStreamStop_t) * karg.count);
1670 if (err) {
1671 PERROR("Can't copy stop list to user space.\n");
1672 kfree(list);
1673 return -EFAULT;
1676 kfree(list);
1678 return err;
1681 /* //me_probe_usb
1682 static int me_probe_usb(struct usb_interface *interface, const struct usb_device_id *id)
1684 //int err;
1685 //me_usb_constructor_t *constructor = NULL;
1686 me_device_t *n_device = NULL;
1688 PDEBUG("executed.\n");
1690 switch (id->idProduct)
1692 case USB_DEVICE_ID_MEPHISTO_S1:
1693 if((constructor = symbol_get(mephisto_s1_constructor)) == NULL){
1694 err = request_module(MEPHISTO_S1_NAME);
1695 if(err){
1696 PERROR("Error while request for module %s.\n", MEPHISTO_S1_NAME);
1697 return -ENODEV;
1699 if((constructor = symbol_get(mephisto_s1_constructor)) == NULL){
1700 PERROR("Can't get %s driver module constructor.\n", MEPHISTO_S1_NAME);
1701 return -ENODEV;
1705 if((n_device = (*constructor)(interface)) == NULL){
1706 symbol_put(mephisto_s1_constructor);
1707 PERROR("Can't get device instance of %s driver module.\n", MEPHISTO_S1_NAME);
1708 return -ENODEV;
1711 break;
1713 default:
1714 PERROR("Invalid product id.\n");
1716 return -EINVAL;
1719 return insert_to_device_list(n_device);
1723 /* //me_disconnect_usb
1724 static void me_disconnect_usb(struct usb_interface *interface)
1727 struct usb_device *device = interface_to_usbdev(interface);
1728 int vendor_id = device->descriptor.idVendor;
1729 int device_id = device->descriptor.idProduct;
1730 int serial_no;
1732 sscanf(&device->serial[2], "%x", &serial_no);
1734 PDEBUG("executed.\n");
1736 PINFO("Vendor id = 0x%08X\n", vendor_id);
1737 PINFO("Device id = 0x%08X\n", device_id);
1738 PINFO("Serial Number = 0x%08X\n", serial_no);
1740 replace_with_dummy(vendor_id, device_id, serial_no);
1744 static int me_ioctl(struct inode *inodep,
1745 struct file *filep, unsigned int service, unsigned long arg)
1748 PDEBUG("executed.\n");
1750 if (_IOC_TYPE(service) != MEMAIN_MAGIC) {
1751 PERROR("Invalid magic number.\n");
1752 return -ENOTTY;
1755 PDEBUG("service number: 0x%x.\n", service);
1757 switch (service) {
1758 case ME_IO_IRQ_ENABLE:
1759 return me_io_irq_start(filep, (me_io_irq_start_t *) arg);
1761 case ME_IO_IRQ_WAIT:
1762 return me_io_irq_wait(filep, (me_io_irq_wait_t *) arg);
1764 case ME_IO_IRQ_DISABLE:
1765 return me_io_irq_stop(filep, (me_io_irq_stop_t *) arg);
1767 case ME_IO_RESET_DEVICE:
1768 return me_io_reset_device(filep, (me_io_reset_device_t *) arg);
1770 case ME_IO_RESET_SUBDEVICE:
1771 return me_io_reset_subdevice(filep,
1772 (me_io_reset_subdevice_t *) arg);
1774 case ME_IO_SINGLE_CONFIG:
1775 return me_io_single_config(filep,
1776 (me_io_single_config_t *) arg);
1778 case ME_IO_SINGLE:
1779 return me_io_single(filep, (me_io_single_t *) arg);
1781 case ME_IO_STREAM_CONFIG:
1782 return me_io_stream_config(filep,
1783 (me_io_stream_config_t *) arg);
1785 case ME_IO_STREAM_NEW_VALUES:
1786 return me_io_stream_new_values(filep,
1787 (me_io_stream_new_values_t *)
1788 arg);
1790 case ME_IO_STREAM_READ:
1791 return me_io_stream_read(filep, (me_io_stream_read_t *) arg);
1793 case ME_IO_STREAM_START:
1794 return me_io_stream_start(filep, (me_io_stream_start_t *) arg);
1796 case ME_IO_STREAM_STATUS:
1797 return me_io_stream_status(filep,
1798 (me_io_stream_status_t *) arg);
1800 case ME_IO_STREAM_STOP:
1801 return me_io_stream_stop(filep, (me_io_stream_stop_t *) arg);
1803 case ME_IO_STREAM_WRITE:
1804 return me_io_stream_write(filep, (me_io_stream_write_t *) arg);
1806 case ME_LOCK_DRIVER:
1807 return me_lock_driver(filep, (me_lock_driver_t *) arg);
1809 case ME_LOCK_DEVICE:
1810 return me_lock_device(filep, (me_lock_device_t *) arg);
1812 case ME_LOCK_SUBDEVICE:
1813 return me_lock_subdevice(filep, (me_lock_subdevice_t *) arg);
1815 case ME_QUERY_INFO_DEVICE:
1816 return me_query_info_device(filep,
1817 (me_query_info_device_t *) arg);
1819 case ME_QUERY_DESCRIPTION_DEVICE:
1820 return me_query_description_device(filep,
1821 (me_query_description_device_t
1822 *) arg);
1824 case ME_QUERY_NAME_DEVICE:
1825 return me_query_name_device(filep,
1826 (me_query_name_device_t *) arg);
1828 case ME_QUERY_NAME_DEVICE_DRIVER:
1829 return me_query_name_device_driver(filep,
1830 (me_query_name_device_driver_t
1831 *) arg);
1833 case ME_QUERY_NUMBER_DEVICES:
1834 return me_query_number_devices(filep,
1835 (me_query_number_devices_t *)
1836 arg);
1838 case ME_QUERY_NUMBER_SUBDEVICES:
1839 return me_query_number_subdevices(filep,
1840 (me_query_number_subdevices_t
1841 *) arg);
1843 case ME_QUERY_NUMBER_CHANNELS:
1844 return me_query_number_channels(filep,
1845 (me_query_number_channels_t *)
1846 arg);
1848 case ME_QUERY_NUMBER_RANGES:
1849 return me_query_number_ranges(filep,
1850 (me_query_number_ranges_t *) arg);
1852 case ME_QUERY_RANGE_BY_MIN_MAX:
1853 return me_query_range_by_min_max(filep,
1854 (me_query_range_by_min_max_t *)
1855 arg);
1857 case ME_QUERY_RANGE_INFO:
1858 return me_query_range_info(filep,
1859 (me_query_range_info_t *) arg);
1861 case ME_QUERY_SUBDEVICE_BY_TYPE:
1862 return me_query_subdevice_by_type(filep,
1863 (me_query_subdevice_by_type_t
1864 *) arg);
1866 case ME_QUERY_SUBDEVICE_TYPE:
1867 return me_query_subdevice_type(filep,
1868 (me_query_subdevice_type_t *)
1869 arg);
1871 case ME_QUERY_SUBDEVICE_CAPS:
1872 return me_query_subdevice_caps(filep,
1873 (me_query_subdevice_caps_t *)
1874 arg);
1876 case ME_QUERY_SUBDEVICE_CAPS_ARGS:
1877 return me_query_subdevice_caps_args(filep,
1878 (me_query_subdevice_caps_args_t
1879 *) arg);
1881 case ME_QUERY_TIMER:
1882 return me_query_timer(filep, (me_query_timer_t *) arg);
1884 case ME_QUERY_VERSION_MAIN_DRIVER:
1885 return me_query_version_main_driver(filep,
1886 (me_query_version_main_driver_t
1887 *) arg);
1889 case ME_QUERY_VERSION_DEVICE_DRIVER:
1890 return me_query_version_device_driver(filep,
1891 (me_query_version_device_driver_t
1892 *) arg);
1894 case ME_CONFIG_LOAD:
1895 return me_config_load(filep, (me_config_load_t *) arg);
1898 PERROR("Invalid ioctl number.\n");
1899 return -ENOTTY;
1902 static struct miscdevice me_miscdev = {
1903 .minor = MISC_DYNAMIC_MINOR,
1904 .name = MEMAIN_NAME,
1905 .fops = &me_file_operations,
1908 // Init and exit of module.
1909 static int memain_init(void)
1911 int result = 0;
1913 PDEBUG("executed.\n");
1915 // Register pci driver. This will return 0 if the PCI subsystem is not available.
1916 result = pci_register_driver(&me_pci_driver);
1918 if (result < 0) {
1919 PERROR("Can't register pci driver.\n");
1920 goto INIT_ERROR_1;
1924 // Register usb driver. This will return -ENODEV if no USB subsystem is available.
1925 result = usb_register(&me_usb_driver);
1927 if (result)
1929 if (result == -ENODEV)
1931 PERROR("No USB subsystem available.\n");
1933 else
1935 PERROR("Can't register usb driver.\n");
1936 goto INIT_ERROR_2;
1940 result = misc_register(&me_miscdev);
1941 if (result < 0) {
1942 printk(KERN_ERR MEMAIN_NAME ": can't register misc device\n");
1943 goto INIT_ERROR_3;
1946 return 0;
1948 INIT_ERROR_3:
1949 // usb_deregister(&me_usb_driver);
1951 //INIT_ERROR_2:
1952 pci_unregister_driver(&me_pci_driver);
1953 clear_device_list();
1955 INIT_ERROR_1:
1956 return result;
1959 static void __exit memain_exit(void)
1961 PDEBUG("executed.\n");
1963 misc_deregister(&me_miscdev);
1964 pci_unregister_driver(&me_pci_driver);
1965 // usb_deregister(&me_usb_driver);
1966 clear_device_list();
1969 module_init(memain_init);
1970 module_exit(memain_exit);
1972 // Administrative stuff for modinfo.
1973 MODULE_AUTHOR
1974 ("Guenter Gebhardt <g.gebhardt@meilhaus.de> & Krzysztof Gantzke <k.gantzke@meilhaus.de>");
1975 MODULE_DESCRIPTION("Central module for Meilhaus Driver System.");
1976 MODULE_SUPPORTED_DEVICE("Meilhaus PCI/cPCI boards.");
1977 MODULE_LICENSE("GPL");