-
Notifications
You must be signed in to change notification settings - Fork 2
/
tmk1553usb.c
3520 lines (3162 loc) · 96.4 KB
/
tmk1553usb.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* tmk1553busb.c -- the tmk1553busb v1.08 usb kernel module.
* (c) ELCUS, 2008.
*/
#ifndef __KERNEL__
# define __KERNEL__
#endif
#ifndef MODULE
# define MODULE
#endif
#include "config.h"
#ifndef TMK1553B_NOCONFIGH
#include <linux/config.h>
#endif
#include <linux/version.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/sched.h>
#include <linux/unistd.h>
#include <linux/errno.h>
#include <linux/poll.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/fcntl.h>
#include <linux/module.h>
#include <linux/spinlock.h>
#include <linux/wait.h>
#include <linux/smp.h>
#ifdef CONFIG_DEVFS_FS
#include <linux/devfs_fs_kernel.h>
#endif
#include <linux/usb.h>
#ifndef KERNEL_VERSION
#define KERNEL_VERSION(a,b,c) ((a)*65536+(b)*256+(c))
#endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
#error Unsupported Kernel Version!
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,0,0)
#define _LINUX_5_0_
#define _LINUX_3_0_
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3,0,0)
#define _LINUX_3_0_
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
#define _LINUX_2_6_
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
#define _LINUX_2_4_
#endif
#if defined(_LINUX_3_0_) || defined(_LINUX_2_6_)
MODULE_LICENSE("GPL");
#endif
#ifdef CONFIG_64BIT
#define __64BIT__
#endif
#ifdef _LINUX_5_0_
#include <linux/sched/signal.h>
#else
#include <linux/signal.h>
#endif
#ifdef _LINUX_3_0_
#include<linux/kthread.h>
#endif
#include "tmk1553busb.h"
/* Module paramaters */
#define MAX_TMK_NUMBER (NTMK - 1)
#define TMK_BAD_0 -1024
/* table of devices that work with this driver */
static struct usb_device_id tmk1553busb_table [] =
{
{ USB_DEVICE(TA1_USB_01_VENDOR_ID, TA1_USB_01_PRODUCT_ID) },
{ } /* Terminating entry */
};
MODULE_DEVICE_TABLE (usb, tmk1553busb_table);
#ifdef CONFIG_DEVFS_FS
/* the global usb devfs handle */
extern devfs_handle_t usb_devfs_handle;
#endif
#include "tmklllin.h"
u32 TMK_tmkgetmaxn(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_tmkconfig(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_tmkdone(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_tmkselect(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_tmkselected(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_tmkgetmode(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_tmksetcwbits(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_tmkclrcwbits(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_tmkgetcwbits(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_tmkwaitevents(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
//u32 TMK_tmkdefevent(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_tmkgetevd(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
//u32 TMK_bcdefintnorm();
//u32 TMK_bcdefintexc();
//u32 TMK_bcdefintx();
//u32 TMK_bcdefintsig();
u32 TMK_bcreset(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_bc_def_tldw(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_bc_enable_di(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_bc_disable_di(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_bcdefirqmode(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_bcgetirqmode(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_bcgetmaxbase(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_bcdefbase(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_bcgetbase(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_bcputw(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_bcgetw(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_bcgetansw(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_bcputblk(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_bcgetblk(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_bcdefbus(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_bcgetbus(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_bcstart(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_bcstartx(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_bcdeflink(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_bcgetlink(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_bcstop(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_bcgetstate(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
//u32 TMK_rtdefintcmd();
//u32 TMK_rtdefinterr();
//u32 TMK_rtdefintdata();
u32 TMK_rtreset(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_rtdefirqmode(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_rtgetirqmode(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_rtdefmode(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_rtgetmode(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_rtgetmaxpage(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_rtdefpage(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_rtgetpage(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_rtdefpagepc(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_rtdefpagebus(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_rtgetpagepc(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_rtgetpagebus(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_rtdefaddress(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_rtgetaddress(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_rtdefsubaddr(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_rtgetsubaddr(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_rtputw(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_rtgetw(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_rtputblk(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_rtgetblk(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_rtsetanswbits(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_rtclranswbits(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_rtgetanswbits(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_rtgetflags(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_rtputflags(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_rtsetflag(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_rtclrflag(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_rtgetflag(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_rtgetstate(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_rtbusy(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_rtlock(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_rtunlock(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_rtgetcmddata(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_rtputcmddata(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
//u32 TMK_mtdefintx();
//u32 TMK_mtdefintsig();
u32 TMK_mtreset(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
#define TMK_mtdefirqmode TMK_bcdefirqmode
#define TMK_mtgetirqmode TMK_bcgetirqmode
#define TMK_mtgetmaxbase TMK_bcgetmaxbase
#define TMK_mtdefbase TMK_bcdefbase
#define TMK_mtgetbase TMK_bcgetbase
#define TMK_mtputw TMK_bcputw
#define TMK_mtgetw TMK_bcgetw
u32 TMK_mtgetsw(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
#define TMK_mtputblk TMK_bcputblk
#define TMK_mtgetblk TMK_bcgetblk
#define TMK_mtstartx TMK_bcstartx
#define TMK_mtdeflink TMK_bcdeflink
#define TMK_mtgetlink TMK_bcgetlink
#define TMK_mtstop TMK_bcstop
#define TMK_mtgetstate TMK_bcgetstate
u32 TMK_tmkgetinfo(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_getversion(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_rtenable(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_mrtgetmaxn(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_mrtconfig(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_mrtselected(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_mrtgetstate(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_mrtdefbrcsubaddr0(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_mrtreset(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_tmktimer(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_tmkgettimer(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_tmkgettimerl(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_bcgetmsgtime(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
#define TMK_mtgetmsgtime TMK_bcgetmsgtime
u32 TMK_rtgetmsgtime(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_tmkgethwver(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_tmkgetevtime(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_tmkswtimer(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_tmkgetswtimer(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_tmktimeout(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_MT_Start(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_MT_GetMessage(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_MT_Stop(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_mrtdefbrcpage(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_mrtgetbrcpage(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_mbcinit(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_mbcpreparex(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_mbcstartx(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_mbcalloc(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_mbcfree(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_tmkwaiteventsflag(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_tmkwaiteventsm(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
//u32 TMK_bcputblk64(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
//u32 TMK_bcgetblk64(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
//u32 TMK_rtputblk64(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
//u32 TMK_rtgetblk64(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
//u32 TMK_rtgetflags64(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
//u32 TMK_rtputflags64(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 TMK_tmkreadsn(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf);
u32 (*TMK_Procs[])(struct tmk1553busb * dev, u16 * awIn, u16 * awOut, u16 * awBuf) = {
TMK_tmkconfig,
TMK_tmkdone,
TMK_tmkgetmaxn,
TMK_tmkselect,
TMK_tmkselected,
TMK_tmkgetmode,
TMK_tmksetcwbits,
TMK_tmkclrcwbits,
TMK_tmkgetcwbits,
TMK_tmkwaitevents,
// TMK_tmkdefevent,
TMK_tmkgetevd,
// TMK_bcdefintnorm,
// TMK_bcdefintexc,
// TMK_bcdefintx,
// TMK_bcdefintsig,
TMK_bcreset,
TMK_bc_def_tldw,
TMK_bc_enable_di,
TMK_bc_disable_di,
TMK_bcdefirqmode,
TMK_bcgetirqmode,
TMK_bcgetmaxbase,
TMK_bcdefbase,
TMK_bcgetbase,
TMK_bcputw,
TMK_bcgetw,
TMK_bcgetansw,
TMK_bcputblk,
TMK_bcgetblk,
TMK_bcdefbus,
TMK_bcgetbus,
TMK_bcstart,
TMK_bcstartx,
TMK_bcdeflink,
TMK_bcgetlink,
TMK_bcstop,
TMK_bcgetstate,
// TMK_rtdefintcmd,
// TMK_rtdefinterr,
// TMK_rtdefintdata,
TMK_rtreset,
TMK_rtdefirqmode,
TMK_rtgetirqmode,
TMK_rtdefmode,
TMK_rtgetmode,
TMK_rtgetmaxpage,
TMK_rtdefpage,
TMK_rtgetpage,
TMK_rtdefpagepc,
TMK_rtdefpagebus,
TMK_rtgetpagepc,
TMK_rtgetpagebus,
TMK_rtdefaddress,
TMK_rtgetaddress,
TMK_rtdefsubaddr,
TMK_rtgetsubaddr,
TMK_rtputw,
TMK_rtgetw,
TMK_rtputblk,
TMK_rtgetblk,
TMK_rtsetanswbits,
TMK_rtclranswbits,
TMK_rtgetanswbits,
TMK_rtgetflags,
TMK_rtputflags,
TMK_rtsetflag,
TMK_rtclrflag,
TMK_rtgetflag,
TMK_rtgetstate,
TMK_rtbusy,
TMK_rtlock,
TMK_rtunlock,
TMK_rtgetcmddata,
TMK_rtputcmddata,
// TMK_mtdefintx,
// TMK_mtdefintsig,
TMK_mtreset,
TMK_mtdefirqmode,
TMK_mtgetirqmode,
TMK_mtgetmaxbase,
TMK_mtdefbase,
TMK_mtgetbase,
TMK_mtputw,
TMK_mtgetw,
TMK_mtgetsw,
TMK_mtputblk,
TMK_mtgetblk,
TMK_mtstartx,
TMK_mtdeflink,
TMK_mtgetlink,
TMK_mtstop,
TMK_mtgetstate,
TMK_tmkgetinfo,
TMK_getversion,
TMK_rtenable,
TMK_mrtgetmaxn,
TMK_mrtconfig,
TMK_mrtselected,
TMK_mrtgetstate,
TMK_mrtdefbrcsubaddr0,
TMK_mrtreset,
TMK_tmktimer,
TMK_tmkgettimer,
TMK_tmkgettimerl,
TMK_bcgetmsgtime,
TMK_mtgetmsgtime,
TMK_rtgetmsgtime,
TMK_tmkgethwver,
TMK_tmkgetevtime,
TMK_tmkswtimer,
TMK_tmkgetswtimer,
TMK_tmktimeout,
TMK_mrtdefbrcpage,
TMK_mrtgetbrcpage,
TMK_mbcinit,
TMK_mbcpreparex,
TMK_mbcstartx,
TMK_mbcalloc,
TMK_mbcfree,
TMK_MT_Start,
TMK_MT_GetMessage,
TMK_MT_Stop,
TMK_tmkwaiteventsflag, //115
TMK_tmkwaiteventsm,
TMK_tmkwaiteventsflag, //117
TMK_tmkwaiteventsflag,
TMK_tmkwaiteventsflag,
TMK_tmkwaiteventsflag,
TMK_tmkwaiteventsflag,
TMK_tmkwaiteventsflag,
TMK_tmkwaiteventsflag,
TMK_tmkwaiteventsflag,
TMK_tmkwaiteventsflag,
TMK_tmkwaiteventsflag,
TMK_tmkreadsn //127
// TMK_bcputblk64,
// TMK_bcgetblk64,
// TMK_rtputblk64,
// TMK_rtgetblk64,
// TMK_rtgetflags64,
// TMK_rtputflags64
};
#define MAX_TMK_API (sizeof(TMK_Procs)/sizeof(void*)+1)
#define LOWORD(l) ((u16)(l))
#define HIWORD(l) ((u16)(((u32)(l) >> 16) & 0xFFFF))
/* local function prototypes */
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
static long tmk1553busb_uioctl (struct file *filp, unsigned int cmd, unsigned long arg);
#else
static int tmk1553busb_ioctl (struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg);
#endif
static int tmk1553busb_open (struct inode *inode, struct file *file);
static int tmk1553busb_release (struct inode *inode, struct file *file);
#ifdef _LINUX_2_4_
static void * tmk1553busb_probe (struct usb_device *dev, unsigned int ifnum, const struct usb_device_id *id);
static void tmk1553busb_disconnect (struct usb_device *dev, void *ptr);
#endif
#if defined(_LINUX_2_6_) || defined(_LINUX_3_0_)
static int tmk1553busb_probe(struct usb_interface *interface, const struct usb_device_id *id);
static void tmk1553busb_disconnect(struct usb_interface *interface);
#endif
void tmk1553busb_delete (struct tmk1553busb * dev);
void kthread_launcher(void *data);
#ifdef _LINUX_3_0_
int int_thread(void * dev);
#else
void int_thread(struct tmk1553busb * dev);
#endif
/* array of pointers to our devices that are currently connected */
struct tmk1553busb * minor_table[MAX_DEVICES];
char intth_run[MAX_DEVICES];
struct list_head hlProc;
/* semaphores to protect the minor_table structure */
#ifdef SPIN_LOCK_BLOCKING
spinlock_t dev_lock[MAX_DEVICES];
spinlock_t list_lock;
#define LOCK_DEVICE(lock) spin_lock_irq(lock)
#define UNLOCK_DEVICE(lock) spin_unlock_irq(lock)
#define LOCK_LIST() spin_lock_irq(&list_lock)
#define UNLOCK_LIST() spin_unlock_irq(&list_lock)
#else
struct semaphore dev_lock[MAX_DEVICES];
struct semaphore list_lock;
#define LOCK_DEVICE(lock) down(lock)
#define UNLOCK_DEVICE(lock) up(lock)
#define LOCK_LIST() down(&list_lock)
#define UNLOCK_LIST() up(&list_lock)
#endif
#ifdef SPIN_LOCK_IRQ_BLOCKING
spinlock_t intLock[MAX_DEVICES];
#define LOCK_IRQ(lock) spin_lock_irq(lock)
#define UNLOCK_IRQ(lock) spin_unlock_irq(lock)
#else
struct semaphore intLock[MAX_DEVICES];
#define LOCK_IRQ(lock) down(lock)
#define UNLOCK_IRQ(lock) up(lock)
#endif
//volatile int tmkEvents = 0;
wait_queue_head_t wq;
#ifdef _LINUX_2_4_
pid_t keventd_pid = -1;
#endif
/* int FIFO stuff */
#define EVENTS_SIZE 1024
TListEvD aEvData_usb[MAX_DEVICES][EVENTS_SIZE];
int iEvDataBegin_usb[MAX_DEVICES];
int iEvDataEnd_usb[MAX_DEVICES];
int cEvData_usb[MAX_DEVICES];
#ifdef ASYNCHRONOUS_IO
char cAsync[MAX_DEVICES];
#endif
/* mt FIFO stuff*/
u8 * MonitorHwBuf[MAX_DEVICES];
u8 MonitorHwBufOF[MAX_DEVICES];
u32 MonitorHwBufRead[MAX_DEVICES];
u32 MonitorHwBufWrite[MAX_DEVICES];
u32 MonitorHwBufSize[MAX_DEVICES];
u32 MonitorHwBufCount[MAX_DEVICES];
u8 MonitorHwTimer[MAX_DEVICES];
static int usbminor = TMK1553BUSB_MINOR_BASE;
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,3)
module_param(usbminor, int, 0);
MODULE_PARM_DESC(usbminor, "Minor base number");
#else
MODULE_PARM(usbminor,"i");
#endif
/*
* File operations needed when we register this driver.
* This assumes that this driver NEEDS file operations,
* of course, which means that the driver is expected
* to have a node in the /dev directory. If the USB
* device were for a network interface then the driver
* would use "struct net_driver" instead, and a serial
* device would use "struct tty_driver".
*/
static struct file_operations tmk1553busb_fops =
{
/*
* The owner field is part of the module-locking
* mechanism. The idea is that the kernel knows
* which module to increment the use-counter of
* BEFORE it calls the device's open() function.
* This also means that the kernel can decrement
* the use-counter again before calling release()
* or should the open() function fail.
*
* Not all device structures have an "owner" field
* yet. "struct file_operations" and "struct net_device"
* do, while "struct tty_driver" does not. If the struct
* has an "owner" field, then initialize it to the value
* THIS_MODULE and the kernel will handle all module
* locking for you automatically. Otherwise, you must
* increment the use-counter in the open() function
* and decrement it again in the release() function
* yourself.
*/
#ifdef MY_OWNER
owner: THIS_MODULE,
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
unlocked_ioctl: tmk1553busb_uioctl,
#else
ioctl: tmk1553busb_ioctl,
#endif
open: tmk1553busb_open,
release: tmk1553busb_release,
};
#if defined(_LINUX_2_6_) || defined(_LINUX_3_0_)
static struct usb_class_driver tmk1553busb_class = {
name: "tmk1553busb%d",
fops: &tmk1553busb_fops,
minor_base: TMK1553BUSB_MINOR_BASE,
};
#endif
/* usb specific object needed to register this driver with the usb subsystem */
static struct usb_driver tmk1553busb_driver =
{
name: "tmk1553busb",
probe: tmk1553busb_probe,
disconnect: tmk1553busb_disconnect,
#ifdef _LINUX_2_4_
fops: &tmk1553busb_fops,
minor: TMK1553BUSB_MINOR_BASE,
#endif
id_table: tmk1553busb_table,
};
/*
* tmk1553busb_delete
*/
inline void tmk1553busb_delete(struct tmk1553busb * dev)
{
if(MonitorHwBuf[dev->minor])
kfree(MonitorHwBuf[dev->minor]);
minor_table[dev->minor] = NULL;
#if defined(_LINUX_2_6_) || defined(_LINUX_3_0_)
usb_deregister_dev(dev->interface, &tmk1553busb_class);
#endif
kfree (dev);
}
/*
* tmk1553busb_open
*/
static int tmk1553busb_open (struct inode *inode, struct file *file)
{
struct tmk1553busb * dev = NULL;
int subminor;
TListProc *hlnProc;
TListProc *hlnProc1;
if(MINOR (inode->i_rdev) >= usbminor)
subminor = MINOR (inode->i_rdev) - usbminor;
else
subminor = MINOR (inode->i_rdev);
#ifdef TMK1553BUSB_DEBUG
printk(KERN_INFO "tmk1553busb: Enter to tmk1553busb_open minor %d procID: %d\n",
subminor,
current->pid);
#endif
if ((subminor < 0) || (subminor >= MAX_DEVICES))
{
return -ENODEV;
}
/* Increment our usage count for the module.
* This is redundant here, because "struct file_operations"
* has an "owner" field. This line is included here soley as
* a reference for drivers using lesser structures.
*/
#ifndef MY_OWNER
MOD_INC_USE_COUNT;
#endif
hlnProc = kmalloc(sizeof(TListProc), GFP_KERNEL);
if(hlnProc == NULL)
return -ENODEV;
/* lock our device and get our local data for this minor */
LOCK_DEVICE(&dev_lock[subminor]);
dev = minor_table[subminor];
if (dev == NULL) //device was removed
{
UNLOCK_DEVICE(&dev_lock[subminor]);
#ifndef MY_OWNER
MOD_DEC_USE_COUNT;
#endif
kfree(hlnProc);
return -ENODEV;
}
/* increment our usage count for the driver */
++dev->open_count;
/* save our object in the file's private structure */
file->private_data = dev;
/* unlock this device */
UNLOCK_DEVICE(&dev_lock[subminor]);
LOCK_LIST();
for(hlnProc1 = (TListProc*)(hlProc.next);
hlnProc1 != (TListProc*)(&hlProc);
hlnProc1 = (TListProc*)(hlnProc1->ProcListEntry.next)
)
{
if (hlnProc1->hProc == current->pid)
{
hlnProc1->openCnt++;
kfree(hlnProc);
goto exit_open;
}
}
hlnProc->hProc = current->pid;
hlnProc->openCnt = 1;
hlnProc->waitFlag = 0;
list_add_tail(&hlnProc->ProcListEntry, &hlProc);
exit_open:
UNLOCK_LIST();
return 0;
}
/*
* tmk1553busb_release
*/
static int tmk1553busb_release (struct inode *inode, struct file *file)
{
struct tmk1553busb * dev = NULL;
int subminor;
TListProc *hlnProc;
pid_t hProc;
if(MINOR (inode->i_rdev) >= usbminor)
subminor = MINOR (inode->i_rdev) - usbminor;
else
subminor = MINOR (inode->i_rdev);
#ifdef TMK1553BUSB_DEBUG
printk(KERN_INFO "tmk1553busb: Enter to tmk1553busb_release minor %d\n",
subminor);
#endif
if ((subminor < 0) || (subminor >= MAX_DEVICES))
{
return -ENODEV;
}
hProc = current->pid;
LOCK_LIST();
for (hlnProc = (TListProc*)(hlProc.next);
hlnProc != (TListProc*)(&hlProc);
hlnProc = (TListProc*)(hlnProc->ProcListEntry.next)
)
{
if (hlnProc->hProc != hProc)
continue;
hlnProc->openCnt--;
if(hlnProc->openCnt <= 0)
{
list_del((struct list_head *)hlnProc);
kfree(hlnProc);
}
break;
}
UNLOCK_LIST();
LOCK_DEVICE(&dev_lock[subminor]);
// dev = (struct tmk1553busb *)file->private_data;
dev = minor_table[subminor];
if (dev == NULL)
{
UNLOCK_DEVICE(&dev_lock[subminor]);
return -ENODEV;
}
if (dev->udev == NULL)
{
/* the device was unplugged before the file was released */
--dev->open_count;
if(dev->open_count <= 0)
{
tmk1553busb_delete (dev);
goto exit2;
}
goto exit1;
}
/* decrement our usage count for the device */
--dev->open_count;
if (dev->open_count <= 0)
{
dev->open_count = 0;
}
exit1:
if(dev->curproc == current->pid)
{
tmkdone_usb(dev->minor);
LOCK_IRQ(&intLock[dev->minor]);
// tmkEvents &= ~(1<<(dev->minor));
dev->event = 0;
iEvDataBegin_usb[dev->minor] = iEvDataEnd_usb[dev->minor] = cEvData_usb[dev->minor] = 0;
UNLOCK_IRQ(&intLock[dev->minor]);
dev->curproc = 0;
}
exit2:
UNLOCK_DEVICE(&dev_lock[subminor]);
#ifndef MY_OWNER
MOD_DEC_USE_COUNT;
#endif
return 0;
}
/*
* tmk1553busb_ioctl
*/
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
static long tmk1553busb_uioctl (struct file *filp, unsigned int cmd, unsigned long arg)
#else
static int tmk1553busb_ioctl (struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg)
#endif
{
struct tmk1553busb * dev;
int err = 0;
int subminor;
u32 dwService;
u32 dwRetVal = 0;
u16 awBuf[64];
u16 awIn[8];
u16 awOut[6];
u16 * ptr = NULL;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
subminor = ((struct tmk1553busb *)filp->private_data)->minor;
#else
if(MINOR (inode->i_rdev) >= usbminor)
subminor = MINOR (inode->i_rdev) - usbminor;
else
subminor = MINOR (inode->i_rdev);
#endif
#ifdef TMK1553BUSB_DEBUG
printk(KERN_INFO "tmk1553busb: Enter to tmk1553busb_ioctl minor %d cmd %d\n",
subminor, _IOC_NR(cmd));
#endif
if ((subminor < 0) || (subminor >= MAX_DEVICES))
{
return -ENODEV;
}
/*
* extract the type and number bitfields, and don't decode
* wrong cmds: return ENOTTY (inappropriate ioctl) before access_ok()
*/
if (_IOC_TYPE(cmd) != TMK_IOC_MAGIC) return -ENOTTY;
dwService = _IOC_NR(cmd);
if (dwService > MAX_TMK_API) return -ENOTTY;
if (_IOC_DIR(cmd) & _IOC_READ)
#ifdef _LINUX_5_0_
err = !access_ok((void *)arg, _IOC_SIZE(cmd));
#else
err = !access_ok(VERIFY_WRITE, (void *)arg, _IOC_SIZE(cmd));
#endif
else if (_IOC_DIR(cmd) & _IOC_WRITE)
#ifdef _LINUX_5_0_
err = !access_ok((void *)arg, _IOC_SIZE(cmd));
#else
err = !access_ok(VERIFY_READ, (void *)arg, _IOC_SIZE(cmd));
#endif
if (err) return -EFAULT;
if (_IOC_DIR(cmd) & _IOC_WRITE)
{
if (_IOC_SIZE(cmd) == sizeof(u32[2]))
{
__get_user(*((u32*)awIn), (u32*)arg);
__get_user(*((u32*)awIn+1), (u32*)arg+1);
// use 32bit ptr on 32bit system or convert it to 64bit ptr on
// 64bit system for backward compatibility with pre4.02 programs
// can fail on 64bit system with addresses above 4G!!!
ptr = (u16*)((unsigned long)(*((u32*)awIn+1))); // not needed for tmkwaitevents
}
#ifdef __64BIT__
else if (_IOC_SIZE(cmd) == sizeof(u64[2]))
{
__get_user(*((u32*)awIn), (u32*)arg);
*((u32*)awIn+1) = 0; // not needed for put/get
__get_user(ptr, (u16**)arg+1);
}
#endif
else
return -EFAULT;
}
else
*((u32 *)awIn) = (u32)arg;
switch (dwService)
{
case VTMK_MT_GetMessage://update later!!!!
__get_user(*((u32*)awIn), (unsigned long*)arg);
__get_user(*((u32*)awIn+1), (unsigned long*)arg+1);
__get_user(*((unsigned long*)(awIn+4)), (unsigned long*)arg+2);
break;
case VTMK_bcputblk:
case VTMK_mtputblk:
case VTMK_rtputblk:
if (awIn[1] > 64 || awIn[1] == 0)
break;
if (__copy_from_user(
awBuf,
// (u16 *)(*((u32 *)(awIn+2))),
ptr,
awIn[1]<<1
))
return -EFAULT;
break;
case VTMK_rtputflags:
awIn[4] = awIn[0] & RT_DIR_MASK;
*((u32 *)(awIn)) &= ~(RT_DIR_MASK | (RT_DIR_MASK<<16));
if (awIn[1] < awIn[0] || awIn[1] > 31)
break;
if (__copy_from_user(
awBuf,
// (u16 *)(*((u32 *)(awIn))),
ptr,
(awIn[1]-awIn[0]+1)<<1
))
return -EFAULT;
break;
case VTMK_rtgetflags:
awIn[4] = awIn[0] & RT_DIR_MASK;
*((u32 *)(awIn)) &= ~(RT_DIR_MASK | (RT_DIR_MASK<<16));
break;
}
LOCK_DEVICE(&dev_lock[subminor]);
dev = minor_table[subminor];
// dev = (struct tmk1553busb *)file->private_data;
if (dev == NULL)
{
UNLOCK_DEVICE(&dev_lock[subminor]);
return -ENODEV;
}
/* verify that the device wasn't unplugged */
if (dev->udev == NULL)
{
UNLOCK_DEVICE(&dev_lock[subminor]);
return -ENODEV;
}
tmkError_usb[dev->minor] = 0;
dwRetVal = (TMK_Procs[dwService-2])(dev, awIn, awOut, awBuf);
err = tmkError_usb[dev->minor];
/* unlock the device */
UNLOCK_DEVICE(&dev_lock[subminor]);
#ifdef TMK1553BUSB_DEBUG
printk(KERN_INFO "tmk1553busb: ioctl: error %d\n",err);
#endif
if (err == 0)
{
switch (dwService)
{
case VTMK_bcgetblk:
case VTMK_mtgetblk:
case VTMK_rtgetblk:
if (awIn[1] > 64 || awIn[1] == 0)
break;
if (__copy_to_user(
// (u16 *)(*((u32 *)(awIn+2))),
ptr,
awBuf,
awIn[1]<<1
))
return -EFAULT;
break;
case VTMK_rtgetflags:
if (awIn[1] < awIn[0] || awIn[1] > 31)
break;
if (__copy_to_user(
// (u16 *)(*((u32 *)(awIn))),
ptr,
awBuf,
(awIn[3]-awIn[2]+1)<<1
))
return -EFAULT;
break;
case VTMK_tmkgetinfo:
if (__copy_to_user(
(TTmkConfigData*)arg,
awBuf,
sizeof(TTmkConfigData)
))
return -EFAULT;
break;
case VTMK_tmkgetevd:
if (__copy_to_user(
(u16 *)arg,//check it!!!
awOut,
12
))
return -EFAULT;
break;
default:
if (_IOC_DIR(cmd) & _IOC_READ)
{
__put_user(*((u32*)awOut), (u32*)arg);
/*
if (dwService == VTMK_tmkgetevd) // _IOC_SIZE(cmd) == 12
{
__put_user(*((u32*)awOut+1), (u32*)arg+1);
__put_user(*((u32*)awOut+2), (u32*)arg+2);
}
*/
}
// else
// dwRetVal = (u32)awOut[0];
break;
}
}
if (err != 0)
err = TMK_BAD_0 - err;
else
err = dwRetVal; // has to be > 0 for Ok and < 0 for error !!!
return err;
}
/*
* tmk1553busb_probe
*
* Called by the usb core when a new device is connected that it thinks
* this driver might be interested in.
*/
#ifdef _LINUX_2_4_
static void * tmk1553busb_probe(struct usb_device *udev, unsigned int ifnum, const struct usb_device_id *id)
#endif
#if defined(_LINUX_2_6_) || defined(_LINUX_3_0_)
static int tmk1553busb_probe(struct usb_interface *interface, const struct usb_device_id *id)
#endif
{
struct tmk1553busb * dev = NULL;
#ifdef _LINUX_2_4_
struct usb_interface * interface;
struct usb_interface_descriptor * iface_desc;
struct tq_struct tq;
#endif
#if defined(_LINUX_2_6_) || defined(_LINUX_3_0_)
struct usb_device * udev;
struct usb_host_interface * iface_desc;
#ifdef TMK1553BUSB_DEBUG
struct usb_endpoint_descriptor * endpoint;
#endif
#endif
int minor;
char * chBuf;