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)
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.
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"
58 static unsigned int me_bosch_fw
= 0;
59 EXPORT_SYMBOL(me_bosch_fw
);
62 module_param(me_bosch_fw
, int, S_IRUGO
);
64 MODULE_PARM(me_bosch_fw
, "i");
67 MODULE_PARM_DESC(me_bosch_fw
,
68 "Flags which signals the ME-4600 driver to load the bosch firmware (default = 0).");
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
);
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
,
103 .release
= me_release
,
106 static const struct pci_device_id me_pci_table
[] = {
107 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME1000
) },
108 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME1000_A
) },
109 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME1000_B
) },
111 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME1400
) },
112 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME140A
) },
113 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME140B
) },
114 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME14E0
) },
115 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME14EA
) },
116 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME14EB
) },
117 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME140C
) },
118 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME140D
) },
120 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME1600_4U
) },
121 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME1600_8U
) },
122 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME1600_12U
) },
123 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME1600_16U
) },
124 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME1600_16U_8I
) },
126 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME4610
) },
127 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME4650
) },
128 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME4660
) },
129 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME4660I
) },
130 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME4670
) },
131 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME4670I
) },
132 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME4670S
) },
133 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME4670IS
) },
134 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME4680
) },
135 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME4680I
) },
136 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME4680S
) },
137 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME4680IS
) },
139 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME6004
) },
140 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME6008
) },
141 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME600F
) },
143 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME6014
) },
144 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME6018
) },
145 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME601F
) },
147 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME6034
) },
148 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME6038
) },
149 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME603F
) },
151 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME6104
) },
152 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME6108
) },
153 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME610F
) },
155 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME6114
) },
156 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME6118
) },
157 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME611F
) },
159 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME6134
) },
160 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME6138
) },
161 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME613F
) },
163 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME6044
) },
164 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME6048
) },
165 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME604F
) },
167 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME6054
) },
168 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME6058
) },
169 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME605F
) },
171 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME6074
) },
172 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME6078
) },
173 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME607F
) },
175 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME6144
) },
176 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME6148
) },
177 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME614F
) },
179 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME6154
) },
180 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME6158
) },
181 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME615F
) },
183 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME6174
) },
184 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME6178
) },
185 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME617F
) },
187 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME6259
) },
189 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME6359
) },
191 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME0630
) },
193 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME8100_A
) },
194 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME8100_B
) },
196 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME8200_A
) },
197 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME8200_B
) },
199 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME0940
) },
200 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME0950
) },
201 { PCI_VDEVICE(MEILHAUS
, PCI_DEVICE_ID_MEILHAUS_ME0960
) },
205 MODULE_DEVICE_TABLE(pci
, me_pci_table
);
207 static struct pci_driver me_pci_driver
= {
209 .id_table
= me_pci_table
,
210 .probe
= me_probe_pci
,
211 .remove
= __devexit_p(me_remove_pci
),
215 static struct usb_device_id me_usb_table[] = {
216 { USB_DEVICE(USB_VENDOR_ID_MEPHISTO_S1, USB_DEVICE_ID_MEPHISTO_S1) },
219 MODULE_DEVICE_TABLE (usb, me_usb_table);
221 static struct usb_driver me_usb_driver =
224 .id_table = me_usb_table,
225 .probe = me_probe_usb,
226 .disconnect = me_disconnect_usb
230 #ifdef ME_LOCK_MULTIPLEX_TEMPLATE
231 ME_LOCK_MULTIPLEX_TEMPLATE("me_lock_device",
234 me_device_lock_device
,
235 (device
, filep
, karg
.lock
, karg
.flags
))
237 ME_LOCK_MULTIPLEX_TEMPLATE("me_lock_subdevice",
240 me_device_lock_subdevice
,
241 (device
, filep
, karg
.subdevice
, karg
.lock
,
244 #error macro ME_LOCK_MULTIPLEX_TEMPLATE not defined
247 #ifdef ME_IO_MULTIPLEX_TEMPLATE
248 ME_IO_MULTIPLEX_TEMPLATE("me_io_irq_start",
251 me_device_io_irq_start
,
257 karg
.irq_edge
, karg
.irq_arg
, karg
.flags
))
259 ME_IO_MULTIPLEX_TEMPLATE("me_io_irq_wait",
262 me_device_io_irq_wait
,
267 &karg
.irq_count
, &karg
.value
, karg
.time_out
, karg
.flags
))
269 ME_IO_MULTIPLEX_TEMPLATE("me_io_irq_stop",
272 me_device_io_irq_stop
,
274 filep
, karg
.subdevice
, karg
.channel
, karg
.flags
))
276 ME_IO_MULTIPLEX_TEMPLATE("me_io_reset_device",
277 me_io_reset_device_t
,
279 me_device_io_reset_device
, (device
, filep
, karg
.flags
))
281 ME_IO_MULTIPLEX_TEMPLATE("me_io_reset_subdevice",
282 me_io_reset_subdevice_t
,
283 me_io_reset_subdevice
,
284 me_device_io_reset_subdevice
,
285 (device
, filep
, karg
.subdevice
, karg
.flags
))
287 ME_IO_MULTIPLEX_TEMPLATE("me_io_single_config",
288 me_io_single_config_t
,
290 me_device_io_single_config
,
298 karg
.trig_type
, karg
.trig_edge
, karg
.flags
))
300 ME_IO_MULTIPLEX_TEMPLATE("me_io_stream_new_values",
301 me_io_stream_new_values_t
,
302 me_io_stream_new_values
,
303 me_device_io_stream_new_values
,
306 karg
.subdevice
, karg
.time_out
, &karg
.count
, karg
.flags
))
308 ME_IO_MULTIPLEX_TEMPLATE("me_io_stream_read",
311 me_device_io_stream_read
,
315 karg
.read_mode
, karg
.values
, &karg
.count
, karg
.flags
))
317 ME_IO_MULTIPLEX_TEMPLATE("me_io_stream_status",
318 me_io_stream_status_t
,
320 me_device_io_stream_status
,
324 karg
.wait
, &karg
.status
, &karg
.count
, karg
.flags
))
326 ME_IO_MULTIPLEX_TEMPLATE("me_io_stream_write",
327 me_io_stream_write_t
,
329 me_device_io_stream_write
,
333 karg
.write_mode
, karg
.values
, &karg
.count
, karg
.flags
))
335 #error macro ME_IO_MULTIPLEX_TEMPLATE not defined
338 #ifdef ME_QUERY_MULTIPLEX_STR_TEMPLATE
339 ME_QUERY_MULTIPLEX_STR_TEMPLATE("me_query_name_device",
340 me_query_name_device_t
,
341 me_query_name_device
,
342 me_device_query_name_device
, (device
, &msg
))
344 ME_QUERY_MULTIPLEX_STR_TEMPLATE("me_query_name_device_driver",
345 me_query_name_device_driver_t
,
346 me_query_name_device_driver
,
347 me_device_query_name_device_driver
,
350 ME_QUERY_MULTIPLEX_STR_TEMPLATE("me_query_description_device",
351 me_query_description_device_t
,
352 me_query_description_device
,
353 me_device_query_description_device
,
356 #error macro ME_QUERY_MULTIPLEX_STR_TEMPLATE not defined
359 #ifdef ME_QUERY_MULTIPLEX_TEMPLATE
360 ME_QUERY_MULTIPLEX_TEMPLATE("me_query_info_device",
361 me_query_info_device_t
,
362 me_query_info_device
,
363 me_device_query_info_device
,
370 &karg
.dev_no
, &karg
.func_no
, &karg
.plugged
))
372 ME_QUERY_MULTIPLEX_TEMPLATE("me_query_number_subdevices",
373 me_query_number_subdevices_t
,
374 me_query_number_subdevices
,
375 me_device_query_number_subdevices
,
376 (device
, &karg
.number
))
378 ME_QUERY_MULTIPLEX_TEMPLATE("me_query_number_channels",
379 me_query_number_channels_t
,
380 me_query_number_channels
,
381 me_device_query_number_channels
,
382 (device
, karg
.subdevice
, &karg
.number
))
384 ME_QUERY_MULTIPLEX_TEMPLATE("me_query_subdevice_by_type",
385 me_query_subdevice_by_type_t
,
386 me_query_subdevice_by_type
,
387 me_device_query_subdevice_by_type
,
389 karg
.start_subdevice
,
390 karg
.type
, karg
.subtype
, &karg
.subdevice
))
392 ME_QUERY_MULTIPLEX_TEMPLATE("me_query_subdevice_type",
393 me_query_subdevice_type_t
,
394 me_query_subdevice_type
,
395 me_device_query_subdevice_type
,
396 (device
, karg
.subdevice
, &karg
.type
, &karg
.subtype
))
398 ME_QUERY_MULTIPLEX_TEMPLATE("me_query_subdevice_caps",
399 me_query_subdevice_caps_t
,
400 me_query_subdevice_caps
,
401 me_device_query_subdevice_caps
,
402 (device
, karg
.subdevice
, &karg
.caps
))
404 ME_QUERY_MULTIPLEX_TEMPLATE("me_query_subdevice_caps_args",
405 me_query_subdevice_caps_args_t
,
406 me_query_subdevice_caps_args
,
407 me_device_query_subdevice_caps_args
,
408 (device
, karg
.subdevice
, karg
.cap
, karg
.args
,
411 ME_QUERY_MULTIPLEX_TEMPLATE("me_query_number_ranges",
412 me_query_number_ranges_t
,
413 me_query_number_ranges
,
414 me_device_query_number_ranges
,
415 (device
, karg
.subdevice
, karg
.unit
, &karg
.number
))
417 ME_QUERY_MULTIPLEX_TEMPLATE("me_query_range_by_min_max",
418 me_query_range_by_min_max_t
,
419 me_query_range_by_min_max
,
420 me_device_query_range_by_min_max
,
424 &karg
.min
, &karg
.max
, &karg
.max_data
, &karg
.range
))
426 ME_QUERY_MULTIPLEX_TEMPLATE("me_query_range_info",
427 me_query_range_info_t
,
429 me_device_query_range_info
,
433 &karg
.unit
, &karg
.min
, &karg
.max
, &karg
.max_data
))
435 ME_QUERY_MULTIPLEX_TEMPLATE("me_query_timer",
438 me_device_query_timer
,
442 &karg
.base_frequency
,
443 &karg
.min_ticks
, &karg
.max_ticks
))
445 ME_QUERY_MULTIPLEX_TEMPLATE("me_query_version_device_driver",
446 me_query_version_device_driver_t
,
447 me_query_version_device_driver
,
448 me_device_query_version_device_driver
,
449 (device
, &karg
.version
))
451 #error macro ME_QUERY_MULTIPLEX_TEMPLATE not defined
454 /** ******************************************************************************** **/
456 static me_device_t
*get_dummy_instance(unsigned short vendor_id
,
457 unsigned short device_id
,
458 unsigned int serial_no
,
460 int bus_no
, int dev_no
, int func_no
)
463 me_dummy_constructor_t constructor
= NULL
;
464 me_device_t
*instance
;
466 PDEBUG("executed.\n");
468 if ((constructor
= symbol_get(medummy_constructor
)) == NULL
) {
469 err
= request_module(MEDUMMY_NAME
);
472 PERROR("Error while request for module %s.\n",
477 if ((constructor
= symbol_get(medummy_constructor
)) == NULL
) {
478 PERROR("Can't get %s driver module constructor.\n",
484 if ((instance
= (*constructor
) (vendor_id
,
488 bus_no
, dev_no
, func_no
)) == NULL
)
489 symbol_put(medummy_constructor
);
494 static int __devinit
me_probe_pci(struct pci_dev
*dev
,
495 const struct pci_device_id
*id
)
498 me_pci_constructor_t constructor
= NULL
;
500 me_bosch_constructor_t constructor_bosch
= NULL
;
502 me_device_t
*n_device
= NULL
;
505 char constructor_name
[24] = "me0000_pci_constructor";
506 char module_name
[7] = "me0000";
508 PDEBUG("executed.\n");
509 device
= dev
->device
;
510 if ((device
& 0xF000) == 0x6000) { // Exceptions: me61xx, me62xx, me63xx are handled by one driver.
514 constructor_name
[2] += (char)((device
>> 12) & 0x000F);
515 constructor_name
[3] += (char)((device
>> 8) & 0x000F);
516 PDEBUG("constructor_name: %s\n", constructor_name
);
517 module_name
[2] += (char)((device
>> 12) & 0x000F);
518 module_name
[3] += (char)((device
>> 8) & 0x000F);
519 PDEBUG("module_name: %s\n", module_name
);
522 (me_pci_constructor_t
) symbol_get(constructor_name
)) == NULL
) {
523 if (request_module("%s", module_name
)) {
524 PERROR("Error while request for module %s.\n",
530 (me_pci_constructor_t
) symbol_get(constructor_name
)) ==
532 PERROR("Can't get %s driver module constructor.\n",
538 if ((device
& 0xF000) == 0x4000) { // Bosch build has differnt constructor for me4600.
540 (*constructor_bosch
) (dev
, me_bosch_fw
)) == NULL
) {
541 symbol_put(constructor_name
);
543 ("Can't get device instance of %s driver module.\n",
549 if ((n_device
= (*constructor
) (dev
)) == NULL
) {
550 symbol_put(constructor_name
);
552 ("Can't get device instance of %s driver module.\n",
560 insert_to_device_list(n_device
);
562 n_device
->me_device_io_reset_device(n_device
, NULL
,
563 ME_IO_RESET_DEVICE_NO_FLAGS
);
565 PERROR("Error while reseting device.\n");
567 PDEBUG("Reseting device was sucessful.\n");
569 return ME_ERRNO_SUCCESS
;
572 static void release_instance(me_device_t
*device
)
585 char constructor_name
[24] = "me0000_pci_constructor";
587 PDEBUG("executed.\n");
589 device
->me_device_query_info_device(device
,
595 &dev_no
, &func_no
, &plugged
);
598 device
->me_device_destructor(device
);
600 if (plugged
!= ME_PLUGGED_IN
) {
601 PDEBUG("release: medummy_constructor\n");
603 symbol_put("medummy_constructor");
605 if ((dev_id
& 0xF000) == 0x6000) { // Exceptions: me61xx, me62xx, me63xx are handled by one driver.
609 constructor_name
[2] += (char)((dev_id
>> 12) & 0x000F);
610 constructor_name
[3] += (char)((dev_id
>> 8) & 0x000F);
611 PDEBUG("release: %s\n", constructor_name
);
613 symbol_put(constructor_name
);
617 static int insert_to_device_list(me_device_t
*n_device
)
619 me_device_t
*o_device
= NULL
;
621 struct list_head
*pos
;
639 PDEBUG("executed.\n");
641 n_device
->me_device_query_info_device(n_device
,
648 &n_func_no
, &n_plugged
);
650 down_write(&me_rwsem
);
652 list_for_each(pos
, &me_device_list
) {
653 o_device
= list_entry(pos
, me_device_t
, list
);
654 o_device
->me_device_query_info_device(o_device
,
661 &o_func_no
, &o_plugged
);
663 if (o_plugged
== ME_PLUGGED_OUT
) {
664 if (((o_vendor_id
== n_vendor_id
) &&
665 (o_device_id
== n_device_id
) &&
666 (o_serial_no
== n_serial_no
) &&
667 (o_bus_type
== n_bus_type
)) ||
668 ((o_vendor_id
== n_vendor_id
) &&
669 (o_device_id
== n_device_id
) &&
670 (o_bus_type
== n_bus_type
) &&
671 (o_bus_no
== n_bus_no
) &&
672 (o_dev_no
== n_dev_no
) &&
673 (o_func_no
== n_func_no
))) {
674 n_device
->list
.prev
= pos
->prev
;
675 n_device
->list
.next
= pos
->next
;
676 pos
->prev
->next
= &n_device
->list
;
677 pos
->next
->prev
= &n_device
->list
;
678 release_instance(o_device
);
684 if (pos
== &me_device_list
) {
685 list_add_tail(&n_device
->list
, &me_device_list
);
693 static void __devexit
me_remove_pci(struct pci_dev
*dev
)
695 int vendor_id
= dev
->vendor
;
696 int device_id
= dev
->device
;
697 int subsystem_vendor
= dev
->subsystem_vendor
;
698 int subsystem_device
= dev
->subsystem_device
;
699 int serial_no
= (subsystem_device
<< 16) | subsystem_vendor
;
701 PDEBUG("executed.\n");
703 PINFO("Vendor id = 0x%08X\n", vendor_id
);
704 PINFO("Device id = 0x%08X\n", device_id
);
705 PINFO("Serial Number = 0x%08X\n", serial_no
);
707 replace_with_dummy(vendor_id
, device_id
, serial_no
);
710 static int replace_with_dummy(int vendor_id
, int device_id
, int serial_no
)
713 struct list_head
*pos
;
714 me_device_t
*n_device
= NULL
;
715 me_device_t
*o_device
= NULL
;
725 PDEBUG("executed.\n");
727 down_write(&me_rwsem
);
729 list_for_each(pos
, &me_device_list
) {
730 o_device
= list_entry(pos
, me_device_t
, list
);
731 o_device
->me_device_query_info_device(o_device
,
738 &o_func_no
, &o_plugged
);
740 if (o_plugged
== ME_PLUGGED_IN
) {
741 if (((o_vendor_id
== vendor_id
) &&
742 (o_device_id
== device_id
) &&
743 (o_serial_no
== serial_no
))) {
744 n_device
= get_dummy_instance(o_vendor_id
,
754 PERROR("Cannot get dummy instance.\n");
758 n_device
->list
.prev
= pos
->prev
;
760 n_device
->list
.next
= pos
->next
;
761 pos
->prev
->next
= &n_device
->list
;
762 pos
->next
->prev
= &n_device
->list
;
763 release_instance(o_device
);
774 static void clear_device_list(void)
777 struct list_head
*entry
;
780 // Clear the device info list .
781 down_write(&me_rwsem
);
783 while (!list_empty(&me_device_list
)) {
784 entry
= me_device_list
.next
;
785 device
= list_entry(entry
, me_device_t
, list
);
787 release_instance(device
);
793 static int lock_driver(struct file
*filep
, int lock
, int flags
)
795 int err
= ME_ERRNO_SUCCESS
;
798 PDEBUG("executed.\n");
800 down_read(&me_rwsem
);
809 ("Driver System is currently used by another process.\n");
811 } else if ((me_filep
!= NULL
) && (me_filep
!= filep
)) {
813 ("Driver System is already logged by another process.\n");
814 err
= ME_ERRNO_LOCKED
;
816 list_for_each_entry(device
, &me_device_list
, list
) {
818 device
->me_device_lock_device(device
, filep
,
832 case ME_LOCK_RELEASE
:
833 if ((me_filep
!= NULL
) && (me_filep
!= filep
)) {
834 err
= ME_ERRNO_SUCCESS
;
836 list_for_each_entry(device
, &me_device_list
, list
) {
837 device
->me_device_lock_device(device
, filep
,
848 PERROR("Invalid lock specified.\n");
850 err
= ME_ERRNO_INVALID_LOCK
;
855 spin_unlock(&me_lock
);
862 static int me_lock_driver(struct file
*filep
, me_lock_driver_t
*arg
)
866 me_lock_driver_t lock
;
868 PDEBUG("executed.\n");
870 err
= copy_from_user(&lock
, arg
, sizeof(me_lock_driver_t
));
873 PERROR("Can't copy arguments to kernel space.\n");
877 lock
.errno
= lock_driver(filep
, lock
.lock
, lock
.flags
);
879 err
= copy_to_user(arg
, &lock
, sizeof(me_lock_driver_t
));
882 PERROR("Can't copy query back to user space.\n");
886 return ME_ERRNO_SUCCESS
;
889 static int me_open(struct inode
*inode_ptr
, struct file
*filep
)
892 PDEBUG("executed.\n");
893 // Nothing to do here.
897 static int me_release(struct inode
*inode_ptr
, struct file
*filep
)
900 PDEBUG("executed.\n");
901 lock_driver(filep
, ME_LOCK_RELEASE
, ME_LOCK_DRIVER_NO_FLAGS
);
906 static int me_query_version_main_driver(struct file
*filep
,
907 me_query_version_main_driver_t
*arg
)
910 me_query_version_main_driver_t karg
;
912 PDEBUG("executed.\n");
914 karg
.version
= ME_VERSION_DRIVER
;
915 karg
.errno
= ME_ERRNO_SUCCESS
;
917 err
= copy_to_user(arg
, &karg
, sizeof(me_query_version_main_driver_t
));
920 PERROR("Can't copy query back to user space.\n");
927 static int me_config_load_device(struct file
*filep
,
928 me_cfg_device_entry_t
*karg
, int device_no
)
931 int err
= ME_ERRNO_SUCCESS
;
934 struct list_head
*pos
= NULL
;
935 me_device_t
*device
= NULL
;
937 PDEBUG("executed.\n");
939 list_for_each(pos
, &me_device_list
) {
940 if (k
== device_no
) {
941 device
= list_entry(pos
, me_device_t
, list
);
948 if (pos
== &me_device_list
) {
949 PERROR("Invalid device number specified.\n");
950 return ME_ERRNO_INVALID_DEVICE
;
954 if ((me_filep
!= NULL
) && (me_filep
!= filep
)) {
955 spin_unlock(&me_lock
);
956 PERROR("Resource is locked by another process.\n");
957 return ME_ERRNO_LOCKED
;
960 spin_unlock(&me_lock
);
963 device
->me_device_config_load(device
, filep
, karg
);
967 spin_unlock(&me_lock
);
974 static int me_config_load(struct file
*filep
, me_config_load_t
*arg
)
978 me_config_load_t cfg_setup
;
979 me_config_load_t karg_cfg_setup
;
981 struct list_head
*pos
= NULL
;
983 struct list_head new_list
;
984 me_device_t
*o_device
;
985 me_device_t
*n_device
;
995 PDEBUG("executed.\n");
997 // Copy argument to kernel space.
998 err
= copy_from_user(&karg_cfg_setup
, arg
, sizeof(me_config_load_t
));
1001 PERROR("Can't copy arguments to kernel space.\n");
1004 // Allocate kernel buffer for device list.
1005 cfg_setup
.device_list
=
1006 kmalloc(sizeof(me_cfg_device_entry_t
) * karg_cfg_setup
.count
,
1009 if (!cfg_setup
.device_list
) {
1010 PERROR("Can't get buffer %li for device list.\n",
1011 sizeof(me_cfg_device_entry_t
) * karg_cfg_setup
.count
);
1014 // Copy device list to kernel space.
1016 copy_from_user(cfg_setup
.device_list
, karg_cfg_setup
.device_list
,
1017 sizeof(me_cfg_device_entry_t
) *
1018 karg_cfg_setup
.count
);
1021 PERROR("Can't copy device list to kernel space.\n");
1022 kfree(cfg_setup
.device_list
);
1026 cfg_setup
.count
= karg_cfg_setup
.count
;
1028 INIT_LIST_HEAD(&new_list
);
1030 down_write(&me_rwsem
);
1032 spin_lock(&me_lock
);
1034 if ((me_filep
!= NULL
) && (me_filep
!= filep
)) {
1035 spin_unlock(&me_lock
);
1036 PERROR("Driver System is logged by another process.\n");
1037 karg_cfg_setup
.errno
= ME_ERRNO_LOCKED
;
1040 spin_unlock(&me_lock
);
1042 for (i
= 0; i
< karg_cfg_setup
.count
; i
++) {
1043 PDEBUG("me_config_load() device=%d.\n", i
);
1044 if (cfg_setup
.device_list
[i
].tcpip
.access_type
==
1045 ME_ACCESS_TYPE_LOCAL
) {
1046 list_for_each(pos
, &me_device_list
) {
1048 list_entry(pos
, me_device_t
, list
);
1050 me_device_query_info_device
1051 (o_device
, &o_vendor_id
,
1052 &o_device_id
, &o_serial_no
,
1053 &o_bus_type
, &o_bus_no
, &o_dev_no
,
1054 &o_func_no
, &o_plugged
);
1056 if (cfg_setup
.device_list
[i
].info
.
1057 hw_location
.bus_type
==
1059 if (((o_vendor_id
==
1060 cfg_setup
.device_list
[i
].
1064 device_list
[i
].info
.
1068 device_list
[i
].info
.
1072 device_list
[i
].info
.
1073 hw_location
.bus_type
))
1076 cfg_setup
.device_list
[i
].
1080 device_list
[i
].info
.
1084 device_list
[i
].info
.
1085 hw_location
.bus_type
)
1088 device_list
[i
].info
.
1089 hw_location
.pci
.bus_no
)
1092 device_list
[i
].info
.
1097 device_list
[i
].info
.
1106 else if (cfg_setup.device_list[i].info.hw_location.bus_type == ME_BUS_TYPE_USB)
1108 if (((o_vendor_id == cfg_setup.device_list[i].info.vendor_id) &&
1109 (o_device_id == cfg_setup.device_list[i].info.device_id) &&
1110 (o_serial_no == cfg_setup.device_list[i].info.serial_no) &&
1111 (o_bus_type == cfg_setup.device_list[i].info.hw_location.bus_type)) ||
1112 ((o_vendor_id == cfg_setup.device_list[i].info.vendor_id) &&
1113 (o_device_id == cfg_setup.device_list[i].info.device_id) &&
1114 (o_bus_type == cfg_setup.device_list[i].info.hw_location.bus_type) &&
1115 (o_bus_no == cfg_setup.device_list[i].info.hw_location.usb.root_hub_no)))
1117 list_move_tail(pos, &new_list);
1123 PERROR("Wrong bus type: %d.\n",
1124 cfg_setup
.device_list
[i
].
1130 if (pos
== &me_device_list
) { // Device is not already in the list
1131 if (cfg_setup
.device_list
[i
].info
.
1132 hw_location
.bus_type
==
1136 (cfg_setup
.device_list
[i
].
1138 cfg_setup
.device_list
[i
].
1140 cfg_setup
.device_list
[i
].
1142 cfg_setup
.device_list
[i
].
1143 info
.hw_location
.bus_type
,
1144 cfg_setup
.device_list
[i
].
1145 info
.hw_location
.pci
.
1147 cfg_setup
.device_list
[i
].
1148 info
.hw_location
.pci
.
1150 cfg_setup
.device_list
[i
].
1151 info
.hw_location
.pci
.
1156 ("Can't get dummy instance.\n");
1159 spin_lock(&me_lock
);
1161 spin_unlock(&me_lock
);
1162 up_write(&me_rwsem
);
1166 list_add_tail(&n_device
->list
,
1170 else if (cfg_setup.device_list[i].info.hw_location.bus_type == ME_BUS_TYPE_USB)
1172 n_device = get_dummy_instance(
1173 cfg_setup.device_list[i].info.vendor_id,
1174 cfg_setup.device_list[i].info.device_id,
1175 cfg_setup.device_list[i].info.serial_no,
1176 cfg_setup.device_list[i].info.hw_location.bus_type,
1177 cfg_setup.device_list[i].info.hw_location.usb.root_hub_no,
1183 PERROR("Can't get dummy instance.\n");
1184 kfree(cfg_setup.device_list);
1185 spin_lock(&me_lock);
1187 spin_unlock(&me_lock);
1188 up_write(&me_rwsem);
1192 list_add_tail(&n_device->list, &new_list);
1197 n_device
= get_dummy_instance(0,
1201 PERROR("Can't get dummy instance.\n");
1202 kfree(cfg_setup
.device_list
);
1203 spin_lock(&me_lock
);
1205 spin_unlock(&me_lock
);
1206 up_write(&me_rwsem
);
1210 list_add_tail(&n_device
->list
, &new_list
);
1214 while (!list_empty(&me_device_list
)) {
1216 list_entry(me_device_list
.next
, me_device_t
, list
);
1217 o_device
->me_device_query_info_device(o_device
,
1227 if (o_plugged
== ME_PLUGGED_IN
) {
1228 list_move_tail(me_device_list
.next
, &new_list
);
1230 list_del(me_device_list
.next
);
1231 release_instance(o_device
);
1235 // Move temporary new list to global driver list.
1236 list_splice(&new_list
, &me_device_list
);
1238 karg_cfg_setup
.errno
= ME_ERRNO_SUCCESS
;
1241 for (i
= 0; i
< cfg_setup
.count
; i
++) {
1243 karg_cfg_setup
.errno
=
1244 me_config_load_device(filep
, &cfg_setup
.device_list
[i
], i
);
1245 if (karg_cfg_setup
.errno
) {
1246 PERROR("me_config_load_device(%d)=%d\n", i
,
1247 karg_cfg_setup
.errno
);
1252 spin_lock(&me_lock
);
1255 spin_unlock(&me_lock
);
1256 up_write(&me_rwsem
);
1258 err
= copy_to_user(arg
, &karg_cfg_setup
, sizeof(me_config_load_t
));
1261 PERROR("Can't copy config list to user space.\n");
1262 kfree(cfg_setup
.device_list
);
1266 kfree(cfg_setup
.device_list
);
1270 static int me_io_stream_start(struct file
*filep
, me_io_stream_start_t
*arg
)
1275 struct list_head
*pos
;
1276 me_device_t
*device
;
1277 me_io_stream_start_t karg
;
1278 meIOStreamStart_t
*list
;
1280 PDEBUG("executed.\n");
1282 err
= copy_from_user(&karg
, arg
, sizeof(me_io_stream_start_t
));
1285 PERROR("Can't copy arguments to kernel space.\n");
1289 karg
.errno
= ME_ERRNO_SUCCESS
;
1291 list
= kmalloc(sizeof(meIOStreamStart_t
) * karg
.count
, GFP_KERNEL
);
1294 PERROR("Can't get buffer for start list.\n");
1299 copy_from_user(list
, karg
.start_list
,
1300 sizeof(meIOStreamStart_t
) * karg
.count
);
1303 PERROR("Can't copy start list to kernel space.\n");
1308 spin_lock(&me_lock
);
1310 if ((me_filep
!= NULL
) && (me_filep
!= filep
)) {
1311 spin_unlock(&me_lock
);
1312 PERROR("Driver System is logged by another process.\n");
1314 for (i
= 0; i
< karg
.count
; i
++) {
1315 list
[i
].iErrno
= ME_ERRNO_LOCKED
;
1319 spin_unlock(&me_lock
);
1321 for (i
= 0; i
< karg
.count
; i
++) {
1322 down_read(&me_rwsem
);
1324 list_for_each(pos
, &me_device_list
) {
1325 if (k
== list
[i
].iDevice
) {
1327 list_entry(pos
, me_device_t
, list
);
1334 if (pos
== &me_device_list
) {
1336 PERROR("Invalid device number specified.\n");
1337 list
[i
].iErrno
= ME_ERRNO_INVALID_DEVICE
;
1338 karg
.errno
= ME_ERRNO_INVALID_DEVICE
;
1342 device
->me_device_io_stream_start(device
,
1353 if (list
[i
].iErrno
) {
1355 karg
.errno
= list
[i
].iErrno
;
1363 spin_lock(&me_lock
);
1366 spin_unlock(&me_lock
);
1369 err
= copy_to_user(arg
, &karg
, sizeof(me_io_stream_start_t
));
1372 PERROR("Can't copy arguments to user space.\n");
1378 copy_to_user(karg
.start_list
, list
,
1379 sizeof(meIOStreamStart_t
) * karg
.count
);
1382 PERROR("Can't copy start list to user space.\n");
1392 static int me_io_single(struct file
*filep
, me_io_single_t
*arg
)
1397 struct list_head
*pos
;
1398 me_device_t
*device
;
1399 me_io_single_t karg
;
1402 PDEBUG("executed.\n");
1404 err
= copy_from_user(&karg
, arg
, sizeof(me_io_single_t
));
1407 PERROR("Can't copy arguments to kernel space.\n");
1411 karg
.errno
= ME_ERRNO_SUCCESS
;
1413 list
= kmalloc(sizeof(meIOSingle_t
) * karg
.count
, GFP_KERNEL
);
1416 PERROR("Can't get buffer for single list.\n");
1421 copy_from_user(list
, karg
.single_list
,
1422 sizeof(meIOSingle_t
) * karg
.count
);
1425 PERROR("Can't copy single list to kernel space.\n");
1430 spin_lock(&me_lock
);
1432 if ((me_filep
!= NULL
) && (me_filep
!= filep
)) {
1433 spin_unlock(&me_lock
);
1434 PERROR("Driver System is logged by another process.\n");
1436 for (i
= 0; i
< karg
.count
; i
++) {
1437 list
[i
].iErrno
= ME_ERRNO_LOCKED
;
1441 spin_unlock(&me_lock
);
1443 for (i
= 0; i
< karg
.count
; i
++) {
1446 down_read(&me_rwsem
);
1448 list_for_each(pos
, &me_device_list
) {
1449 if (k
== list
[i
].iDevice
) {
1451 list_entry(pos
, me_device_t
, list
);
1458 if (pos
== &me_device_list
) {
1460 PERROR("Invalid device number specified.\n");
1461 list
[i
].iErrno
= ME_ERRNO_INVALID_DEVICE
;
1462 karg
.errno
= ME_ERRNO_INVALID_DEVICE
;
1465 if (list
[i
].iDir
== ME_DIR_OUTPUT
) {
1468 me_device_io_single_write(device
,
1481 if (list
[i
].iErrno
) {
1483 karg
.errno
= list
[i
].iErrno
;
1486 } else if (list
[i
].iDir
== ME_DIR_INPUT
) {
1489 me_device_io_single_read(device
,
1502 if (list
[i
].iErrno
) {
1504 karg
.errno
= list
[i
].iErrno
;
1510 ("Invalid single direction specified.\n");
1511 list
[i
].iErrno
= ME_ERRNO_INVALID_DIR
;
1512 karg
.errno
= ME_ERRNO_INVALID_DIR
;
1520 spin_lock(&me_lock
);
1523 spin_unlock(&me_lock
);
1526 err
= copy_to_user(arg
, &karg
, sizeof(me_io_single_t
));
1529 PERROR("Can't copy arguments to user space.\n");
1534 copy_to_user(karg
.single_list
, list
,
1535 sizeof(meIOSingle_t
) * karg
.count
);
1538 PERROR("Can't copy single list to user space.\n");
1548 static int me_io_stream_config(struct file
*filep
, me_io_stream_config_t
*arg
)
1553 struct list_head
*pos
;
1554 me_device_t
*device
;
1555 me_io_stream_config_t karg
;
1556 meIOStreamConfig_t
*list
;
1558 PDEBUG("executed.\n");
1560 err
= copy_from_user(&karg
, arg
, sizeof(me_io_stream_config_t
));
1563 PERROR("Can't copy arguments to kernel space.\n");
1567 list
= kmalloc(sizeof(meIOStreamConfig_t
) * karg
.count
, GFP_KERNEL
);
1570 PERROR("Can't get buffer for config list.\n");
1575 copy_from_user(list
, karg
.config_list
,
1576 sizeof(meIOStreamConfig_t
) * karg
.count
);
1579 PERROR("Can't copy config list to kernel space.\n");
1584 spin_lock(&me_lock
);
1586 if ((me_filep
!= NULL
) && (me_filep
!= filep
)) {
1587 spin_unlock(&me_lock
);
1588 PERROR("Driver System is logged by another process.\n");
1589 karg
.errno
= ME_ERRNO_LOCKED
;
1592 spin_unlock(&me_lock
);
1594 down_read(&me_rwsem
);
1596 list_for_each(pos
, &me_device_list
) {
1597 if (k
== karg
.device
) {
1598 device
= list_entry(pos
, me_device_t
, list
);
1605 if (pos
== &me_device_list
) {
1606 PERROR("Invalid device number specified.\n");
1607 karg
.errno
= ME_ERRNO_INVALID_DEVICE
;
1610 device
->me_device_io_stream_config(device
, filep
,
1621 spin_lock(&me_lock
);
1623 spin_unlock(&me_lock
);
1626 err
= copy_to_user(arg
, &karg
, sizeof(me_io_stream_config_t
));
1629 PERROR("Can't copy back to user space.\n");
1639 static int me_query_number_devices(struct file
*filep
,
1640 me_query_number_devices_t
*arg
)
1643 me_query_number_devices_t karg
;
1645 struct list_head
*pos
;
1647 PDEBUG("executed.\n");
1650 down_read(&me_rwsem
);
1651 list_for_each(pos
, &me_device_list
) {
1657 karg
.errno
= ME_ERRNO_SUCCESS
;
1659 err
= copy_to_user(arg
, &karg
, sizeof(me_query_number_devices_t
));
1662 PERROR("Can't copy query back to user space.\n");
1669 static int me_io_stream_stop(struct file
*filep
, me_io_stream_stop_t
*arg
)
1674 struct list_head
*pos
;
1675 me_device_t
*device
;
1676 me_io_stream_stop_t karg
;
1677 meIOStreamStop_t
*list
;
1679 PDEBUG("executed.\n");
1681 err
= copy_from_user(&karg
, arg
, sizeof(me_io_stream_stop_t
));
1684 PERROR("Can't copy arguments to kernel space.\n");
1688 karg
.errno
= ME_ERRNO_SUCCESS
;
1690 list
= kmalloc(sizeof(meIOStreamStop_t
) * karg
.count
, GFP_KERNEL
);
1693 PERROR("Can't get buffer for stop list.\n");
1698 copy_from_user(list
, karg
.stop_list
,
1699 sizeof(meIOStreamStop_t
) * karg
.count
);
1702 PERROR("Can't copy stop list to kernel space.\n");
1707 spin_lock(&me_lock
);
1709 if ((me_filep
!= NULL
) && (me_filep
!= filep
)) {
1710 spin_unlock(&me_lock
);
1711 PERROR("Driver System is logged by another process.\n");
1713 for (i
= 0; i
< karg
.count
; i
++) {
1714 list
[i
].iErrno
= ME_ERRNO_LOCKED
;
1718 spin_unlock(&me_lock
);
1720 for (i
= 0; i
< karg
.count
; i
++) {
1722 down_read(&me_rwsem
);
1723 list_for_each(pos
, &me_device_list
) {
1724 if (k
== list
[i
].iDevice
) {
1726 list_entry(pos
, me_device_t
, list
);
1733 if (pos
== &me_device_list
) {
1735 PERROR("Invalid device number specified.\n");
1736 list
[i
].iErrno
= ME_ERRNO_INVALID_DEVICE
;
1737 karg
.errno
= ME_ERRNO_INVALID_DEVICE
;
1741 device
->me_device_io_stream_stop(device
,
1750 if (list
[i
].iErrno
) {
1752 karg
.errno
= list
[i
].iErrno
;
1760 spin_lock(&me_lock
);
1763 spin_unlock(&me_lock
);
1766 err
= copy_to_user(arg
, &karg
, sizeof(me_io_stream_stop_t
));
1769 PERROR("Can't copy arguments to user space.\n");
1774 copy_to_user(karg
.stop_list
, list
,
1775 sizeof(meIOStreamStop_t
) * karg
.count
);
1778 PERROR("Can't copy stop list to user space.\n");
1789 static int me_probe_usb(struct usb_interface *interface, const struct usb_device_id *id)
1792 //me_usb_constructor_t *constructor = NULL;
1793 me_device_t *n_device = NULL;
1795 PDEBUG("executed.\n");
1797 switch (id->idProduct)
1799 case USB_DEVICE_ID_MEPHISTO_S1:
1800 if((constructor = symbol_get(mephisto_s1_constructor)) == NULL){
1801 err = request_module(MEPHISTO_S1_NAME);
1803 PERROR("Error while request for module %s.\n", MEPHISTO_S1_NAME);
1806 if((constructor = symbol_get(mephisto_s1_constructor)) == NULL){
1807 PERROR("Can't get %s driver module constructor.\n", MEPHISTO_S1_NAME);
1812 if((n_device = (*constructor)(interface)) == NULL){
1813 symbol_put(mephisto_s1_constructor);
1814 PERROR("Can't get device instance of %s driver module.\n", MEPHISTO_S1_NAME);
1821 PERROR("Invalid product id.\n");
1826 return insert_to_device_list(n_device);
1830 /* //me_disconnect_usb
1831 static void me_disconnect_usb(struct usb_interface *interface)
1834 struct usb_device *device = interface_to_usbdev(interface);
1835 int vendor_id = device->descriptor.idVendor;
1836 int device_id = device->descriptor.idProduct;
1839 sscanf(&device->serial[2], "%x", &serial_no);
1841 PDEBUG("executed.\n");
1843 PINFO("Vendor id = 0x%08X\n", vendor_id);
1844 PINFO("Device id = 0x%08X\n", device_id);
1845 PINFO("Serial Number = 0x%08X\n", serial_no);
1847 replace_with_dummy(vendor_id, device_id, serial_no);
1851 static int me_ioctl(struct inode
*inodep
,
1852 struct file
*filep
, unsigned int service
, unsigned long arg
)
1855 PDEBUG("executed.\n");
1857 if (_IOC_TYPE(service
) != MEMAIN_MAGIC
) {
1858 PERROR("Invalid magic number.\n");
1862 PDEBUG("service number: 0x%x.\n", service
);
1865 case ME_IO_IRQ_ENABLE
:
1866 return me_io_irq_start(filep
, (me_io_irq_start_t
*) arg
);
1868 case ME_IO_IRQ_WAIT
:
1869 return me_io_irq_wait(filep
, (me_io_irq_wait_t
*) arg
);
1871 case ME_IO_IRQ_DISABLE
:
1872 return me_io_irq_stop(filep
, (me_io_irq_stop_t
*) arg
);
1874 case ME_IO_RESET_DEVICE
:
1875 return me_io_reset_device(filep
, (me_io_reset_device_t
*) arg
);
1877 case ME_IO_RESET_SUBDEVICE
:
1878 return me_io_reset_subdevice(filep
,
1879 (me_io_reset_subdevice_t
*) arg
);
1881 case ME_IO_SINGLE_CONFIG
:
1882 return me_io_single_config(filep
,
1883 (me_io_single_config_t
*) arg
);
1886 return me_io_single(filep
, (me_io_single_t
*) arg
);
1888 case ME_IO_STREAM_CONFIG
:
1889 return me_io_stream_config(filep
,
1890 (me_io_stream_config_t
*) arg
);
1892 case ME_IO_STREAM_NEW_VALUES
:
1893 return me_io_stream_new_values(filep
,
1894 (me_io_stream_new_values_t
*)
1897 case ME_IO_STREAM_READ
:
1898 return me_io_stream_read(filep
, (me_io_stream_read_t
*) arg
);
1900 case ME_IO_STREAM_START
:
1901 return me_io_stream_start(filep
, (me_io_stream_start_t
*) arg
);
1903 case ME_IO_STREAM_STATUS
:
1904 return me_io_stream_status(filep
,
1905 (me_io_stream_status_t
*) arg
);
1907 case ME_IO_STREAM_STOP
:
1908 return me_io_stream_stop(filep
, (me_io_stream_stop_t
*) arg
);
1910 case ME_IO_STREAM_WRITE
:
1911 return me_io_stream_write(filep
, (me_io_stream_write_t
*) arg
);
1913 case ME_LOCK_DRIVER
:
1914 return me_lock_driver(filep
, (me_lock_driver_t
*) arg
);
1916 case ME_LOCK_DEVICE
:
1917 return me_lock_device(filep
, (me_lock_device_t
*) arg
);
1919 case ME_LOCK_SUBDEVICE
:
1920 return me_lock_subdevice(filep
, (me_lock_subdevice_t
*) arg
);
1922 case ME_QUERY_INFO_DEVICE
:
1923 return me_query_info_device(filep
,
1924 (me_query_info_device_t
*) arg
);
1926 case ME_QUERY_DESCRIPTION_DEVICE
:
1927 return me_query_description_device(filep
,
1928 (me_query_description_device_t
1931 case ME_QUERY_NAME_DEVICE
:
1932 return me_query_name_device(filep
,
1933 (me_query_name_device_t
*) arg
);
1935 case ME_QUERY_NAME_DEVICE_DRIVER
:
1936 return me_query_name_device_driver(filep
,
1937 (me_query_name_device_driver_t
1940 case ME_QUERY_NUMBER_DEVICES
:
1941 return me_query_number_devices(filep
,
1942 (me_query_number_devices_t
*)
1945 case ME_QUERY_NUMBER_SUBDEVICES
:
1946 return me_query_number_subdevices(filep
,
1947 (me_query_number_subdevices_t
1950 case ME_QUERY_NUMBER_CHANNELS
:
1951 return me_query_number_channels(filep
,
1952 (me_query_number_channels_t
*)
1955 case ME_QUERY_NUMBER_RANGES
:
1956 return me_query_number_ranges(filep
,
1957 (me_query_number_ranges_t
*) arg
);
1959 case ME_QUERY_RANGE_BY_MIN_MAX
:
1960 return me_query_range_by_min_max(filep
,
1961 (me_query_range_by_min_max_t
*)
1964 case ME_QUERY_RANGE_INFO
:
1965 return me_query_range_info(filep
,
1966 (me_query_range_info_t
*) arg
);
1968 case ME_QUERY_SUBDEVICE_BY_TYPE
:
1969 return me_query_subdevice_by_type(filep
,
1970 (me_query_subdevice_by_type_t
1973 case ME_QUERY_SUBDEVICE_TYPE
:
1974 return me_query_subdevice_type(filep
,
1975 (me_query_subdevice_type_t
*)
1978 case ME_QUERY_SUBDEVICE_CAPS
:
1979 return me_query_subdevice_caps(filep
,
1980 (me_query_subdevice_caps_t
*)
1983 case ME_QUERY_SUBDEVICE_CAPS_ARGS
:
1984 return me_query_subdevice_caps_args(filep
,
1985 (me_query_subdevice_caps_args_t
1988 case ME_QUERY_TIMER
:
1989 return me_query_timer(filep
, (me_query_timer_t
*) arg
);
1991 case ME_QUERY_VERSION_MAIN_DRIVER
:
1992 return me_query_version_main_driver(filep
,
1993 (me_query_version_main_driver_t
1996 case ME_QUERY_VERSION_DEVICE_DRIVER
:
1997 return me_query_version_device_driver(filep
,
1998 (me_query_version_device_driver_t
2001 case ME_CONFIG_LOAD
:
2002 return me_config_load(filep
, (me_config_load_t
*) arg
);
2005 PERROR("Invalid ioctl number.\n");
2009 static struct miscdevice me_miscdev
= {
2010 .minor
= MISC_DYNAMIC_MINOR
,
2011 .name
= MEMAIN_NAME
,
2012 .fops
= &me_file_operations
,
2015 // Init and exit of module.
2016 static int memain_init(void)
2020 PDEBUG("executed.\n");
2022 // Register pci driver. This will return 0 if the PCI subsystem is not available.
2023 result
= pci_register_driver(&me_pci_driver
);
2026 PERROR("Can't register pci driver.\n");
2031 // Register usb driver. This will return -ENODEV if no USB subsystem is available.
2032 result = usb_register(&me_usb_driver);
2036 if (result == -ENODEV)
2038 PERROR("No USB subsystem available.\n");
2042 PERROR("Can't register usb driver.\n");
2047 result
= misc_register(&me_miscdev
);
2049 printk(KERN_ERR MEMAIN_NAME
": can't register misc device\n");
2056 // usb_deregister(&me_usb_driver);
2059 pci_unregister_driver(&me_pci_driver
);
2060 clear_device_list();
2066 static void __exit
memain_exit(void)
2068 PDEBUG("executed.\n");
2070 misc_deregister(&me_miscdev
);
2071 pci_unregister_driver(&me_pci_driver
);
2072 // usb_deregister(&me_usb_driver);
2073 clear_device_list();
2076 module_init(memain_init
);
2077 module_exit(memain_exit
);
2079 // Administrative stuff for modinfo.
2081 ("Guenter Gebhardt <g.gebhardt@meilhaus.de> & Krzysztof Gantzke <k.gantzke@meilhaus.de>");
2082 MODULE_DESCRIPTION("Central module for Meilhaus Driver System.");
2083 MODULE_SUPPORTED_DEVICE("Meilhaus PCI/cPCI boards.");
2084 MODULE_LICENSE("GPL");