ASoC: Remove duplicate ADC/DAC widgets from wm_hubs.c
[linux/fpc-iii.git] / drivers / staging / meilhaus / medevice.c
blob75aaec0f681bdef67d23bf95e15a210912f1d339
1 /**
2 * @file medevice.c
4 * @brief Meilhaus device base class.
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 #include "mecommon.h"
29 #include "meinternal.h"
30 #include "medefines.h"
31 #include "meerror.h"
33 #include "medebug.h"
34 #include "medevice.h"
36 #ifndef __KERNEL__
37 # define __KERNEL__
38 #endif
40 static int me_device_io_irq_start(struct me_device *device,
41 struct file *filep,
42 int subdevice,
43 int channel,
44 int irq_source,
45 int irq_edge, int irq_arg, int flags)
47 int err = ME_ERRNO_SUCCESS;
48 me_subdevice_t *s;
50 PDEBUG("executed.\n");
52 // Check subdevice index.
53 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
54 PERROR("Invalid subdevice.\n");
55 return ME_ERRNO_INVALID_SUBDEVICE;
57 // Enter device.
58 err = me_dlock_enter(&device->dlock, filep);
60 if (err) {
61 PERROR("Cannot enter device.\n");
62 return err;
64 // Get subdevice instance.
65 s = me_slist_get_subdevice(&device->slist, subdevice);
67 if (s) {
68 // Call subdevice method.
69 err = s->me_subdevice_io_irq_start(s,
70 filep,
71 channel,
72 irq_source,
73 irq_edge, irq_arg, flags);
74 } else {
75 // Something really bad happened.
76 PERROR("Cannot get subdevice instance.\n");
77 err = ME_ERRNO_INTERNAL;
80 // Exit device.
81 me_dlock_exit(&device->dlock, filep);
83 return err;
86 static int me_device_io_irq_wait(struct me_device *device,
87 struct file *filep,
88 int subdevice,
89 int channel,
90 int *irq_count,
91 int *value, int time_out, int flags)
93 int err = ME_ERRNO_SUCCESS;
94 me_subdevice_t *s;
96 PDEBUG("executed.\n");
98 // Check subdevice index.
99 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
100 PERROR("Invalid subdevice.\n");
101 return ME_ERRNO_INVALID_SUBDEVICE;
103 // Enter device.
104 err = me_dlock_enter(&device->dlock, filep);
106 if (err) {
107 PERROR("Cannot enter device.\n");
108 return err;
110 // Get subdevice instance.
111 s = me_slist_get_subdevice(&device->slist, subdevice);
113 if (s) {
114 // Call subdevice method.
115 err = s->me_subdevice_io_irq_wait(s,
116 filep,
117 channel,
118 irq_count,
119 value, time_out, flags);
120 } else {
121 // Something really bad happened.
122 PERROR("Cannot get subdevice instance.\n");
123 err = ME_ERRNO_INTERNAL;
126 // Exit device.
127 me_dlock_exit(&device->dlock, filep);
129 return err;
132 static int me_device_io_irq_stop(struct me_device *device,
133 struct file *filep,
134 int subdevice, int channel, int flags)
136 int err = ME_ERRNO_SUCCESS;
137 me_subdevice_t *s;
139 PDEBUG("executed.\n");
141 // Check subdevice index.
142 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
143 PERROR("Invalid subdevice.\n");
144 return ME_ERRNO_INVALID_SUBDEVICE;
146 // Enter device.
147 err = me_dlock_enter(&device->dlock, filep);
149 if (err) {
150 PERROR("Cannot enter device.\n");
151 return err;
153 // Get subdevice instance.
154 s = me_slist_get_subdevice(&device->slist, subdevice);
156 if (s) {
157 // Call subdevice method.
158 err = s->me_subdevice_io_irq_stop(s, filep, channel, flags);
159 } else {
160 // Something really bad happened.
161 PERROR("Cannot get subdevice instance.\n");
162 err = ME_ERRNO_INTERNAL;
165 // Exit device.
166 me_dlock_exit(&device->dlock, filep);
168 return err;
171 static int me_device_io_reset_device(struct me_device *device,
172 struct file *filep, int flags)
174 int err = ME_ERRNO_SUCCESS;
175 me_subdevice_t *s;
176 int i, n;
178 PDEBUG("executed.\n");
180 /* Get the number of subdevices. */
181 n = me_slist_get_number_subdevices(&device->slist);
183 // Enter device.
184 err = me_dlock_enter(&device->dlock, filep);
186 if (err) {
187 PERROR("Cannot enter device.\n");
188 return err;
191 /* Reset every subdevice in list. */
192 for (i = 0; i < n; i++) {
193 s = me_slist_get_subdevice(&device->slist, i);
194 err = s->me_subdevice_io_reset_subdevice(s, filep, flags);
196 if (err) {
197 PERROR("Cannot reset subdevice.\n");
198 break;
202 // Exit device.
203 me_dlock_exit(&device->dlock, filep);
205 return err;
208 static int me_device_io_reset_subdevice(struct me_device *device,
209 struct file *filep,
210 int subdevice, int flags)
212 int err = ME_ERRNO_SUCCESS;
213 me_subdevice_t *s;
215 PDEBUG("executed.\n");
217 // Check subdevice index.
219 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
220 PERROR("Invalid subdevice.\n");
221 return ME_ERRNO_INVALID_SUBDEVICE;
223 // Enter device.
224 err = me_dlock_enter(&device->dlock, filep);
226 if (err) {
227 PERROR("Cannot enter device.\n");
228 return err;
230 // Get subdevice instance.
231 s = me_slist_get_subdevice(&device->slist, subdevice);
233 if (s) {
234 // Call subdevice method.
235 err = s->me_subdevice_io_reset_subdevice(s, filep, flags);
236 } else {
237 // Something really bad happened.
238 PERROR("Cannot get subdevice instance.\n");
239 err = ME_ERRNO_INTERNAL;
242 // Exit device.
243 me_dlock_exit(&device->dlock, filep);
245 return err;
248 static int me_device_io_single_config(struct me_device *device,
249 struct file *filep,
250 int subdevice,
251 int channel,
252 int single_config,
253 int ref,
254 int trig_chan,
255 int trig_type, int trig_edge, int flags)
257 int err = ME_ERRNO_SUCCESS;
258 me_subdevice_t *s;
260 PDEBUG("executed.\n");
262 // Check subdevice index.
264 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
265 PERROR("Invalid subdevice.\n");
266 return ME_ERRNO_INVALID_SUBDEVICE;
268 // Enter device.
269 err = me_dlock_enter(&device->dlock, filep);
271 if (err) {
272 PERROR("Cannot enter device.\n");
273 return err;
275 // Get subdevice instance.
276 s = me_slist_get_subdevice(&device->slist, subdevice);
278 if (s) {
279 // Call subdevice method.
280 err = s->me_subdevice_io_single_config(s,
281 filep,
282 channel,
283 single_config,
284 ref,
285 trig_chan,
286 trig_type,
287 trig_edge, flags);
288 } else {
289 // Something really bad happened.
290 PERROR("Cannot get subdevice instance.\n");
291 err = ME_ERRNO_INTERNAL;
294 // Exit device.
295 me_dlock_exit(&device->dlock, filep);
297 return err;
300 static int me_device_io_single_read(struct me_device *device,
301 struct file *filep,
302 int subdevice,
303 int channel,
304 int *value, int time_out, int flags)
306 int err = ME_ERRNO_SUCCESS;
307 me_subdevice_t *s;
309 PDEBUG("executed.\n");
311 // Check subdevice index.
313 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
314 PERROR("Invalid subdevice.\n");
315 return ME_ERRNO_INVALID_SUBDEVICE;
317 // Enter device.
318 err = me_dlock_enter(&device->dlock, filep);
320 if (err) {
321 PERROR("Cannot enter device.\n");
322 return err;
324 // Get subdevice instance.
325 s = me_slist_get_subdevice(&device->slist, subdevice);
327 if (s) {
328 // Call subdevice method.
329 err = s->me_subdevice_io_single_read(s,
330 filep,
331 channel,
332 value, time_out, flags);
333 } else {
334 // Something really bad happened.
335 PERROR("Cannot get subdevice instance.\n");
336 err = ME_ERRNO_INTERNAL;
339 // Exit device.
340 me_dlock_exit(&device->dlock, filep);
342 return err;
345 static int me_device_io_single_write(struct me_device *device,
346 struct file *filep,
347 int subdevice,
348 int channel,
349 int value, int time_out, int flags)
351 int err = ME_ERRNO_SUCCESS;
352 me_subdevice_t *s;
354 PDEBUG("executed.\n");
356 // Check subdevice index.
358 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
359 PERROR("Invalid subdevice.\n");
360 return ME_ERRNO_INVALID_SUBDEVICE;
362 // Enter device.
363 err = me_dlock_enter(&device->dlock, filep);
365 if (err) {
366 PERROR("Cannot enter device.\n");
367 return err;
369 // Get subdevice instance.
370 s = me_slist_get_subdevice(&device->slist, subdevice);
372 if (s) {
373 // Call subdevice method.
374 err = s->me_subdevice_io_single_write(s,
375 filep,
376 channel,
377 value, time_out, flags);
378 } else {
379 // Something really bad happened.
380 PERROR("Cannot get subdevice instance.\n");
381 err = ME_ERRNO_INTERNAL;
384 // Exit device.
385 me_dlock_exit(&device->dlock, filep);
387 return err;
390 static int me_device_io_stream_config(struct me_device *device,
391 struct file *filep,
392 int subdevice,
393 meIOStreamConfig_t *config_list,
394 int count,
395 meIOStreamTrigger_t *trigger,
396 int fifo_irq_threshold, int flags)
398 int err = ME_ERRNO_SUCCESS;
399 me_subdevice_t *s;
401 PDEBUG("executed.\n");
403 // Check subdevice index.
405 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
406 PERROR("Invalid subdevice.\n");
407 return ME_ERRNO_INVALID_SUBDEVICE;
409 // Enter device.
410 err = me_dlock_enter(&device->dlock, filep);
412 if (err) {
413 PERROR("Cannot enter device.\n");
414 return err;
416 // Get subdevice instance.
417 s = me_slist_get_subdevice(&device->slist, subdevice);
419 if (s) {
420 // Call subdevice method.
421 err = s->me_subdevice_io_stream_config(s,
422 filep,
423 config_list,
424 count,
425 trigger,
426 fifo_irq_threshold,
427 flags);
428 } else {
429 // Something really bad happened.
430 PERROR("Cannot get subdevice instance.\n");
431 err = ME_ERRNO_INTERNAL;
434 // Exit device.
435 me_dlock_exit(&device->dlock, filep);
437 return err;
440 static int me_device_io_stream_new_values(struct me_device *device,
441 struct file *filep,
442 int subdevice,
443 int time_out, int *count, int flags)
445 int err = ME_ERRNO_SUCCESS;
446 me_subdevice_t *s;
448 PDEBUG("executed.\n");
450 // Check subdevice index.
452 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
453 PERROR("Invalid subdevice.\n");
454 return ME_ERRNO_INVALID_SUBDEVICE;
456 // Enter device.
457 err = me_dlock_enter(&device->dlock, filep);
459 if (err) {
460 PERROR("Cannot enter device.\n");
461 return err;
463 // Get subdevice instance.
464 s = me_slist_get_subdevice(&device->slist, subdevice);
466 if (s) {
467 // Call subdevice method.
468 err = s->me_subdevice_io_stream_new_values(s,
469 filep,
470 time_out,
471 count, flags);
472 } else {
473 // Something really bad happened.
474 PERROR("Cannot get subdevice instance.\n");
475 err = ME_ERRNO_INTERNAL;
478 // Exit device.
479 me_dlock_exit(&device->dlock, filep);
481 return err;
484 static int me_device_io_stream_read(struct me_device *device,
485 struct file *filep,
486 int subdevice,
487 int read_mode,
488 int *values, int *count, int flags)
490 int err = ME_ERRNO_SUCCESS;
491 me_subdevice_t *s;
493 PDEBUG("executed.\n");
495 // Check subdevice index.
497 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
498 PERROR("Invalid subdevice.\n");
499 return ME_ERRNO_INVALID_SUBDEVICE;
501 // Enter device.
502 err = me_dlock_enter(&device->dlock, filep);
504 if (err) {
505 PERROR("Cannot enter device.\n");
506 return err;
508 // Get subdevice instance.
509 s = me_slist_get_subdevice(&device->slist, subdevice);
511 if (s) {
512 // Call subdevice method.
513 err = s->me_subdevice_io_stream_read(s,
514 filep,
515 read_mode,
516 values, count, flags);
517 } else {
518 // Something really bad happened.
519 PERROR("Cannot get subdevice instance.\n");
520 err = ME_ERRNO_INTERNAL;
523 // Exit device.
524 me_dlock_exit(&device->dlock, filep);
526 return err;
529 static int me_device_io_stream_start(struct me_device *device,
530 struct file *filep,
531 int subdevice,
532 int start_mode, int time_out, int flags)
534 int err = ME_ERRNO_SUCCESS;
535 me_subdevice_t *s;
537 PDEBUG("executed.\n");
539 // Check subdevice index.
541 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
542 PERROR("Invalid subdevice.\n");
543 return ME_ERRNO_INVALID_SUBDEVICE;
545 // Enter device.
546 err = me_dlock_enter(&device->dlock, filep);
548 if (err) {
549 PERROR("Cannot enter device.\n");
550 return err;
552 // Get subdevice instance.
553 s = me_slist_get_subdevice(&device->slist, subdevice);
555 if (s) {
556 // Call subdevice method.
557 err = s->me_subdevice_io_stream_start(s,
558 filep,
559 start_mode,
560 time_out, flags);
561 } else {
562 // Something really bad happened.
563 PERROR("Cannot get subdevice instance.\n");
564 err = ME_ERRNO_INTERNAL;
567 // Exit device.
568 me_dlock_exit(&device->dlock, filep);
570 return err;
573 static int me_device_io_stream_status(struct me_device *device,
574 struct file *filep,
575 int subdevice,
576 int wait,
577 int *status, int *count, int flags)
579 int err = ME_ERRNO_SUCCESS;
580 me_subdevice_t *s;
582 PDEBUG("executed.\n");
584 // Check subdevice index.
586 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
587 PERROR("Invalid subdevice.\n");
588 return ME_ERRNO_INVALID_SUBDEVICE;
590 // Enter device.
591 err = me_dlock_enter(&device->dlock, filep);
593 if (err) {
594 PERROR("Cannot enter device.\n");
595 return err;
597 // Get subdevice instance.
598 s = me_slist_get_subdevice(&device->slist, subdevice);
600 if (s) {
601 // Call subdevice method.
602 err = s->me_subdevice_io_stream_status(s,
603 filep,
604 wait,
605 status, count, flags);
606 } else {
607 // Something really bad happened.
608 PERROR("Cannot get subdevice instance.\n");
609 err = ME_ERRNO_INTERNAL;
612 // Exit device.
613 me_dlock_exit(&device->dlock, filep);
615 return err;
618 static int me_device_io_stream_stop(struct me_device *device,
619 struct file *filep,
620 int subdevice, int stop_mode, int flags)
622 int err = ME_ERRNO_SUCCESS;
623 me_subdevice_t *s;
625 PDEBUG("executed.\n");
627 // Check subdevice index.
629 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
630 PERROR("Invalid subdevice.\n");
631 return ME_ERRNO_INVALID_SUBDEVICE;
633 // Enter device.
634 err = me_dlock_enter(&device->dlock, filep);
636 if (err) {
637 PERROR("Cannot enter device.\n");
638 return err;
640 // Get subdevice instance.
641 s = me_slist_get_subdevice(&device->slist, subdevice);
643 if (s) {
644 // Call subdevice method.
645 err = s->me_subdevice_io_stream_stop(s,
646 filep, stop_mode, flags);
647 } else {
648 // Something really bad happened.
649 PERROR("Cannot get subdevice instance.\n");
650 err = ME_ERRNO_INTERNAL;
653 // Exit device.
654 me_dlock_exit(&device->dlock, filep);
656 return err;
659 static int me_device_io_stream_write(struct me_device *device,
660 struct file *filep,
661 int subdevice,
662 int write_mode,
663 int *values, int *count, int flags)
665 int err = ME_ERRNO_SUCCESS;
666 me_subdevice_t *s;
668 PDEBUG("executed.\n");
670 // Check subdevice index.
672 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
673 PERROR("Invalid subdevice.\n");
674 return ME_ERRNO_INVALID_SUBDEVICE;
676 // Enter device.
677 err = me_dlock_enter(&device->dlock, filep);
679 if (err) {
680 PERROR("Cannot enter device.\n");
681 return err;
683 // Get subdevice instance.
684 s = me_slist_get_subdevice(&device->slist, subdevice);
686 if (s) {
687 // Call subdevice method.
688 err = s->me_subdevice_io_stream_write(s,
689 filep,
690 write_mode,
691 values, count, flags);
692 } else {
693 // Something really bad happened.
694 PERROR("Cannot get subdevice instance.\n");
695 err = ME_ERRNO_INTERNAL;
698 // Exit device.
699 me_dlock_exit(&device->dlock, filep);
701 return err;
704 static int me_device_lock_device(struct me_device *device,
705 struct file *filep, int lock, int flags)
707 PDEBUG("executed.\n");
709 return me_dlock_lock(&device->dlock,
710 filep, lock, flags, &device->slist);
713 static int me_device_lock_subdevice(struct me_device *device,
714 struct file *filep,
715 int subdevice, int lock, int flags)
717 int err = ME_ERRNO_SUCCESS;
718 me_subdevice_t *s;
720 PDEBUG("executed.\n");
722 // Check subdevice index.
724 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
725 PERROR("Invalid subdevice.\n");
726 return ME_ERRNO_INVALID_SUBDEVICE;
728 // Enter device.
729 err = me_dlock_enter(&device->dlock, filep);
731 if (err) {
732 PERROR("Cannot enter device.\n");
733 return err;
735 // Get subdevice instance.
736 s = me_slist_get_subdevice(&device->slist, subdevice);
738 if (s) {
739 // Call subdevice method.
740 err = s->me_subdevice_lock_subdevice(s, filep, lock, flags);
741 } else {
742 // Something really bad happened.
743 PERROR("Cannot get subdevice instance.\n");
744 err = ME_ERRNO_INTERNAL;
747 // Exit device.
748 me_dlock_exit(&device->dlock, filep);
750 return err;
753 static int me_device_query_description_device(struct me_device *device,
754 char **description)
756 PDEBUG("executed.\n");
757 *description = device->device_description;
758 return ME_ERRNO_SUCCESS;
761 static int me_device_query_info_device(struct me_device *device,
762 int *vendor_id,
763 int *device_id,
764 int *serial_no,
765 int *bus_type,
766 int *bus_no,
767 int *dev_no, int *func_no, int *plugged)
769 PDEBUG("executed.\n");
771 if (device->bus_type == ME_BUS_TYPE_PCI) {
772 *vendor_id = device->info.pci.vendor_id;
773 *device_id = device->info.pci.device_id;
774 *serial_no = device->info.pci.serial_no;
775 *bus_type = ME_BUS_TYPE_PCI;
776 *bus_no = device->info.pci.pci_bus_no;
777 *dev_no = device->info.pci.pci_dev_no;
778 *func_no = device->info.pci.pci_func_no;
779 *plugged = ME_PLUGGED_IN;
780 } else {
781 *plugged = ME_PLUGGED_OUT;
783 return ME_ERRNO_SUCCESS;
786 static int me_device_query_name_device(struct me_device *device, char **name)
788 PDEBUG("executed.\n");
789 *name = device->device_name;
790 return ME_ERRNO_SUCCESS;
793 static int me_device_query_name_device_driver(struct me_device *device,
794 char **name)
796 PDEBUG("executed.\n");
797 *name = device->driver_name;
798 return ME_ERRNO_SUCCESS;
801 static int me_device_query_number_subdevices(struct me_device *device,
802 int *number)
804 PDEBUG("executed.\n");
805 return me_slist_query_number_subdevices(&device->slist, number);
808 static int me_device_query_number_channels(struct me_device *device,
809 int subdevice, int *number)
811 int err = ME_ERRNO_SUCCESS;
812 me_subdevice_t *s;
814 PDEBUG("executed.\n");
816 // Check subdevice index.
818 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
819 PERROR("Invalid subdevice.\n");
820 return ME_ERRNO_INVALID_SUBDEVICE;
822 // Get subdevice instance.
823 s = me_slist_get_subdevice(&device->slist, subdevice);
825 if (s) {
826 // Call subdevice method.
827 err = s->me_subdevice_query_number_channels(s, number);
828 } else {
829 // Something really bad happened.
830 PERROR("Cannot get subdevice instance.\n");
831 err = ME_ERRNO_INTERNAL;
834 return err;
837 static int me_device_query_number_ranges(struct me_device *device,
838 int subdevice, int unit, int *count)
840 int err = ME_ERRNO_SUCCESS;
841 me_subdevice_t *s;
843 PDEBUG("executed.\n");
845 // Check subdevice index.
847 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
848 PERROR("Invalid subdevice.\n");
849 return ME_ERRNO_INVALID_SUBDEVICE;
851 // Get subdevice instance.
852 s = me_slist_get_subdevice(&device->slist, subdevice);
854 if (s) {
855 // Call subdevice method.
856 err = s->me_subdevice_query_number_ranges(s, unit, count);
857 } else {
858 // Something really bad happened.
859 PERROR("Cannot get subdevice instance.\n");
860 err = ME_ERRNO_INTERNAL;
863 return err;
866 static int me_device_query_range_by_min_max(struct me_device *device,
867 int subdevice,
868 int unit,
869 int *min,
870 int *max, int *maxdata, int *range)
872 int err = ME_ERRNO_SUCCESS;
873 me_subdevice_t *s;
875 PDEBUG("executed.\n");
877 // Check subdevice index.
879 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
880 PERROR("Invalid subdevice.\n");
881 return ME_ERRNO_INVALID_SUBDEVICE;
883 // Get subdevice instance.
884 s = me_slist_get_subdevice(&device->slist, subdevice);
886 if (s) {
887 // Call subdevice method.
888 err = s->me_subdevice_query_range_by_min_max(s,
889 unit,
890 min,
891 max,
892 maxdata, range);
893 } else {
894 // Something really bad happened.
895 PERROR("Cannot get subdevice instance.\n");
896 err = ME_ERRNO_INTERNAL;
899 return err;
902 static int me_device_query_range_info(struct me_device *device,
903 int subdevice,
904 int range,
905 int *unit,
906 int *min, int *max, int *maxdata)
908 int err = ME_ERRNO_SUCCESS;
909 me_subdevice_t *s;
911 PDEBUG("executed.\n");
913 // Check subdevice index.
915 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
916 PERROR("Invalid subdevice.\n");
917 return ME_ERRNO_INVALID_SUBDEVICE;
919 // Get subdevice instance.
920 s = me_slist_get_subdevice(&device->slist, subdevice);
922 if (s) {
923 // Call subdevice method.
924 err = s->me_subdevice_query_range_info(s,
925 range,
926 unit, min, max, maxdata);
927 } else {
928 // Something really bad happened.
929 PERROR("Cannot get subdevice instance.\n");
930 err = ME_ERRNO_INTERNAL;
933 return err;
936 static int me_device_query_subdevice_by_type(struct me_device *device,
937 int start_subdevice,
938 int type,
939 int subtype, int *subdevice)
941 PDEBUG("executed.\n");
943 return me_slist_get_subdevice_by_type(&device->slist,
944 start_subdevice,
945 type, subtype, subdevice);
948 static int me_device_query_subdevice_type(struct me_device *device,
949 int subdevice,
950 int *type, int *subtype)
952 int err = ME_ERRNO_SUCCESS;
953 me_subdevice_t *s;
955 PDEBUG("executed.\n");
957 // Check subdevice index.
959 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
960 PERROR("Invalid subdevice.\n");
961 return ME_ERRNO_INVALID_SUBDEVICE;
963 // Get subdevice instance.
964 s = me_slist_get_subdevice(&device->slist, subdevice);
966 if (s) {
967 // Call subdevice method.
968 err = s->me_subdevice_query_subdevice_type(s, type, subtype);
969 } else {
970 // Something really bad happened.
971 PERROR("Cannot get subdevice instance.\n");
972 err = ME_ERRNO_INTERNAL;
975 return err;
978 static int me_device_query_subdevice_caps(struct me_device *device,
979 int subdevice, int *caps)
981 int err = ME_ERRNO_SUCCESS;
982 me_subdevice_t *s;
984 PDEBUG("executed.\n");
986 // Check subdevice index.
988 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
989 PERROR("Invalid subdevice.\n");
990 return ME_ERRNO_INVALID_SUBDEVICE;
992 // Get subdevice instance.
993 s = me_slist_get_subdevice(&device->slist, subdevice);
995 if (s) {
996 // Call subdevice method.
997 err = s->me_subdevice_query_subdevice_caps(s, caps);
998 } else {
999 // Something really bad happened.
1000 PERROR("Cannot get subdevice instance.\n");
1001 err = ME_ERRNO_INTERNAL;
1004 return err;
1007 static int me_device_query_subdevice_caps_args(struct me_device *device,
1008 int subdevice,
1009 int cap, int *args, int count)
1011 int err = ME_ERRNO_SUCCESS;
1012 me_subdevice_t *s;
1014 PDEBUG("executed.\n");
1016 // Check subdevice index.
1018 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
1019 PERROR("Invalid subdevice.\n");
1020 return ME_ERRNO_INVALID_SUBDEVICE;
1022 // Get subdevice instance.
1023 s = me_slist_get_subdevice(&device->slist, subdevice);
1025 if (s) {
1026 // Call subdevice method.
1027 err = s->me_subdevice_query_subdevice_caps_args(s,
1028 cap,
1029 args, count);
1030 } else {
1031 // Something really bad happened.
1032 PERROR("Cannot get subdevice instance.\n");
1033 err = ME_ERRNO_INTERNAL;
1036 return err;
1039 static int me_device_query_timer(struct me_device *device,
1040 int subdevice,
1041 int timer,
1042 int *base_frequency,
1043 uint64_t *min_ticks, uint64_t *max_ticks)
1045 int err = ME_ERRNO_SUCCESS;
1046 me_subdevice_t *s;
1048 PDEBUG("executed.\n");
1050 // Check subdevice index.
1052 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
1053 PERROR("Invalid subdevice.\n");
1054 return ME_ERRNO_INVALID_SUBDEVICE;
1056 // Get subdevice instance.
1057 s = me_slist_get_subdevice(&device->slist, subdevice);
1059 if (s) {
1060 // Call subdevice method.
1061 err = s->me_subdevice_query_timer(s,
1062 timer,
1063 base_frequency,
1064 min_ticks, max_ticks);
1065 } else {
1066 // Something really bad happened.
1067 PERROR("Cannot get subdevice instance.\n");
1068 err = ME_ERRNO_INTERNAL;
1071 return err;
1074 static int me_device_query_version_device_driver(struct me_device *device,
1075 int *version)
1076 /** @todo Versions shold be read from driver. I must overwrite this function in each module. Here should be returned an error!
1079 PDEBUG("executed.\n");
1080 *version = ME_VERSION_DRIVER;
1081 return ME_ERRNO_SUCCESS;
1084 static int me_device_config_load(struct me_device *device, struct file *filep,
1085 me_cfg_device_entry_t *config)
1087 PDEBUG("executed.\n");
1088 return ME_ERRNO_SUCCESS; //If no need for config return success.
1089 // return ME_ERRNO_NOT_SUPPORTED;
1092 static void me_device_destructor(me_device_t *me_device)
1094 PDEBUG("executed.\n");
1095 me_device_deinit(me_device);
1096 kfree(me_device);
1099 /* //me_device_usb_init
1100 int me_device_usb_init(me_device_t *me_device, struct usb_interface *interface)
1102 PDEBUG("executed.\n");
1103 return -1;
1107 static int get_device_descriptions(uint16_t device_id,
1108 char **device_name,
1109 char **device_description,
1110 char **driver_name)
1111 /** @todo This is wrong concept! Static table has too strong limitations!
1112 * 'device_name' and 'driver_name' should be calculated from 'device_id'
1113 * 'device_description' should be read from device or moved to user space and handled by library!
1116 PDEBUG("executed.\n");
1118 switch (device_id) {
1119 case PCI_DEVICE_ID_MEILHAUS_ME1000:
1120 case PCI_DEVICE_ID_MEILHAUS_ME1000_A:
1121 case PCI_DEVICE_ID_MEILHAUS_ME1000_B:
1122 *device_name = ME1000_NAME_DEVICE_ME1000;
1123 *device_description = ME1000_DESCRIPTION_DEVICE_ME1000;
1124 *driver_name = ME1000_NAME_DRIVER;
1125 break;
1127 case PCI_DEVICE_ID_MEILHAUS_ME1400:
1128 *device_name = ME1400_NAME_DEVICE_ME1400;
1129 *device_description = ME1400_DESCRIPTION_DEVICE_ME1400;
1130 *driver_name = ME1400_NAME_DRIVER;
1131 break;
1133 case PCI_DEVICE_ID_MEILHAUS_ME140A:
1134 *device_name = ME1400_NAME_DEVICE_ME1400A;
1135 *device_description = ME1400_DESCRIPTION_DEVICE_ME1400A;
1136 *driver_name = ME1400_NAME_DRIVER;
1137 break;
1139 case PCI_DEVICE_ID_MEILHAUS_ME140B:
1140 *device_name = ME1400_NAME_DEVICE_ME1400B;
1141 *device_description = ME1400_DESCRIPTION_DEVICE_ME1400B;
1142 *driver_name = ME1400_NAME_DRIVER;
1143 break;
1145 case PCI_DEVICE_ID_MEILHAUS_ME14E0:
1146 *device_name = ME1400_NAME_DEVICE_ME1400E;
1147 *device_description = ME1400_DESCRIPTION_DEVICE_ME1400E;
1148 *driver_name = ME1400_NAME_DRIVER;
1149 break;
1151 case PCI_DEVICE_ID_MEILHAUS_ME14EA:
1152 *device_name = ME1400_NAME_DEVICE_ME1400EA;
1153 *device_description = ME1400_DESCRIPTION_DEVICE_ME1400EA;
1154 *driver_name = ME1400_NAME_DRIVER;
1155 break;
1157 case PCI_DEVICE_ID_MEILHAUS_ME14EB:
1158 *device_name = ME1400_NAME_DEVICE_ME1400EB;
1159 *device_description = ME1400_DESCRIPTION_DEVICE_ME1400EB;
1160 *driver_name = ME1400_NAME_DRIVER;
1161 break;
1163 case PCI_DEVICE_ID_MEILHAUS_ME140C:
1164 *device_name = ME1400_NAME_DEVICE_ME1400C;
1165 *device_description = ME1400_DESCRIPTION_DEVICE_ME1400C;
1166 *driver_name = ME1400_NAME_DRIVER;
1167 break;
1169 case PCI_DEVICE_ID_MEILHAUS_ME140D:
1170 *device_name = ME1400_NAME_DEVICE_ME1400D;
1171 *device_description = ME1400_DESCRIPTION_DEVICE_ME1400D;
1172 *driver_name = ME1400_NAME_DRIVER;
1173 break;
1175 case PCI_DEVICE_ID_MEILHAUS_ME1600_4U:
1176 *device_name = ME1600_NAME_DEVICE_ME16004U;
1177 *device_description = ME1600_DESCRIPTION_DEVICE_ME16004U;
1178 *driver_name = ME1600_NAME_DRIVER;
1179 break;
1181 case PCI_DEVICE_ID_MEILHAUS_ME1600_8U:
1182 *device_name = ME1600_NAME_DEVICE_ME16008U;
1183 *device_description = ME1600_DESCRIPTION_DEVICE_ME16008U;
1184 *driver_name = ME1600_NAME_DRIVER;
1185 break;
1187 case PCI_DEVICE_ID_MEILHAUS_ME1600_12U:
1188 *device_name = ME1600_NAME_DEVICE_ME160012U;
1189 *device_description = ME1600_DESCRIPTION_DEVICE_ME160012U;
1190 *driver_name = ME1600_NAME_DRIVER;
1191 break;
1193 case PCI_DEVICE_ID_MEILHAUS_ME1600_16U:
1194 *device_name = ME1600_NAME_DEVICE_ME160016U;
1195 *device_description = ME1600_DESCRIPTION_DEVICE_ME160016U;
1196 *driver_name = ME1600_NAME_DRIVER;
1197 break;
1199 case PCI_DEVICE_ID_MEILHAUS_ME1600_16U_8I:
1200 *device_name = ME1600_NAME_DEVICE_ME160016U8I;
1201 *device_description = ME1600_DESCRIPTION_DEVICE_ME160016U8I;
1202 *driver_name = ME1600_NAME_DRIVER;
1203 break;
1205 case PCI_DEVICE_ID_MEILHAUS_ME4610:
1206 *device_name = ME4600_NAME_DEVICE_ME4610;
1207 *device_description = ME4600_DESCRIPTION_DEVICE_ME4610;
1208 *driver_name = ME4600_NAME_DRIVER;
1209 break;
1211 case PCI_DEVICE_ID_MEILHAUS_ME4650:
1212 *device_name = ME4600_NAME_DEVICE_ME4650;
1213 *device_description = ME4600_DESCRIPTION_DEVICE_ME4650;
1214 *driver_name = ME4600_NAME_DRIVER;
1215 break;
1217 case PCI_DEVICE_ID_MEILHAUS_ME4660:
1218 *device_name = ME4600_NAME_DEVICE_ME4660;
1219 *device_description = ME4600_DESCRIPTION_DEVICE_ME4660;
1220 *driver_name = ME4600_NAME_DRIVER;
1221 break;
1223 case PCI_DEVICE_ID_MEILHAUS_ME4660I:
1224 *device_name = ME4600_NAME_DEVICE_ME4660I;
1225 *device_description = ME4600_DESCRIPTION_DEVICE_ME4660I;
1226 *driver_name = ME4600_NAME_DRIVER;
1227 break;
1229 case PCI_DEVICE_ID_MEILHAUS_ME4660S:
1230 *device_name = ME4600_NAME_DEVICE_ME4660S;
1231 *device_description = ME4600_DESCRIPTION_DEVICE_ME4660S;
1232 *driver_name = ME4600_NAME_DRIVER;
1233 break;
1235 case PCI_DEVICE_ID_MEILHAUS_ME4660IS:
1236 *device_name = ME4600_NAME_DEVICE_ME4660IS;
1237 *device_description = ME4600_DESCRIPTION_DEVICE_ME4660IS;
1238 *driver_name = ME4600_NAME_DRIVER;
1239 break;
1241 case PCI_DEVICE_ID_MEILHAUS_ME4670:
1242 *device_name = ME4600_NAME_DEVICE_ME4670;
1243 *device_description = ME4600_DESCRIPTION_DEVICE_ME4670;
1244 *driver_name = ME4600_NAME_DRIVER;
1245 break;
1247 case PCI_DEVICE_ID_MEILHAUS_ME4670I:
1248 *device_name = ME4600_NAME_DEVICE_ME4670I;
1249 *device_description = ME4600_DESCRIPTION_DEVICE_ME4670I;
1250 *driver_name = ME4600_NAME_DRIVER;
1251 break;
1253 case PCI_DEVICE_ID_MEILHAUS_ME4670S:
1254 *device_name = ME4600_NAME_DEVICE_ME4670S;
1255 *device_description = ME4600_DESCRIPTION_DEVICE_ME4670S;
1256 *driver_name = ME4600_NAME_DRIVER;
1257 break;
1259 case PCI_DEVICE_ID_MEILHAUS_ME4670IS:
1260 *device_name = ME4600_NAME_DEVICE_ME4670IS;
1261 *device_description = ME4600_DESCRIPTION_DEVICE_ME4670IS;
1262 *driver_name = ME4600_NAME_DRIVER;
1263 break;
1265 case PCI_DEVICE_ID_MEILHAUS_ME4680:
1266 *device_name = ME4600_NAME_DEVICE_ME4680;
1267 *device_description = ME4600_DESCRIPTION_DEVICE_ME4680;
1268 *driver_name = ME4600_NAME_DRIVER;
1269 break;
1271 case PCI_DEVICE_ID_MEILHAUS_ME4680I:
1272 *device_name = ME4600_NAME_DEVICE_ME4680I;
1273 *device_description = ME4600_DESCRIPTION_DEVICE_ME4680I;
1274 *driver_name = ME4600_NAME_DRIVER;
1275 break;
1277 case PCI_DEVICE_ID_MEILHAUS_ME4680S:
1278 *device_name = ME4600_NAME_DEVICE_ME4680S;
1279 *device_description = ME4600_DESCRIPTION_DEVICE_ME4680S;
1280 *driver_name = ME4600_NAME_DRIVER;
1281 break;
1283 case PCI_DEVICE_ID_MEILHAUS_ME4680IS:
1284 *device_name = ME4600_NAME_DEVICE_ME4680IS;
1285 *device_description = ME4600_DESCRIPTION_DEVICE_ME4680IS;
1286 *driver_name = ME4600_NAME_DRIVER;
1287 break;
1289 case PCI_DEVICE_ID_MEILHAUS_ME6004:
1290 *device_name = ME6000_NAME_DEVICE_ME60004;
1291 *device_description = ME6000_DESCRIPTION_DEVICE_ME60004;
1292 *driver_name = ME6000_NAME_DRIVER;
1293 break;
1295 case PCI_DEVICE_ID_MEILHAUS_ME6008:
1296 *device_name = ME6000_NAME_DEVICE_ME60008;
1297 *device_description = ME6000_DESCRIPTION_DEVICE_ME60008;
1298 *driver_name = ME6000_NAME_DRIVER;
1299 break;
1301 case PCI_DEVICE_ID_MEILHAUS_ME600F:
1302 *device_name = ME6000_NAME_DEVICE_ME600016;
1303 *device_description = ME6000_DESCRIPTION_DEVICE_ME600016;
1304 *driver_name = ME6000_NAME_DRIVER;
1305 break;
1307 case PCI_DEVICE_ID_MEILHAUS_ME6014:
1308 *device_name = ME6000_NAME_DEVICE_ME6000I4;
1309 *device_description = ME6000_DESCRIPTION_DEVICE_ME6000I4;
1310 *driver_name = ME6000_NAME_DRIVER;
1311 break;
1313 case PCI_DEVICE_ID_MEILHAUS_ME6018:
1314 *device_name = ME6000_NAME_DEVICE_ME6000I8;
1315 *device_description = ME6000_DESCRIPTION_DEVICE_ME6000I8;
1316 *driver_name = ME6000_NAME_DRIVER;
1317 break;
1319 case PCI_DEVICE_ID_MEILHAUS_ME601F:
1320 *device_name = ME6000_NAME_DEVICE_ME6000I16;
1321 *device_description = ME6000_DESCRIPTION_DEVICE_ME6000I16;
1322 *driver_name = ME6000_NAME_DRIVER;
1323 break;
1325 case PCI_DEVICE_ID_MEILHAUS_ME6034:
1326 *device_name = ME6000_NAME_DEVICE_ME6000ISLE4;
1327 *device_description = ME6000_DESCRIPTION_DEVICE_ME6000ISLE4;
1328 *driver_name = ME6000_NAME_DRIVER;
1329 break;
1331 case PCI_DEVICE_ID_MEILHAUS_ME6038:
1332 *device_name = ME6000_NAME_DEVICE_ME6000ISLE8;
1333 *device_description = ME6000_DESCRIPTION_DEVICE_ME6000ISLE8;
1334 *driver_name = ME6000_NAME_DRIVER;
1335 break;
1337 case PCI_DEVICE_ID_MEILHAUS_ME603F:
1338 *device_name = ME6000_NAME_DEVICE_ME6000ISLE16;
1339 *device_description = ME6000_DESCRIPTION_DEVICE_ME6000ISLE16;
1340 *driver_name = ME6000_NAME_DRIVER;
1341 break;
1343 case PCI_DEVICE_ID_MEILHAUS_ME6104:
1344 *device_name = ME6000_NAME_DEVICE_ME61004;
1345 *device_description = ME6000_DESCRIPTION_DEVICE_ME61004;
1346 *driver_name = ME6000_NAME_DRIVER;
1347 break;
1349 case PCI_DEVICE_ID_MEILHAUS_ME6108:
1350 *device_name = ME6000_NAME_DEVICE_ME61008;
1351 *device_description = ME6000_DESCRIPTION_DEVICE_ME61008;
1352 *driver_name = ME6000_NAME_DRIVER;
1353 break;
1355 case PCI_DEVICE_ID_MEILHAUS_ME610F:
1356 *device_name = ME6000_NAME_DEVICE_ME610016;
1357 *device_description = ME6000_DESCRIPTION_DEVICE_ME610016;
1358 *driver_name = ME6000_NAME_DRIVER;
1359 break;
1361 case PCI_DEVICE_ID_MEILHAUS_ME6114:
1362 *device_name = ME6000_NAME_DEVICE_ME6100I4;
1363 *device_description = ME6000_DESCRIPTION_DEVICE_ME6100I4;
1364 *driver_name = ME6000_NAME_DRIVER;
1365 break;
1367 case PCI_DEVICE_ID_MEILHAUS_ME6118:
1368 *device_name = ME6000_NAME_DEVICE_ME6100I8;
1369 *device_description = ME6000_DESCRIPTION_DEVICE_ME6100I8;
1370 *driver_name = ME6000_NAME_DRIVER;
1371 break;
1373 case PCI_DEVICE_ID_MEILHAUS_ME611F:
1374 *device_name = ME6000_NAME_DEVICE_ME6100I16;
1375 *device_description = ME6000_DESCRIPTION_DEVICE_ME6100I16;
1376 *driver_name = ME6000_NAME_DRIVER;
1377 break;
1379 case PCI_DEVICE_ID_MEILHAUS_ME6134:
1380 *device_name = ME6000_NAME_DEVICE_ME6100ISLE4;
1381 *device_description = ME6000_DESCRIPTION_DEVICE_ME6100ISLE4;
1382 *driver_name = ME6000_NAME_DRIVER;
1383 break;
1385 case PCI_DEVICE_ID_MEILHAUS_ME6138:
1386 *device_name = ME6000_NAME_DEVICE_ME6100ISLE8;
1387 *device_description = ME6000_DESCRIPTION_DEVICE_ME6100ISLE8;
1388 *driver_name = ME6000_NAME_DRIVER;
1389 break;
1391 case PCI_DEVICE_ID_MEILHAUS_ME613F:
1392 *device_name = ME6000_NAME_DEVICE_ME6100ISLE16;
1393 *device_description = ME6000_DESCRIPTION_DEVICE_ME6100ISLE16;
1394 *driver_name = ME6000_NAME_DRIVER;
1395 break;
1397 case PCI_DEVICE_ID_MEILHAUS_ME6044:
1398 *device_name = ME6000_NAME_DEVICE_ME60004DIO;
1399 *device_description = ME6000_DESCRIPTION_DEVICE_ME60004DIO;
1400 *driver_name = ME6000_NAME_DRIVER;
1401 break;
1403 case PCI_DEVICE_ID_MEILHAUS_ME6048:
1404 *device_name = ME6000_NAME_DEVICE_ME60008DIO;
1405 *device_description = ME6000_DESCRIPTION_DEVICE_ME60008DIO;
1406 *driver_name = ME6000_NAME_DRIVER;
1407 break;
1409 case PCI_DEVICE_ID_MEILHAUS_ME604F:
1410 *device_name = ME6000_NAME_DEVICE_ME600016DIO;
1411 *device_description = ME6000_DESCRIPTION_DEVICE_ME600016DIO;
1412 *driver_name = ME6000_NAME_DRIVER;
1413 break;
1415 case PCI_DEVICE_ID_MEILHAUS_ME6054:
1416 *device_name = ME6000_NAME_DEVICE_ME6000I4DIO;
1417 *device_description = ME6000_DESCRIPTION_DEVICE_ME6000I4DIO;
1418 *driver_name = ME6000_NAME_DRIVER;
1419 break;
1421 case PCI_DEVICE_ID_MEILHAUS_ME6058:
1422 *device_name = ME6000_NAME_DEVICE_ME6000I8DIO;
1423 *device_description = ME6000_DESCRIPTION_DEVICE_ME6000I8DIO;
1424 *driver_name = ME6000_NAME_DRIVER;
1425 break;
1427 case PCI_DEVICE_ID_MEILHAUS_ME605F:
1428 *device_name = ME6000_NAME_DEVICE_ME6000I16DIO;
1429 *device_description = ME6000_DESCRIPTION_DEVICE_ME6000I16DIO;
1430 *driver_name = ME6000_NAME_DRIVER;
1431 break;
1433 case PCI_DEVICE_ID_MEILHAUS_ME6074:
1434 *device_name = ME6000_NAME_DEVICE_ME6000ISLE4DIO;
1435 *device_description = ME6000_DESCRIPTION_DEVICE_ME6000ISLE4DIO;
1436 *driver_name = ME6000_NAME_DRIVER;
1437 break;
1439 case PCI_DEVICE_ID_MEILHAUS_ME6078:
1440 *device_name = ME6000_NAME_DEVICE_ME6000ISLE8DIO;
1441 *device_description = ME6000_DESCRIPTION_DEVICE_ME6000ISLE8DIO;
1442 *driver_name = ME6000_NAME_DRIVER;
1443 break;
1445 case PCI_DEVICE_ID_MEILHAUS_ME607F:
1446 *device_name = ME6000_NAME_DEVICE_ME6000ISLE16DIO;
1447 *device_description = ME6000_DESCRIPTION_DEVICE_ME6000ISLE16DIO;
1448 *driver_name = ME6000_NAME_DRIVER;
1449 break;
1451 case PCI_DEVICE_ID_MEILHAUS_ME6144:
1452 *device_name = ME6000_NAME_DEVICE_ME61004DIO;
1453 *device_description = ME6000_DESCRIPTION_DEVICE_ME61004DIO;
1454 *driver_name = ME6000_NAME_DRIVER;
1455 break;
1457 case PCI_DEVICE_ID_MEILHAUS_ME6148:
1458 *device_name = ME6000_NAME_DEVICE_ME61008DIO;
1459 *device_description = ME6000_DESCRIPTION_DEVICE_ME61008DIO;
1460 *driver_name = ME6000_NAME_DRIVER;
1461 break;
1463 case PCI_DEVICE_ID_MEILHAUS_ME614F:
1464 *device_name = ME6000_NAME_DEVICE_ME610016DIO;
1465 *device_description = ME6000_DESCRIPTION_DEVICE_ME610016DIO;
1466 *driver_name = ME6000_NAME_DRIVER;
1467 break;
1469 case PCI_DEVICE_ID_MEILHAUS_ME6154:
1470 *device_name = ME6000_NAME_DEVICE_ME6100I4DIO;
1471 *device_description = ME6000_DESCRIPTION_DEVICE_ME6100I4DIO;
1472 *driver_name = ME6000_NAME_DRIVER;
1473 break;
1475 case PCI_DEVICE_ID_MEILHAUS_ME6158:
1476 *device_name = ME6000_NAME_DEVICE_ME6100I8DIO;
1477 *device_description = ME6000_DESCRIPTION_DEVICE_ME6100I8DIO;
1478 *driver_name = ME6000_NAME_DRIVER;
1479 break;
1481 case PCI_DEVICE_ID_MEILHAUS_ME615F:
1482 *device_name = ME6000_NAME_DEVICE_ME6100I16DIO;
1483 *device_description = ME6000_DESCRIPTION_DEVICE_ME6100I16DIO;
1484 *driver_name = ME6000_NAME_DRIVER;
1485 break;
1487 case PCI_DEVICE_ID_MEILHAUS_ME6174:
1488 *device_name = ME6000_NAME_DEVICE_ME6100ISLE4DIO;
1489 *device_description = ME6000_DESCRIPTION_DEVICE_ME6100ISLE4DIO;
1490 *driver_name = ME6000_NAME_DRIVER;
1491 break;
1493 case PCI_DEVICE_ID_MEILHAUS_ME6178:
1494 *device_name = ME6000_NAME_DEVICE_ME6100ISLE8DIO;
1495 *device_description = ME6000_DESCRIPTION_DEVICE_ME6100ISLE8DIO;
1496 *driver_name = ME6000_NAME_DRIVER;
1497 break;
1499 case PCI_DEVICE_ID_MEILHAUS_ME617F:
1500 *device_name = ME6000_NAME_DEVICE_ME6100ISLE16DIO;
1501 *device_description = ME6000_DESCRIPTION_DEVICE_ME6100ISLE16DIO;
1502 *driver_name = ME6000_NAME_DRIVER;
1503 break;
1505 case PCI_DEVICE_ID_MEILHAUS_ME6259:
1506 *device_name = ME6000_NAME_DEVICE_ME6200I9DIO;
1507 *device_description = ME6000_DESCRIPTION_DEVICE_ME6200I9DIO;
1508 *driver_name = ME6000_NAME_DRIVER;
1509 break;
1511 case PCI_DEVICE_ID_MEILHAUS_ME6359:
1512 *device_name = ME6000_NAME_DEVICE_ME6300I9DIO;
1513 *device_description = ME6000_DESCRIPTION_DEVICE_ME6300I9DIO;
1514 *driver_name = ME6000_NAME_DRIVER;
1515 break;
1517 case PCI_DEVICE_ID_MEILHAUS_ME0630:
1518 *device_name = ME0600_NAME_DEVICE_ME0630;
1519 *device_description = ME0600_DESCRIPTION_DEVICE_ME0630;
1520 *driver_name = ME0600_NAME_DRIVER;
1521 break;
1523 case PCI_DEVICE_ID_MEILHAUS_ME8100_A:
1524 *device_name = ME8100_NAME_DEVICE_ME8100A;
1525 *device_description = ME8100_DESCRIPTION_DEVICE_ME8100A;
1526 *driver_name = ME8100_NAME_DRIVER;
1527 break;
1529 case PCI_DEVICE_ID_MEILHAUS_ME8100_B:
1530 *device_name = ME8100_NAME_DEVICE_ME8100B;
1531 *device_description = ME8100_DESCRIPTION_DEVICE_ME8100B;
1532 *driver_name = ME8100_NAME_DRIVER;
1533 break;
1535 case PCI_DEVICE_ID_MEILHAUS_ME8200_A:
1536 *device_name = ME8200_NAME_DEVICE_ME8200A;
1537 *device_description = ME8200_DESCRIPTION_DEVICE_ME8200A;
1538 *driver_name = ME8200_NAME_DRIVER;
1539 break;
1541 case PCI_DEVICE_ID_MEILHAUS_ME8200_B:
1542 *device_name = ME8200_NAME_DEVICE_ME8200B;
1543 *device_description = ME8200_DESCRIPTION_DEVICE_ME8200B;
1544 *driver_name = ME8200_NAME_DRIVER;
1545 break;
1547 case PCI_DEVICE_ID_MEILHAUS_ME0940:
1548 *device_name = ME0900_NAME_DEVICE_ME0940;
1549 *device_description = ME0900_DESCRIPTION_DEVICE_ME0940;
1550 *driver_name = ME0900_NAME_DRIVER;
1551 break;
1553 case PCI_DEVICE_ID_MEILHAUS_ME0950:
1554 *device_name = ME0900_NAME_DEVICE_ME0950;
1555 *device_description = ME0900_DESCRIPTION_DEVICE_ME0950;
1556 *driver_name = ME0900_NAME_DRIVER;
1557 break;
1559 case PCI_DEVICE_ID_MEILHAUS_ME0960:
1560 *device_name = ME0900_NAME_DEVICE_ME0960;
1561 *device_description = ME0900_DESCRIPTION_DEVICE_ME0960;
1562 *driver_name = ME0900_NAME_DRIVER;
1563 break;
1565 case USB_DEVICE_ID_MEPHISTO_S1:
1566 *device_name = MEPHISTO_S1_NAME_DEVICE;
1567 *device_description = MEPHISTO_S1_DESCRIPTION_DEVICE;
1568 *driver_name = MEPHISTO_S1_NAME_DRIVER;
1569 break;
1571 default:
1572 *device_name = EMPTY_NAME_DEVICE;
1573 *device_description = EMPTY_DESCRIPTION_DEVICE;
1574 *driver_name = EMPTY_NAME_DRIVER;
1576 PERROR("Invalid device id.\n");
1578 return 1;
1581 return 0;
1584 int me_device_pci_init(me_device_t *me_device, struct pci_dev *pci_device)
1586 int err;
1587 int i;
1589 PDEBUG("executed.\n");
1591 // Initialize device list head.
1592 INIT_LIST_HEAD(&me_device->list);
1594 // Initialize device description strings.
1595 err = get_device_descriptions(pci_device->device,
1596 &me_device->device_name,
1597 &me_device->device_description,
1598 &me_device->driver_name);
1600 if (err) {
1601 PERROR("Cannot initialize device description strings.\n");
1602 return 1;
1604 // Enable the pci device.
1605 err = pci_enable_device(pci_device);
1607 if (err < 0) {
1608 PERROR("Cannot enable PCI device.\n");
1609 return 1;
1611 // Request the PCI register regions.
1612 err = pci_request_regions(pci_device, me_device->device_name);
1614 if (err < 0) {
1615 PERROR("Cannot request PCI regions.\n");
1616 goto ERROR_0;
1618 // The bus carrying the device is a PCI bus.
1619 me_device->bus_type = ME_BUS_TYPE_PCI;
1621 // Store the PCI information for later usage.
1622 me_device->info.pci.pci_device = pci_device;
1624 // Get PCI register bases and sizes.
1625 for (i = 0; i < 6; i++) {
1626 me_device->info.pci.reg_bases[i] =
1627 pci_resource_start(pci_device, i);
1628 me_device->info.pci.reg_sizes[i] =
1629 pci_resource_len(pci_device, i);
1632 // Get the PCI location.
1633 me_device->info.pci.pci_bus_no = pci_device->bus->number;
1634 me_device->info.pci.pci_dev_no = PCI_SLOT(pci_device->devfn);
1635 me_device->info.pci.pci_func_no = PCI_FUNC(pci_device->devfn);
1637 // Get Meilhaus specific device information.
1638 me_device->info.pci.vendor_id = pci_device->vendor;
1639 me_device->info.pci.device_id = pci_device->device;
1640 pci_read_config_byte(pci_device, 0x08,
1641 &me_device->info.pci.hw_revision);
1642 pci_read_config_dword(pci_device, 0x2C, &me_device->info.pci.serial_no);
1644 // Get the interrupt request number.
1645 me_device->irq = pci_device->irq;
1647 // Initialize device lock instance.
1648 err = me_dlock_init(&me_device->dlock);
1650 if (err) {
1651 PERROR("Cannot initialize device lock instance.\n");
1652 goto ERROR_1;
1654 // Initialize subdevice list instance.
1655 me_slist_init(&me_device->slist);
1657 if (err) {
1658 PERROR("Cannot initialize subdevice list instance.\n");
1659 goto ERROR_2;
1661 // Initialize method pointers.
1662 me_device->me_device_io_irq_start = me_device_io_irq_start;
1663 me_device->me_device_io_irq_wait = me_device_io_irq_wait;
1664 me_device->me_device_io_irq_stop = me_device_io_irq_stop;
1665 me_device->me_device_io_reset_device = me_device_io_reset_device;
1666 me_device->me_device_io_reset_subdevice = me_device_io_reset_subdevice;
1667 me_device->me_device_io_single_config = me_device_io_single_config;
1668 me_device->me_device_io_single_read = me_device_io_single_read;
1669 me_device->me_device_io_single_write = me_device_io_single_write;
1670 me_device->me_device_io_stream_config = me_device_io_stream_config;
1671 me_device->me_device_io_stream_new_values =
1672 me_device_io_stream_new_values;
1673 me_device->me_device_io_stream_read = me_device_io_stream_read;
1674 me_device->me_device_io_stream_start = me_device_io_stream_start;
1675 me_device->me_device_io_stream_status = me_device_io_stream_status;
1676 me_device->me_device_io_stream_stop = me_device_io_stream_stop;
1677 me_device->me_device_io_stream_write = me_device_io_stream_write;
1678 me_device->me_device_lock_device = me_device_lock_device;
1679 me_device->me_device_lock_subdevice = me_device_lock_subdevice;
1680 me_device->me_device_query_description_device =
1681 me_device_query_description_device;
1682 me_device->me_device_query_info_device = me_device_query_info_device;
1683 me_device->me_device_query_name_device = me_device_query_name_device;
1684 me_device->me_device_query_name_device_driver =
1685 me_device_query_name_device_driver;
1686 me_device->me_device_query_number_subdevices =
1687 me_device_query_number_subdevices;
1688 me_device->me_device_query_number_channels =
1689 me_device_query_number_channels;
1690 me_device->me_device_query_number_ranges =
1691 me_device_query_number_ranges;
1692 me_device->me_device_query_range_by_min_max =
1693 me_device_query_range_by_min_max;
1694 me_device->me_device_query_range_info = me_device_query_range_info;
1695 me_device->me_device_query_subdevice_by_type =
1696 me_device_query_subdevice_by_type;
1697 me_device->me_device_query_subdevice_type =
1698 me_device_query_subdevice_type;
1699 me_device->me_device_query_subdevice_caps =
1700 me_device_query_subdevice_caps;
1701 me_device->me_device_query_subdevice_caps_args =
1702 me_device_query_subdevice_caps_args;
1703 me_device->me_device_query_timer = me_device_query_timer;
1704 me_device->me_device_query_version_device_driver =
1705 me_device_query_version_device_driver;
1706 me_device->me_device_config_load = me_device_config_load;
1707 me_device->me_device_destructor = me_device_destructor;
1709 return 0;
1711 ERROR_0:
1712 me_dlock_deinit(&me_device->dlock);
1714 ERROR_1:
1715 pci_release_regions(pci_device);
1717 ERROR_2:
1718 pci_disable_device(pci_device);
1720 return 1;
1723 void me_device_deinit(me_device_t *me_device)
1725 PDEBUG("executed.\n");
1727 me_slist_deinit(&me_device->slist);
1728 me_dlock_deinit(&me_device->dlock);
1730 if (me_device->bus_type == ME_BUS_TYPE_PCI) {
1731 pci_release_regions(me_device->info.pci.pci_device);
1732 pci_disable_device(me_device->info.pci.pci_device);
1735 else
1737 // Must be an USB device.