1 /**
2 * @file medevice.c
3 *
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 */
9
10 /*
11 * Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de)
12 *
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.
17 *
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.
22 *
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.
26 */
27
28 #include "mecommon.h"
29 #include "meinternal.h"
30 #include "medefines.h"
31 #include "meerror.h"
32
33 #include "medebug.h"
34 #include "medevice.h"
35
36 #ifndef __KERNEL__
37 # define __KERNEL__
38 #endif
39
me_device_io_irq_start(struct me_device * device,struct file * filep,int subdevice,int channel,int irq_source,int irq_edge,int irq_arg,int flags)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)
46 {
47 int err = ME_ERRNO_SUCCESS;
48 me_subdevice_t *s;
49
50 PDEBUG("executed.\n");
51
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;
56 }
57 // Enter device.
58 err = me_dlock_enter(&device->dlock, filep);
59
60 if (err) {
61 PERROR("Cannot enter device.\n");
62 return err;
63 }
64 // Get subdevice instance.
65 s = me_slist_get_subdevice(&device->slist, subdevice);
66
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;
78 }
79
80 // Exit device.
81 me_dlock_exit(&device->dlock, filep);
82
83 return err;
84 }
85
me_device_io_irq_wait(struct me_device * device,struct file * filep,int subdevice,int channel,int * irq_count,int * value,int time_out,int flags)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)
92 {
93 int err = ME_ERRNO_SUCCESS;
94 me_subdevice_t *s;
95
96 PDEBUG("executed.\n");
97
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;
102 }
103 // Enter device.
104 err = me_dlock_enter(&device->dlock, filep);
105
106 if (err) {
107 PERROR("Cannot enter device.\n");
108 return err;
109 }
110 // Get subdevice instance.
111 s = me_slist_get_subdevice(&device->slist, subdevice);
112
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;
124 }
125
126 // Exit device.
127 me_dlock_exit(&device->dlock, filep);
128
129 return err;
130 }
131
me_device_io_irq_stop(struct me_device * device,struct file * filep,int subdevice,int channel,int flags)132 static int me_device_io_irq_stop(struct me_device *device,
133 struct file *filep,
134 int subdevice, int channel, int flags)
135 {
136 int err = ME_ERRNO_SUCCESS;
137 me_subdevice_t *s;
138
139 PDEBUG("executed.\n");
140
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;
145 }
146 // Enter device.
147 err = me_dlock_enter(&device->dlock, filep);
148
149 if (err) {
150 PERROR("Cannot enter device.\n");
151 return err;
152 }
153 // Get subdevice instance.
154 s = me_slist_get_subdevice(&device->slist, subdevice);
155
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;
163 }
164
165 // Exit device.
166 me_dlock_exit(&device->dlock, filep);
167
168 return err;
169 }
170
me_device_io_reset_device(struct me_device * device,struct file * filep,int flags)171 static int me_device_io_reset_device(struct me_device *device,
172 struct file *filep, int flags)
173 {
174 int err = ME_ERRNO_SUCCESS;
175 me_subdevice_t *s;
176 int i, n;
177
178 PDEBUG("executed.\n");
179
180 /* Get the number of subdevices. */
181 n = me_slist_get_number_subdevices(&device->slist);
182
183 // Enter device.
184 err = me_dlock_enter(&device->dlock, filep);
185
186 if (err) {
187 PERROR("Cannot enter device.\n");
188 return err;
189 }
190
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);
195
196 if (err) {
197 PERROR("Cannot reset subdevice.\n");
198 break;
199 }
200 }
201
202 // Exit device.
203 me_dlock_exit(&device->dlock, filep);
204
205 return err;
206 }
207
me_device_io_reset_subdevice(struct me_device * device,struct file * filep,int subdevice,int flags)208 static int me_device_io_reset_subdevice(struct me_device *device,
209 struct file *filep,
210 int subdevice, int flags)
211 {
212 int err = ME_ERRNO_SUCCESS;
213 me_subdevice_t *s;
214
215 PDEBUG("executed.\n");
216
217 // Check subdevice index.
218
219 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
220 PERROR("Invalid subdevice.\n");
221 return ME_ERRNO_INVALID_SUBDEVICE;
222 }
223 // Enter device.
224 err = me_dlock_enter(&device->dlock, filep);
225
226 if (err) {
227 PERROR("Cannot enter device.\n");
228 return err;
229 }
230 // Get subdevice instance.
231 s = me_slist_get_subdevice(&device->slist, subdevice);
232
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;
240 }
241
242 // Exit device.
243 me_dlock_exit(&device->dlock, filep);
244
245 return err;
246 }
247
me_device_io_single_config(struct me_device * device,struct file * filep,int subdevice,int channel,int single_config,int ref,int trig_chan,int trig_type,int trig_edge,int flags)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)
256 {
257 int err = ME_ERRNO_SUCCESS;
258 me_subdevice_t *s;
259
260 PDEBUG("executed.\n");
261
262 // Check subdevice index.
263
264 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
265 PERROR("Invalid subdevice.\n");
266 return ME_ERRNO_INVALID_SUBDEVICE;
267 }
268 // Enter device.
269 err = me_dlock_enter(&device->dlock, filep);
270
271 if (err) {
272 PERROR("Cannot enter device.\n");
273 return err;
274 }
275 // Get subdevice instance.
276 s = me_slist_get_subdevice(&device->slist, subdevice);
277
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;
292 }
293
294 // Exit device.
295 me_dlock_exit(&device->dlock, filep);
296
297 return err;
298 }
299
me_device_io_single_read(struct me_device * device,struct file * filep,int subdevice,int channel,int * value,int time_out,int flags)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)
305 {
306 int err = ME_ERRNO_SUCCESS;
307 me_subdevice_t *s;
308
309 PDEBUG("executed.\n");
310
311 // Check subdevice index.
312
313 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
314 PERROR("Invalid subdevice.\n");
315 return ME_ERRNO_INVALID_SUBDEVICE;
316 }
317 // Enter device.
318 err = me_dlock_enter(&device->dlock, filep);
319
320 if (err) {
321 PERROR("Cannot enter device.\n");
322 return err;
323 }
324 // Get subdevice instance.
325 s = me_slist_get_subdevice(&device->slist, subdevice);
326
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;
337 }
338
339 // Exit device.
340 me_dlock_exit(&device->dlock, filep);
341
342 return err;
343 }
344
me_device_io_single_write(struct me_device * device,struct file * filep,int subdevice,int channel,int value,int time_out,int flags)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)
350 {
351 int err = ME_ERRNO_SUCCESS;
352 me_subdevice_t *s;
353
354 PDEBUG("executed.\n");
355
356 // Check subdevice index.
357
358 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
359 PERROR("Invalid subdevice.\n");
360 return ME_ERRNO_INVALID_SUBDEVICE;
361 }
362 // Enter device.
363 err = me_dlock_enter(&device->dlock, filep);
364
365 if (err) {
366 PERROR("Cannot enter device.\n");
367 return err;
368 }
369 // Get subdevice instance.
370 s = me_slist_get_subdevice(&device->slist, subdevice);
371
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;
382 }
383
384 // Exit device.
385 me_dlock_exit(&device->dlock, filep);
386
387 return err;
388 }
389
me_device_io_stream_config(struct me_device * device,struct file * filep,int subdevice,meIOStreamConfig_t * config_list,int count,meIOStreamTrigger_t * trigger,int fifo_irq_threshold,int flags)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)
397 {
398 int err = ME_ERRNO_SUCCESS;
399 me_subdevice_t *s;
400
401 PDEBUG("executed.\n");
402
403 // Check subdevice index.
404
405 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
406 PERROR("Invalid subdevice.\n");
407 return ME_ERRNO_INVALID_SUBDEVICE;
408 }
409 // Enter device.
410 err = me_dlock_enter(&device->dlock, filep);
411
412 if (err) {
413 PERROR("Cannot enter device.\n");
414 return err;
415 }
416 // Get subdevice instance.
417 s = me_slist_get_subdevice(&device->slist, subdevice);
418
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;
432 }
433
434 // Exit device.
435 me_dlock_exit(&device->dlock, filep);
436
437 return err;
438 }
439
me_device_io_stream_new_values(struct me_device * device,struct file * filep,int subdevice,int time_out,int * count,int flags)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)
444 {
445 int err = ME_ERRNO_SUCCESS;
446 me_subdevice_t *s;
447
448 PDEBUG("executed.\n");
449
450 // Check subdevice index.
451
452 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
453 PERROR("Invalid subdevice.\n");
454 return ME_ERRNO_INVALID_SUBDEVICE;
455 }
456 // Enter device.
457 err = me_dlock_enter(&device->dlock, filep);
458
459 if (err) {
460 PERROR("Cannot enter device.\n");
461 return err;
462 }
463 // Get subdevice instance.
464 s = me_slist_get_subdevice(&device->slist, subdevice);
465
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;
476 }
477
478 // Exit device.
479 me_dlock_exit(&device->dlock, filep);
480
481 return err;
482 }
483
me_device_io_stream_read(struct me_device * device,struct file * filep,int subdevice,int read_mode,int * values,int * count,int flags)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)
489 {
490 int err = ME_ERRNO_SUCCESS;
491 me_subdevice_t *s;
492
493 PDEBUG("executed.\n");
494
495 // Check subdevice index.
496
497 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
498 PERROR("Invalid subdevice.\n");
499 return ME_ERRNO_INVALID_SUBDEVICE;
500 }
501 // Enter device.
502 err = me_dlock_enter(&device->dlock, filep);
503
504 if (err) {
505 PERROR("Cannot enter device.\n");
506 return err;
507 }
508 // Get subdevice instance.
509 s = me_slist_get_subdevice(&device->slist, subdevice);
510
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;
521 }
522
523 // Exit device.
524 me_dlock_exit(&device->dlock, filep);
525
526 return err;
527 }
528
me_device_io_stream_start(struct me_device * device,struct file * filep,int subdevice,int start_mode,int time_out,int flags)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)
533 {
534 int err = ME_ERRNO_SUCCESS;
535 me_subdevice_t *s;
536
537 PDEBUG("executed.\n");
538
539 // Check subdevice index.
540
541 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
542 PERROR("Invalid subdevice.\n");
543 return ME_ERRNO_INVALID_SUBDEVICE;
544 }
545 // Enter device.
546 err = me_dlock_enter(&device->dlock, filep);
547
548 if (err) {
549 PERROR("Cannot enter device.\n");
550 return err;
551 }
552 // Get subdevice instance.
553 s = me_slist_get_subdevice(&device->slist, subdevice);
554
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;
565 }
566
567 // Exit device.
568 me_dlock_exit(&device->dlock, filep);
569
570 return err;
571 }
572
me_device_io_stream_status(struct me_device * device,struct file * filep,int subdevice,int wait,int * status,int * count,int flags)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)
578 {
579 int err = ME_ERRNO_SUCCESS;
580 me_subdevice_t *s;
581
582 PDEBUG("executed.\n");
583
584 // Check subdevice index.
585
586 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
587 PERROR("Invalid subdevice.\n");
588 return ME_ERRNO_INVALID_SUBDEVICE;
589 }
590 // Enter device.
591 err = me_dlock_enter(&device->dlock, filep);
592
593 if (err) {
594 PERROR("Cannot enter device.\n");
595 return err;
596 }
597 // Get subdevice instance.
598 s = me_slist_get_subdevice(&device->slist, subdevice);
599
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;
610 }
611
612 // Exit device.
613 me_dlock_exit(&device->dlock, filep);
614
615 return err;
616 }
617
me_device_io_stream_stop(struct me_device * device,struct file * filep,int subdevice,int stop_mode,int flags)618 static int me_device_io_stream_stop(struct me_device *device,
619 struct file *filep,
620 int subdevice, int stop_mode, int flags)
621 {
622 int err = ME_ERRNO_SUCCESS;
623 me_subdevice_t *s;
624
625 PDEBUG("executed.\n");
626
627 // Check subdevice index.
628
629 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
630 PERROR("Invalid subdevice.\n");
631 return ME_ERRNO_INVALID_SUBDEVICE;
632 }
633 // Enter device.
634 err = me_dlock_enter(&device->dlock, filep);
635
636 if (err) {
637 PERROR("Cannot enter device.\n");
638 return err;
639 }
640 // Get subdevice instance.
641 s = me_slist_get_subdevice(&device->slist, subdevice);
642
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;
651 }
652
653 // Exit device.
654 me_dlock_exit(&device->dlock, filep);
655
656 return err;
657 }
658
me_device_io_stream_write(struct me_device * device,struct file * filep,int subdevice,int write_mode,int * values,int * count,int flags)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)
664 {
665 int err = ME_ERRNO_SUCCESS;
666 me_subdevice_t *s;
667
668 PDEBUG("executed.\n");
669
670 // Check subdevice index.
671
672 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
673 PERROR("Invalid subdevice.\n");
674 return ME_ERRNO_INVALID_SUBDEVICE;
675 }
676 // Enter device.
677 err = me_dlock_enter(&device->dlock, filep);
678
679 if (err) {
680 PERROR("Cannot enter device.\n");
681 return err;
682 }
683 // Get subdevice instance.
684 s = me_slist_get_subdevice(&device->slist, subdevice);
685
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;
696 }
697
698 // Exit device.
699 me_dlock_exit(&device->dlock, filep);
700
701 return err;
702 }
703
me_device_lock_device(struct me_device * device,struct file * filep,int lock,int flags)704 static int me_device_lock_device(struct me_device *device,
705 struct file *filep, int lock, int flags)
706 {
707 PDEBUG("executed.\n");
708
709 return me_dlock_lock(&device->dlock,
710 filep, lock, flags, &device->slist);
711 }
712
me_device_lock_subdevice(struct me_device * device,struct file * filep,int subdevice,int lock,int flags)713 static int me_device_lock_subdevice(struct me_device *device,
714 struct file *filep,
715 int subdevice, int lock, int flags)
716 {
717 int err = ME_ERRNO_SUCCESS;
718 me_subdevice_t *s;
719
720 PDEBUG("executed.\n");
721
722 // Check subdevice index.
723
724 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
725 PERROR("Invalid subdevice.\n");
726 return ME_ERRNO_INVALID_SUBDEVICE;
727 }
728 // Enter device.
729 err = me_dlock_enter(&device->dlock, filep);
730
731 if (err) {
732 PERROR("Cannot enter device.\n");
733 return err;
734 }
735 // Get subdevice instance.
736 s = me_slist_get_subdevice(&device->slist, subdevice);
737
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;
745 }
746
747 // Exit device.
748 me_dlock_exit(&device->dlock, filep);
749
750 return err;
751 }
752
me_device_query_description_device(struct me_device * device,char ** description)753 static int me_device_query_description_device(struct me_device *device,
754 char **description)
755 {
756 PDEBUG("executed.\n");
757 *description = device->device_description;
758 return ME_ERRNO_SUCCESS;
759 }
760
me_device_query_info_device(struct me_device * device,int * vendor_id,int * device_id,int * serial_no,int * bus_type,int * bus_no,int * dev_no,int * func_no,int * plugged)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)
768 {
769 PDEBUG("executed.\n");
770
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;
782 }
783 return ME_ERRNO_SUCCESS;
784 }
785
me_device_query_name_device(struct me_device * device,char ** name)786 static int me_device_query_name_device(struct me_device *device, char **name)
787 {
788 PDEBUG("executed.\n");
789 *name = device->device_name;
790 return ME_ERRNO_SUCCESS;
791 }
792
me_device_query_name_device_driver(struct me_device * device,char ** name)793 static int me_device_query_name_device_driver(struct me_device *device,
794 char **name)
795 {
796 PDEBUG("executed.\n");
797 *name = device->driver_name;
798 return ME_ERRNO_SUCCESS;
799 }
800
me_device_query_number_subdevices(struct me_device * device,int * number)801 static int me_device_query_number_subdevices(struct me_device *device,
802 int *number)
803 {
804 PDEBUG("executed.\n");
805 return me_slist_query_number_subdevices(&device->slist, number);
806 }
807
me_device_query_number_channels(struct me_device * device,int subdevice,int * number)808 static int me_device_query_number_channels(struct me_device *device,
809 int subdevice, int *number)
810 {
811 int err = ME_ERRNO_SUCCESS;
812 me_subdevice_t *s;
813
814 PDEBUG("executed.\n");
815
816 // Check subdevice index.
817
818 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
819 PERROR("Invalid subdevice.\n");
820 return ME_ERRNO_INVALID_SUBDEVICE;
821 }
822 // Get subdevice instance.
823 s = me_slist_get_subdevice(&device->slist, subdevice);
824
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;
832 }
833
834 return err;
835 }
836
me_device_query_number_ranges(struct me_device * device,int subdevice,int unit,int * count)837 static int me_device_query_number_ranges(struct me_device *device,
838 int subdevice, int unit, int *count)
839 {
840 int err = ME_ERRNO_SUCCESS;
841 me_subdevice_t *s;
842
843 PDEBUG("executed.\n");
844
845 // Check subdevice index.
846
847 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
848 PERROR("Invalid subdevice.\n");
849 return ME_ERRNO_INVALID_SUBDEVICE;
850 }
851 // Get subdevice instance.
852 s = me_slist_get_subdevice(&device->slist, subdevice);
853
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;
861 }
862
863 return err;
864 }
865
me_device_query_range_by_min_max(struct me_device * device,int subdevice,int unit,int * min,int * max,int * maxdata,int * range)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)
871 {
872 int err = ME_ERRNO_SUCCESS;
873 me_subdevice_t *s;
874
875 PDEBUG("executed.\n");
876
877 // Check subdevice index.
878
879 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
880 PERROR("Invalid subdevice.\n");
881 return ME_ERRNO_INVALID_SUBDEVICE;
882 }
883 // Get subdevice instance.
884 s = me_slist_get_subdevice(&device->slist, subdevice);
885
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;
897 }
898
899 return err;
900 }
901
me_device_query_range_info(struct me_device * device,int subdevice,int range,int * unit,int * min,int * max,int * maxdata)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)
907 {
908 int err = ME_ERRNO_SUCCESS;
909 me_subdevice_t *s;
910
911 PDEBUG("executed.\n");
912
913 // Check subdevice index.
914
915 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
916 PERROR("Invalid subdevice.\n");
917 return ME_ERRNO_INVALID_SUBDEVICE;
918 }
919 // Get subdevice instance.
920 s = me_slist_get_subdevice(&device->slist, subdevice);
921
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;
931 }
932
933 return err;
934 }
935
me_device_query_subdevice_by_type(struct me_device * device,int start_subdevice,int type,int subtype,int * subdevice)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)
940 {
941 PDEBUG("executed.\n");
942
943 return me_slist_get_subdevice_by_type(&device->slist,
944 start_subdevice,
945 type, subtype, subdevice);
946 }
947
me_device_query_subdevice_type(struct me_device * device,int subdevice,int * type,int * subtype)948 static int me_device_query_subdevice_type(struct me_device *device,
949 int subdevice,
950 int *type, int *subtype)
951 {
952 int err = ME_ERRNO_SUCCESS;
953 me_subdevice_t *s;
954
955 PDEBUG("executed.\n");
956
957 // Check subdevice index.
958
959 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
960 PERROR("Invalid subdevice.\n");
961 return ME_ERRNO_INVALID_SUBDEVICE;
962 }
963 // Get subdevice instance.
964 s = me_slist_get_subdevice(&device->slist, subdevice);
965
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;
973 }
974
975 return err;
976 }
977
me_device_query_subdevice_caps(struct me_device * device,int subdevice,int * caps)978 static int me_device_query_subdevice_caps(struct me_device *device,
979 int subdevice, int *caps)
980 {
981 int err = ME_ERRNO_SUCCESS;
982 me_subdevice_t *s;
983
984 PDEBUG("executed.\n");
985
986 // Check subdevice index.
987
988 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
989 PERROR("Invalid subdevice.\n");
990 return ME_ERRNO_INVALID_SUBDEVICE;
991 }
992 // Get subdevice instance.
993 s = me_slist_get_subdevice(&device->slist, subdevice);
994
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;
1002 }
1003
1004 return err;
1005 }
1006
me_device_query_subdevice_caps_args(struct me_device * device,int subdevice,int cap,int * args,int count)1007 static int me_device_query_subdevice_caps_args(struct me_device *device,
1008 int subdevice,
1009 int cap, int *args, int count)
1010 {
1011 int err = ME_ERRNO_SUCCESS;
1012 me_subdevice_t *s;
1013
1014 PDEBUG("executed.\n");
1015
1016 // Check subdevice index.
1017
1018 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
1019 PERROR("Invalid subdevice.\n");
1020 return ME_ERRNO_INVALID_SUBDEVICE;
1021 }
1022 // Get subdevice instance.
1023 s = me_slist_get_subdevice(&device->slist, subdevice);
1024
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;
1034 }
1035
1036 return err;
1037 }
1038
me_device_query_timer(struct me_device * device,int subdevice,int timer,int * base_frequency,uint64_t * min_ticks,uint64_t * max_ticks)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)
1044 {
1045 int err = ME_ERRNO_SUCCESS;
1046 me_subdevice_t *s;
1047
1048 PDEBUG("executed.\n");
1049
1050 // Check subdevice index.
1051
1052 if (subdevice >= me_slist_get_number_subdevices(&device->slist)) {
1053 PERROR("Invalid subdevice.\n");
1054 return ME_ERRNO_INVALID_SUBDEVICE;
1055 }
1056 // Get subdevice instance.
1057 s = me_slist_get_subdevice(&device->slist, subdevice);
1058
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;
1069 }
1070
1071 return err;
1072 }
1073
me_device_query_version_device_driver(struct me_device * device,int * version)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!
1077 */
1078 {
1079 PDEBUG("executed.\n");
1080 *version = ME_VERSION_DRIVER;
1081 return ME_ERRNO_SUCCESS;
1082 }
1083
me_device_config_load(struct me_device * device,struct file * filep,me_cfg_device_entry_t * config)1084 static int me_device_config_load(struct me_device *device, struct file *filep,
1085 me_cfg_device_entry_t * config)
1086 {
1087 PDEBUG("executed.\n");
1088 return ME_ERRNO_SUCCESS; //If no need for config return success.
1089 // return ME_ERRNO_NOT_SUPPORTED;
1090 }
1091
me_device_destructor(me_device_t * me_device)1092 static void me_device_destructor(me_device_t * me_device)
1093 {
1094 PDEBUG("executed.\n");
1095 me_device_deinit(me_device);
1096 kfree(me_device);
1097 }
1098
1099 /* //me_device_usb_init
1100 int me_device_usb_init(me_device_t *me_device, struct usb_interface *interface)
1101 {
1102 PDEBUG("executed.\n");
1103 return -1;
1104 }
1105 */
1106
get_device_descriptions(uint16_t device_id,char ** device_name,char ** device_description,char ** driver_name)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!
1114 */
1115 {
1116 PDEBUG("executed.\n");
1117
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;
1126
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;
1132
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;
1138
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;
1144
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;
1150
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;
1156
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;
1162
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;
1168
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;
1174
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;
1180
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;
1186
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;
1192
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;
1198
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;
1204
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;
1210
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;
1216
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;
1222
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;
1228
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;
1234
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;
1240
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;
1246
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;
1252
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;
1258
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;
1264
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;
1270
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;
1276
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;
1282
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;
1288
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;
1294
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;
1300
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;
1306
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;
1312
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;
1318
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;
1324
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;
1330
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;
1336
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;
1342
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;
1348
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;
1354
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;
1360
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;
1366
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;
1372
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;
1378
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;
1384
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;
1390
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;
1396
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;
1402
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;
1408
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;
1414
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;
1420
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;
1426
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;
1432
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;
1438
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;
1444
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;
1450
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;
1456
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;
1462
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;
1468
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;
1474
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;
1480
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;
1486
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;
1492
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;
1498
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;
1504
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;
1510
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;
1516
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;
1522
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;
1528
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;
1534
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;
1540
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;
1546
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;
1552
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;
1558
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;
1564 /*
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;
1570 */
1571 default:
1572 *device_name = EMPTY_NAME_DEVICE;
1573 *device_description = EMPTY_DESCRIPTION_DEVICE;
1574 *driver_name = EMPTY_NAME_DRIVER;
1575
1576 PERROR("Invalid device id.\n");
1577
1578 return 1;
1579 }
1580
1581 return 0;
1582 }
1583
me_device_pci_init(me_device_t * me_device,struct pci_dev * pci_device)1584 int me_device_pci_init(me_device_t * me_device, struct pci_dev *pci_device)
1585 {
1586 int err;
1587 int i;
1588
1589 PDEBUG("executed.\n");
1590
1591 // Initialize device list head.
1592 INIT_LIST_HEAD(&me_device->list);
1593
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);
1599
1600 if (err) {
1601 PERROR("Cannot initialize device description strings.\n");
1602 return 1;
1603 }
1604 // Enable the pci device.
1605 err = pci_enable_device(pci_device);
1606
1607 if (err < 0) {
1608 PERROR("Cannot enable PCI device.\n");
1609 return 1;
1610 }
1611 // Request the PCI register regions.
1612 err = pci_request_regions(pci_device, me_device->device_name);
1613
1614 if (err < 0) {
1615 PERROR("Cannot request PCI regions.\n");
1616 goto ERROR_0;
1617 }
1618 // The bus carrying the device is a PCI bus.
1619 me_device->bus_type = ME_BUS_TYPE_PCI;
1620
1621 // Store the PCI information for later usage.
1622 me_device->info.pci.pci_device = pci_device;
1623
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);
1630 }
1631
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);
1636
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);
1643
1644 // Get the interrupt request number.
1645 me_device->irq = pci_device->irq;
1646
1647 // Initialize device lock instance.
1648 err = me_dlock_init(&me_device->dlock);
1649
1650 if (err) {
1651 PERROR("Cannot initialize device lock instance.\n");
1652 goto ERROR_1;
1653 }
1654 // Initialize subdevice list instance.
1655 me_slist_init(&me_device->slist);
1656
1657 if (err) {
1658 PERROR("Cannot initialize subdevice list instance.\n");
1659 goto ERROR_2;
1660 }
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;
1708
1709 return 0;
1710
1711 ERROR_0:
1712 me_dlock_deinit(&me_device->dlock);
1713
1714 ERROR_1:
1715 pci_release_regions(pci_device);
1716
1717 ERROR_2:
1718 pci_disable_device(pci_device);
1719
1720 return 1;
1721 }
1722
me_device_deinit(me_device_t * me_device)1723 void me_device_deinit(me_device_t * me_device)
1724 {
1725 PDEBUG("executed.\n");
1726
1727 me_slist_deinit(&me_device->slist);
1728 me_dlock_deinit(&me_device->dlock);
1729
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);
1733 }
1734 /*
1735 else
1736 {
1737 // Must be an USB device.
1738 }
1739 */
1740 }
1741